diff --git a/config/contracts.json b/config/contracts.json index 0f85e33..7491c92 100644 --- a/config/contracts.json +++ b/config/contracts.json @@ -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} diff --git a/contracts/deploy/Factory.sol b/contracts/deploy/Factory.sol index b85a80e..eec1b73 100644 --- a/contracts/deploy/Factory.sol +++ b/contracts/deploy/Factory.sol @@ -13,7 +13,8 @@ contract Factory is Controlled { bytes32 codeHash; } - mapping (address => uint256) versionMap; + mapping(bytes32 => uint256) hashToVersion; + mapping(address => uint256) versionMap; Version[] versionLog; uint256 latestUpdate; @@ -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; diff --git a/gas-relayer/config/config.json b/gas-relayer/config/config.json index b2893ac..7caf8a3 100644 --- a/gas-relayer/config/config.json +++ b/gas-relayer/config/config.json @@ -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)", diff --git a/gas-relayer/src/contract-settings.js b/gas-relayer/src/contract-settings.js index ba617a0..16a4a8c 100644 --- a/gas-relayer/src/contract-settings.js +++ b/gas-relayer/src/contract-settings.js @@ -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); }) diff --git a/gas-relayer/src/message-processor.js b/gas-relayer/src/message-processor.js index 2682504..01fe2d1 100644 --- a/gas-relayer/src/message-processor.js +++ b/gas-relayer/src/message-processor.js @@ -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); - - return await this.web3.eth.call({ + const instanceCodeHash = this.web3.utils.soliditySha3(await this.web3.eth.getCode(input.address)); + const kernelVerifSignature = this.web3.utils.soliditySha3(contract.kernelVerification).slice(0, 10); + + 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){