Contract code verification

This commit is contained in:
Richard Ramos 2018-05-03 15:41:25 -04:00
parent b90ac50ec9
commit 9cd85e6541
5 changed files with 24 additions and 13 deletions

View File

@ -34,7 +34,11 @@
"Owned": {"deploy": false},
"IdentityGasRelay": {"gasLimit": 4000000},
"IdentityKernel": {"deploy": false},
"IdentityFactory": {"args":["0x00"], "gasLimit": 4000000},
"IdentityFactory": {
"args":["0x00"],
"gasLimit": 5000000,
"onDeploy": ["IdentityFactory.methods.setKernel('$IdentityGasRelay').send({gasLimit: 1000000})"]
},
"SNTController": {"deploy": false},
"UpdatedIdentityKernel": {"deploy": false},
"TestContract": {"deploy": false}

View File

@ -13,6 +13,7 @@ contract Factory is Controlled {
bytes32 codeHash;
}
mapping(bytes32 => uint256) hashToVersion;
mapping(address => uint256) versionMap;
Version[] versionLog;
@ -50,6 +51,10 @@ contract Factory is Controlled {
);
}
function isKernel(bytes32 _codeHash) public returns (bool){
return hashToVersion[_codeHash] > 0;
}
function isKernel(address _addr) public returns (bool){
return versionMap[_addr] > 0;
}
@ -86,6 +91,7 @@ contract Factory is Controlled {
require(_kernel != latestKernel);
bytes32 _codeHash = getCodeHash(_kernel);
versionMap[_kernel] = versionLog.length;
hashToVersion[_codeHash] = versionLog.length;
versionLog.push(Version({blockNumber: block.number, timestamp: block.timestamp, kernel: _kernel, codeHash: _codeHash}));
latestUpdate = block.timestamp;
latestKernel = _kernel;

View File

@ -25,7 +25,7 @@
"name": "Ethereum",
"symbol": "ETH"
},
"0xf8a85AfA502a0A27aAA3528C62eB059Db97a6007": {
"0xD10e6dAe987Dcc0B3ADaA375C9f59690a4C97a27": {
"minRelayFactor": 10000,
"name": "Random Test Token",
"symbol": "RDN",
@ -37,8 +37,8 @@
"IdentityGasRelay": {
"abiFile": "../abi/IdentityGasRelay.json",
"isIdentity": true,
"factoryAddress": "0xdd8b8aCf484875dC6565F6B614B8Dc9C7f074C00",
"kernelVerification": "isKernel(address _addr)",
"factoryAddress": "0x5F6cDe612C45039AaC867075703Bc118cEA4D531",
"kernelVerification": "isKernel(bytes32)",
"allowedFunctions": [
{
"function": "approveAndCallGasRelayed(address,address,uint256,bytes,uint256,uint256,uint256,address,bytes)",

View File

@ -1,5 +1,3 @@
const md5 = require('md5');
class ContractSettings {
constructor(config, web3, eventEmitter){
@ -45,7 +43,7 @@ class ContractSettings {
this.pendingToLoad++;
this.web3.eth.getCode(this.contracts[topicName].address)
.then(code => {
this.contracts[topicName].code = md5(code);
this.contracts[topicName].code = this.web3.utils.soliditySha3(code);
this.pendingToLoad--;
if(this.pendingToLoad == 0) this.events.emit("setup:complete", this);
})

View File

@ -46,7 +46,7 @@ class MessageProcessor {
// Get code from address and compare it against the contract code
if(!contract.isIdentity){
const code = md5(await this.web3.eth.getCode(input.address));
const code = this.web3.utils.soliditySha3(await this.web3.eth.getCode(input.address));
if(code != contract.code){
this._reply('Invalid contract code', message);
return false;
@ -57,11 +57,14 @@ class MessageProcessor {
async _validateInstance(message, input){
const contract = this.settings.getContractByTopic(message.topic);
const kernelVerifSignature = this.web3.utils.sha3(contract.kernelVerification).slice(0, 10);
const instanceCodeHash = this.web3.utils.soliditySha3(await this.web3.eth.getCode(input.address));
const kernelVerifSignature = this.web3.utils.soliditySha3(contract.kernelVerification).slice(0, 10);
return await this.web3.eth.call({
let verificationResult = await this.web3.eth.call({
to: contract.factoryAddress,
data: kernelVerifSignature + "000000000000000000000000" + input.address.slice(2)});
data: kernelVerifSignature + instanceCodeHash.slice(2)});
return web3.eth.abi.decodeParameter('bool', verificationResult);;
}
_extractInput(message){