From 38565d20501979cd2b451f3eb8a9e6c630f135a1 Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Wed, 3 Oct 2018 14:08:51 -0300 Subject: [PATCH 1/5] Add gas price on initialize foreign erc-to-erc --- .../erc20_to_erc20/ForeignBridgeErcToErc.sol | 5 ++++- deploy/src/erc_to_erc/foreign.js | 6 ++++-- test/erc_to_erc/foreign_bridge.test.js | 15 +++++++++------ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/contracts/upgradeable_contracts/erc20_to_erc20/ForeignBridgeErcToErc.sol b/contracts/upgradeable_contracts/erc20_to_erc20/ForeignBridgeErcToErc.sol index 091c086b3..768eceb91 100644 --- a/contracts/upgradeable_contracts/erc20_to_erc20/ForeignBridgeErcToErc.sol +++ b/contracts/upgradeable_contracts/erc20_to_erc20/ForeignBridgeErcToErc.sol @@ -15,15 +15,18 @@ contract ForeignBridgeErcToErc is BasicBridge, BasicForeignBridge { function initialize( address _validatorContract, address _erc20token, - uint256 _requiredBlockConfirmations + uint256 _requiredBlockConfirmations, + uint256 _gasPrice ) public returns(bool) { require(!isInitialized(), "already initialized"); require(_validatorContract != address(0), "address cannot be empty"); require(_requiredBlockConfirmations != 0, "requiredBlockConfirmations cannot be 0"); + require(_gasPrice > 0); addressStorage[keccak256(abi.encodePacked("validatorContract"))] = _validatorContract; setErc20token(_erc20token); uintStorage[keccak256(abi.encodePacked("deployedAtBlock"))] = block.number; uintStorage[keccak256(abi.encodePacked("requiredBlockConfirmations"))] = _requiredBlockConfirmations; + uintStorage[keccak256(abi.encodePacked("gasPrice"))] = _gasPrice; setInitialize(true); return isInitialized(); } diff --git a/deploy/src/erc_to_erc/foreign.js b/deploy/src/erc_to_erc/foreign.js index 91c1b0f68..9127d5f1e 100644 --- a/deploy/src/erc_to_erc/foreign.js +++ b/deploy/src/erc_to_erc/foreign.js @@ -18,7 +18,8 @@ const { FOREIGN_UPGRADEABLE_ADMIN_VALIDATORS, FOREIGN_UPGRADEABLE_ADMIN_BRIDGE, FOREIGN_REQUIRED_BLOCK_CONFIRMATIONS, - ERC20_TOKEN_ADDRESS + ERC20_TOKEN_ADDRESS, + FOREIGN_GAS_PRICE } = env const DEPLOYMENT_ACCOUNT_ADDRESS = privateKeyToAddress(DEPLOYMENT_ACCOUNT_PRIVATE_KEY) @@ -142,7 +143,8 @@ async function deployForeign() { .initialize( storageValidatorsForeign.options.address, ERC20_TOKEN_ADDRESS, - FOREIGN_REQUIRED_BLOCK_CONFIRMATIONS + FOREIGN_REQUIRED_BLOCK_CONFIRMATIONS, + FOREIGN_GAS_PRICE ) .encodeABI({ from: DEPLOYMENT_ACCOUNT_ADDRESS }) const txInitializeBridge = await sendRawTxForeign({ diff --git a/test/erc_to_erc/foreign_bridge.test.js b/test/erc_to_erc/foreign_bridge.test.js index 4d5ba7adf..d3b95ac1d 100644 --- a/test/erc_to_erc/foreign_bridge.test.js +++ b/test/erc_to_erc/foreign_bridge.test.js @@ -8,6 +8,7 @@ const {ERROR_MSG, ZERO_ADDRESS} = require('../setup'); const {createMessage, sign, signatureToVRS} = require('../helpers/helpers'); const halfEther = web3.toBigNumber(web3.toWei(0.5, "ether")); const requireBlockConfirmations = 8; +const gasPrice = web3.toWei('1', 'gwei') contract('ForeignBridge_ERC20_to_ERC20', async (accounts) => { let validatorContract, authorities, owner, token; @@ -28,7 +29,7 @@ contract('ForeignBridge_ERC20_to_ERC20', async (accounts) => { '0'.should.be.bignumber.equal(await foreignBridge.deployedAtBlock()) false.should.be.equal(await foreignBridge.isInitialized()) '0'.should.be.bignumber.equal(await foreignBridge.requiredBlockConfirmations()) - await foreignBridge.initialize(validatorContract.address, token.address, requireBlockConfirmations); + await foreignBridge.initialize(validatorContract.address, token.address, requireBlockConfirmations, gasPrice); token.address.should.be.equal(await foreignBridge.erc20token()); true.should.be.equal(await foreignBridge.isInitialized()) @@ -36,6 +37,8 @@ contract('ForeignBridge_ERC20_to_ERC20', async (accounts) => { token.address.should.be.equal(await foreignBridge.erc20token()); (await foreignBridge.deployedAtBlock()).should.be.bignumber.above(0); requireBlockConfirmations.should.be.bignumber.equal(await foreignBridge.requiredBlockConfirmations()) + const contractGasPrice = await foreignBridge.gasPrice() + contractGasPrice.should.be.bignumber.equal(gasPrice) const bridgeMode = '0xba4690f5' // 4 bytes of keccak256('erc-to-erc-core') const mode = await foreignBridge.getBridgeMode(); mode.should.be.equal(bridgeMode) @@ -50,7 +53,7 @@ contract('ForeignBridge_ERC20_to_ERC20', async (accounts) => { beforeEach(async () => { foreignBridge = await ForeignBridge.new() token = await ERC677BridgeToken.new("Some ERC20", "RSZT", 18); - await foreignBridge.initialize(validatorContract.address, token.address, requireBlockConfirmations); + await foreignBridge.initialize(validatorContract.address, token.address, requireBlockConfirmations, gasPrice); await token.mint(foreignBridge.address,value); }) it('should allow to executeSignatures', async () => { @@ -134,7 +137,7 @@ contract('ForeignBridge_ERC20_to_ERC20', async (accounts) => { await multisigValidatorContract.initialize(2, twoAuthorities, ownerOfValidatorContract, {from: ownerOfValidatorContract}) foreignBridgeWithMultiSignatures = await ForeignBridge.new() const oneEther = web3.toBigNumber(web3.toWei(1, "ether")); - await foreignBridgeWithMultiSignatures.initialize(multisigValidatorContract.address, token.address, requireBlockConfirmations, {from: ownerOfValidatorContract}); + await foreignBridgeWithMultiSignatures.initialize(multisigValidatorContract.address, token.address, requireBlockConfirmations, gasPrice, {from: ownerOfValidatorContract}); await token.mint(foreignBridgeWithMultiSignatures.address,value); }) it('withdraw should fail if not enough signatures are provided', async () => { @@ -191,7 +194,7 @@ contract('ForeignBridge_ERC20_to_ERC20', async (accounts) => { await foreignBridgeProxy.upgradeTo('1', foreignBridgeImpl.address).should.be.fulfilled; foreignBridgeProxy = await ForeignBridge.at(foreignBridgeProxy.address); - await foreignBridgeProxy.initialize(validatorsProxy.address, token.address, requireBlockConfirmations) + await foreignBridgeProxy.initialize(validatorsProxy.address, token.address, requireBlockConfirmations, gasPrice) // Deploy V2 let foreignImplV2 = await ForeignBridgeV2.new(); @@ -211,7 +214,7 @@ contract('ForeignBridge_ERC20_to_ERC20', async (accounts) => { let storageProxy = await EternalStorageProxy.new().should.be.fulfilled; let foreignBridge = await ForeignBridge.new(); let data = foreignBridge.initialize.request( - fakeValidatorsAddress, fakeTokenAddress, requireBlockConfirmations).params[0].data + fakeValidatorsAddress, fakeTokenAddress, requireBlockConfirmations, gasPrice).params[0].data await storageProxy.upgradeToAndCall('1', foreignBridge.address, data).should.be.fulfilled; let finalContract = await ForeignBridge.at(storageProxy.address); true.should.be.equal(await finalContract.isInitialized()); @@ -224,7 +227,7 @@ contract('ForeignBridge_ERC20_to_ERC20', async (accounts) => { const owner = accounts[0]; token = await ERC677BridgeToken.new("Some ERC20", "RSZT", 18); foreignBridge = await ForeignBridge.new(); - await foreignBridge.initialize(validatorContract.address, token.address, requireBlockConfirmations); + await foreignBridge.initialize(validatorContract.address, token.address, requireBlockConfirmations, gasPrice); let tokenSecond = await ERC677BridgeToken.new("Roman Token", "RST", 18); From 4f30ca81adb521f37f33d0b1fdb4cf4695124e0c Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Thu, 4 Oct 2018 10:54:27 -0300 Subject: [PATCH 2/5] Test initialize fails if incorrect number of parameters --- test/erc_to_erc/foreign_bridge.test.js | 5 ++++- test/setup.js | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/test/erc_to_erc/foreign_bridge.test.js b/test/erc_to_erc/foreign_bridge.test.js index d3b95ac1d..b53f76074 100644 --- a/test/erc_to_erc/foreign_bridge.test.js +++ b/test/erc_to_erc/foreign_bridge.test.js @@ -4,7 +4,7 @@ const BridgeValidators = artifacts.require("BridgeValidators.sol"); const EternalStorageProxy = artifacts.require("EternalStorageProxy.sol"); const ERC677BridgeToken = artifacts.require("ERC677BridgeToken.sol"); -const {ERROR_MSG, ZERO_ADDRESS} = require('../setup'); +const {ERROR_MSG, ZERO_ADDRESS, INVALID_ARGUMENTS} = require('../setup'); const {createMessage, sign, signatureToVRS} = require('../helpers/helpers'); const halfEther = web3.toBigNumber(web3.toWei(0.5, "ether")); const requireBlockConfirmations = 8; @@ -29,6 +29,9 @@ contract('ForeignBridge_ERC20_to_ERC20', async (accounts) => { '0'.should.be.bignumber.equal(await foreignBridge.deployedAtBlock()) false.should.be.equal(await foreignBridge.isInitialized()) '0'.should.be.bignumber.equal(await foreignBridge.requiredBlockConfirmations()) + + await foreignBridge.initialize(validatorContract.address, token.address, requireBlockConfirmations).should.be.rejectedWith(INVALID_ARGUMENTS); + await foreignBridge.initialize(validatorContract.address, token.address, requireBlockConfirmations, gasPrice); token.address.should.be.equal(await foreignBridge.erc20token()); diff --git a/test/setup.js b/test/setup.js index cf96cdf10..c8f0382ab 100644 --- a/test/setup.js +++ b/test/setup.js @@ -8,3 +8,4 @@ require('chai') exports.ERROR_MSG = 'VM Exception while processing transaction: revert'; exports.ERROR_MSG_OPCODE = 'VM Exception while processing transaction: invalid opcode'; exports.ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' +exports.INVALID_ARGUMENTS = 'Invalid number of arguments to Solidity function' From 205a7c3d1277958137fedf16569d03eac67bf4bb Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Mon, 8 Oct 2018 17:19:44 -0300 Subject: [PATCH 3/5] Remove revert reason ForeignBridgeErcToErc --- .../erc20_to_erc20/ForeignBridgeErcToErc.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/upgradeable_contracts/erc20_to_erc20/ForeignBridgeErcToErc.sol b/contracts/upgradeable_contracts/erc20_to_erc20/ForeignBridgeErcToErc.sol index 768eceb91..24f24a352 100644 --- a/contracts/upgradeable_contracts/erc20_to_erc20/ForeignBridgeErcToErc.sol +++ b/contracts/upgradeable_contracts/erc20_to_erc20/ForeignBridgeErcToErc.sol @@ -18,9 +18,9 @@ contract ForeignBridgeErcToErc is BasicBridge, BasicForeignBridge { uint256 _requiredBlockConfirmations, uint256 _gasPrice ) public returns(bool) { - require(!isInitialized(), "already initialized"); - require(_validatorContract != address(0), "address cannot be empty"); - require(_requiredBlockConfirmations != 0, "requiredBlockConfirmations cannot be 0"); + require(!isInitialized()); + require(_validatorContract != address(0)); + require(_requiredBlockConfirmations != 0); require(_gasPrice > 0); addressStorage[keccak256(abi.encodePacked("validatorContract"))] = _validatorContract; setErc20token(_erc20token); From a4beb533483c29c8ebba50473fbd074693f55428 Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Mon, 8 Oct 2018 17:20:03 -0300 Subject: [PATCH 4/5] Remove revert reason ForeignBridgeErcToNative --- .../erc20_to_native/ForeignBridgeErcToNative.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/upgradeable_contracts/erc20_to_native/ForeignBridgeErcToNative.sol b/contracts/upgradeable_contracts/erc20_to_native/ForeignBridgeErcToNative.sol index 3d4363e0a..eaa408b99 100644 --- a/contracts/upgradeable_contracts/erc20_to_native/ForeignBridgeErcToNative.sol +++ b/contracts/upgradeable_contracts/erc20_to_native/ForeignBridgeErcToNative.sol @@ -17,9 +17,9 @@ contract ForeignBridgeErcToNative is BasicBridge, BasicForeignBridge { uint256 _requiredBlockConfirmations, uint256 _gasPrice ) public returns(bool) { - require(!isInitialized(), "already initialized"); - require(_validatorContract != address(0), "address cannot be empty"); - require(_requiredBlockConfirmations != 0, "requiredBlockConfirmations cannot be 0"); + require(!isInitialized()); + require(_validatorContract != address(0)); + require(_requiredBlockConfirmations != 0); require(_gasPrice > 0); addressStorage[keccak256(abi.encodePacked("validatorContract"))] = _validatorContract; setErc20token(_erc20token); From 31de52fe6b1152958fb4da5f2a686edc895cc84f Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Mon, 8 Oct 2018 17:27:35 -0300 Subject: [PATCH 5/5] Update initialize tests ForeignBridgeErcToErc --- test/erc_to_erc/foreign_bridge.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/erc_to_erc/foreign_bridge.test.js b/test/erc_to_erc/foreign_bridge.test.js index b53f76074..d7f2a30d3 100644 --- a/test/erc_to_erc/foreign_bridge.test.js +++ b/test/erc_to_erc/foreign_bridge.test.js @@ -32,6 +32,11 @@ contract('ForeignBridge_ERC20_to_ERC20', async (accounts) => { await foreignBridge.initialize(validatorContract.address, token.address, requireBlockConfirmations).should.be.rejectedWith(INVALID_ARGUMENTS); + await foreignBridge.initialize(ZERO_ADDRESS, token.address, requireBlockConfirmations, gasPrice).should.be.rejectedWith(ERROR_MSG); + await foreignBridge.initialize(validatorContract.address, ZERO_ADDRESS, requireBlockConfirmations, gasPrice).should.be.rejectedWith(ERROR_MSG); + await foreignBridge.initialize(validatorContract.address, token.address, 0, gasPrice).should.be.rejectedWith(ERROR_MSG); + await foreignBridge.initialize(validatorContract.address, token.address, requireBlockConfirmations, 0).should.be.rejectedWith(ERROR_MSG); + await foreignBridge.initialize(validatorContract.address, token.address, requireBlockConfirmations, gasPrice); token.address.should.be.equal(await foreignBridge.erc20token());