π΅βπ« A Recurrent Neural Network (RNN) hallucinating solidity source code.
- We train our model on samples from the https://github.com/tintinweb/smart-contract-sanctuary
- And then "hallucinate" new contracts
Note: train the model on https://colab.research.google.com/ as it is much faster than doing this locally.
./solidity_model_text/
- contains a pre-trained keras model trained on 15mb solidity input, character based training (pretty dumb), with sampling sequence length of 250 chars. The model has anembedding_dimension
of256
with1024
rnn_units
. It was trained for15 epochs
on google collab (hw-accelleration:GPU
) which took somewhere between 1-1.5 hrs.- ./tutorial_2_hallucinate_from_pretrained_model.ipynb - loads the pre-trained model from
./solidity_model_text
to hallucinate more solidity. - ./tutorial_1_train_and_hallucinate_save_restore_continue_training.ipynb - is the code that downloads samples from https://github.com/tintinweb/smart-contract-sanctuary, creates the model, trains it, hallucinates some text, and then continues to show how to save/restore/re-train the model. Ultimately, the model is exported and converted to tensorflow.js conform format so that it can be used with any javascript/web-front/backend.
Copy the two tutorials to your google drive and run them.
print(trainingData.predict(['contract '], 3000))
contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
function Ownable() public {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
contract Parminicinvition is Ownable {
using SafeMath for uint256;
enum State { Approve = token.totalSupply();
require(tokens >= summaryTokens.add(bonus));
totalDailydested = totalEthInWei + msg.value;
totalSoldTokens = token.totalSupply();
emit Transfer(address(0), 0xCf49B9298aC4d4933a7D6984d89A49aDc84A6CA602BA513D872C3,21f36325D28718](0));
totalSupply = totalSupply.mul(totalValue.add(soldSignedMap[tokensBough.mul(1)));
restributedPluyRates[msg.sender] = true;
nonStokenSupplyFinallow
}
if(opits[msg.sender].amount <= totalSupply)) ether;
}
assignOpe(address(this).balance, weiAmount);
require(canTra_secrecover(_approved) >= rNo(_reward, _weight, _amount);
totalAmount = totalAmount.add(_amount);
Transfer(_addr, msg.sender, amount);
}
...
Based on the TensorFlow Text Generation Tutorial