From 6a07eefba650b8254b327549ebbc5988385d66ea Mon Sep 17 00:00:00 2001 From: David Ansermino Date: Fri, 19 Jun 2020 10:17:06 -0400 Subject: [PATCH] Update proposal mapping (#184) - Updates proposal mappings to use hash of proposal data as a key - Combines nonce and source chain ID into a single key --- contracts/Bridge.sol | 60 +++++++++++++------- test/contractBridge/cancelDepositProposal.js | 16 +++--- test/contractBridge/createDepositProposal.js | 10 ++-- test/contractBridge/depositERC20.js | 2 +- test/contractBridge/depositERC721.js | 2 +- test/contractBridge/depositGeneric.js | 2 +- test/contractBridge/fee.js | 11 +++- test/contractBridge/voteDepositProposal.js | 20 +++---- test/e2e/erc20/differentChainsMock.js | 2 + test/e2e/erc20/sameChain.js | 1 + test/e2e/erc721/differentChainsMock.js | 2 + test/e2e/erc721/sameChain.js | 1 + test/gasBenchmarks/executeProposal.js | 16 +++--- test/handlers/generic/executeProposal.js | 2 + test/helpers.js | 7 ++- 15 files changed, 95 insertions(+), 59 deletions(-) diff --git a/contracts/Bridge.sol b/contracts/Bridge.sol index 8868dfe3..86f341e0 100644 --- a/contracts/Bridge.sol +++ b/contracts/Bridge.sol @@ -40,12 +40,12 @@ contract Bridge is Pausable, AccessControl { mapping(uint8 => uint64) public _depositCounts; // resourceID => handler address mapping(bytes32 => address) public _resourceIDToHandlerAddress; - // destinationChainID => depositNonce => bytes - mapping(uint8 => mapping(uint64 => bytes)) public _depositRecords; - // destinationChainID => depositNonce => Proposal - mapping(uint8 => mapping(uint64 => Proposal)) public _proposals; - // destinationChainID => depositNonce => relayerAddress => bool - mapping(uint8 => mapping(uint64 => mapping(address => bool))) public _hasVotedOnProposal; + // depositNonce => destinationChainID => bytes + mapping(uint64 => mapping(uint8 => bytes)) public _depositRecords; + // destinationChainID + depositNonce => dataHash => Proposal + mapping(uint72 => mapping(bytes32 => Proposal)) public _proposals; + // destinationChainID + depositNonce => dataHash => relayerAddress => bool + mapping(uint72 => mapping(bytes32 => mapping(address => bool))) public _hasVotedOnProposal; event RelayerThresholdChanged(uint indexed newThreshold); event RelayerAdded(address indexed relayer); @@ -261,14 +261,16 @@ contract Bridge is Pausable, AccessControl { @notice Returns a proposal. @param originChainID Chain ID deposit originated from. @param depositNonce ID of proposal generated by proposal's origin Bridge contract. + @param dataHash Hash of data to be provided when deposit proposal is executed. @return Proposal which consists of: - _dataHash Hash of data to be provided when deposit proposal is executed. - _yesVotes Number of votes in favor of proposal. - _noVotes Number of votes against proposal. - _status Current status of proposal. */ - function getProposal(uint8 originChainID, uint64 depositNonce) external view returns (Proposal memory) { - return _proposals[originChainID][depositNonce]; + function getProposal(uint8 originChainID, uint64 depositNonce, bytes32 dataHash) external view returns (Proposal memory) { + uint72 nonceAndID = (uint72(depositNonce) << 8) | uint72(originChainID); + return _proposals[nonceAndID][dataHash]; } /** @@ -313,7 +315,7 @@ contract Bridge is Pausable, AccessControl { require(handler != address(0), "resourceID not mapped to handler address"); uint64 depositNonce = ++_depositCounts[destinationChainID]; - _depositRecords[destinationChainID][depositNonce] = data; + _depositRecords[depositNonce][destinationChainID] = data; IDepositExecute depositHandler = IDepositExecute(handler); depositHandler.deposit(resourceID, destinationChainID, depositNonce, msg.sender, data); @@ -335,15 +337,17 @@ contract Bridge is Pausable, AccessControl { {_relayerThreshold}. */ function voteProposal(uint8 chainID, uint64 depositNonce, bytes32 resourceID, bytes32 dataHash) external onlyRelayers whenNotPaused { - Proposal storage proposal = _proposals[uint8(chainID)][depositNonce]; + + uint72 nonceAndID = (uint72(depositNonce) << 8) | uint72(chainID); + Proposal storage proposal = _proposals[nonceAndID][dataHash]; require(_resourceIDToHandlerAddress[resourceID] != address(0), "no handler for resourceID"); require(uint(proposal._status) <= 1, "proposal has already been passed, transferred, or cancelled"); - require(!_hasVotedOnProposal[chainID][depositNonce][msg.sender], "relayer has already voted on proposal"); + require(!_hasVotedOnProposal[nonceAndID][dataHash][msg.sender], "relayer has already voted on proposal"); if (uint(proposal._status) == 0) { ++_totalProposals; - _proposals[chainID][depositNonce] = Proposal({ + _proposals[nonceAndID][dataHash] = Proposal({ _resourceID: resourceID, _dataHash: dataHash, _yesVotes: new address[](1), @@ -364,11 +368,12 @@ contract Bridge is Pausable, AccessControl { require(dataHash == proposal._dataHash, "datahash mismatch"); proposal._yesVotes.push(msg.sender); + } } if (proposal._status != ProposalStatus.Cancelled) { - _hasVotedOnProposal[chainID][depositNonce][msg.sender] = true; + _hasVotedOnProposal[nonceAndID][dataHash][msg.sender] = true; emit ProposalVote(chainID, _chainID, depositNonce, resourceID, proposal._status); // If _depositThreshold is set to 1, then auto finalize @@ -381,8 +386,19 @@ contract Bridge is Pausable, AccessControl { } - function cancelProposal(uint8 chainID, uint64 depositNonce) public onlyAdminOrRelayer { - Proposal storage proposal = _proposals[uint8(chainID)][depositNonce]; + /** + @notice Executes a deposit proposal that is considered passed using a specified handler contract. + @notice Only callable by relayers when Bridge is not paused. + @param chainID ID of chain deposit originated from. + @param depositNonce ID of deposited generated by origin Bridge contract. + @param dataHash Hash of data originally provided when deposit was made. + @notice Proposal must be past expiry threshold. + @notice Emits {ProposalCancelled} event. + */ + function cancelProposal(uint8 chainID, uint64 depositNonce, bytes32 dataHash) public onlyAdminOrRelayer { + uint72 nonceAndID = (uint72(depositNonce) << 8) | uint72(chainID); + Proposal storage proposal = _proposals[nonceAndID][dataHash]; + require(proposal._status != ProposalStatus.Cancelled, "Proposal already cancelled"); require((block.number).sub(proposal._proposedBlock) > _expiry, "Proposal does not meet expiry threshold"); @@ -395,20 +411,22 @@ contract Bridge is Pausable, AccessControl { @notice Executes a deposit proposal that is considered passed using a specified handler contract. @notice Only callable by relayers when Bridge is not paused. @param chainID ID of chain deposit originated from. + @param resourceID ResourceID to be used when making deposits. @param depositNonce ID of deposited generated by origin Bridge contract. @param data Data originally provided when deposit was made. @notice Proposal must have Passed status. @notice Hash of {data} must equal proposal's {dataHash}. @notice Emits {ProposalExecuted} event. */ - function executeProposal(uint8 chainID, uint64 depositNonce, bytes calldata data) external onlyRelayers whenNotPaused { - Proposal storage proposal = _proposals[uint8(chainID)][depositNonce]; - address handler = _resourceIDToHandlerAddress[proposal._resourceID]; + function executeProposal(uint8 chainID, uint64 depositNonce, bytes calldata data, bytes32 resourceID) external onlyRelayers whenNotPaused { + address handler = _resourceIDToHandlerAddress[resourceID]; + uint72 nonceAndID = (uint72(depositNonce) << 8) | uint72(chainID); + bytes32 dataHash = keccak256(abi.encodePacked(handler, data)); + Proposal storage proposal = _proposals[nonceAndID][dataHash]; require(proposal._status != ProposalStatus.Inactive, "proposal is not active"); require(proposal._status == ProposalStatus.Passed, "proposal was not passed or has already been transferred"); - require(keccak256(abi.encodePacked(handler, data)) == proposal._dataHash, - "provided data does not match proposal's data hash"); + require(dataHash == proposal._dataHash, "provided data does not match proposal's data hash"); proposal._status = ProposalStatus.Transferred; @@ -430,4 +448,4 @@ contract Bridge is Pausable, AccessControl { } } -} \ No newline at end of file +} diff --git a/test/contractBridge/cancelDepositProposal.js b/test/contractBridge/cancelDepositProposal.js index 5597f8d0..b76e4312 100644 --- a/test/contractBridge/cancelDepositProposal.js +++ b/test/contractBridge/cancelDepositProposal.js @@ -90,7 +90,7 @@ contract('Bridge - [voteProposal with relayerThreshold == 3]', async (accounts) }; const depositProposal = await BridgeInstance.getProposal( - originChainID, expectedDepositNonce); + originChainID, expectedDepositNonce, depositDataHash); assert.deepInclude(Object.assign({}, depositProposal), expectedDepositProposal); }); @@ -114,7 +114,7 @@ contract('Bridge - [voteProposal with relayerThreshold == 3]', async (accounts) _status: '4' // Cancelled }; - const depositProposal = await BridgeInstance.getProposal(originChainID, expectedDepositNonce); + const depositProposal = await BridgeInstance.getProposal(originChainID, expectedDepositNonce, depositDataHash); assert.deepInclude(Object.assign({}, depositProposal), expectedDepositProposal); await TruffleAssert.reverts(vote(relayer3Address), "proposal has already been passed, transferred, or cancelled.") @@ -135,8 +135,8 @@ contract('Bridge - [voteProposal with relayerThreshold == 3]', async (accounts) _status: '4' // Cancelled }; - await TruffleAssert.passes(BridgeInstance.cancelProposal(originChainID, expectedDepositNonce)) - const depositProposal = await BridgeInstance.getProposal(originChainID, expectedDepositNonce); + await TruffleAssert.passes(BridgeInstance.cancelProposal(originChainID, expectedDepositNonce, depositDataHash)) + const depositProposal = await BridgeInstance.getProposal(originChainID, expectedDepositNonce, depositDataHash); assert.deepInclude(Object.assign({}, depositProposal), expectedDepositProposal); await TruffleAssert.reverts(vote(relayer4Address), "proposal has already been passed, transferred, or cancelled.") @@ -156,8 +156,8 @@ contract('Bridge - [voteProposal with relayerThreshold == 3]', async (accounts) _status: '4' // Cancelled }; - await TruffleAssert.passes(BridgeInstance.cancelProposal(originChainID, expectedDepositNonce)) - const depositProposal = await BridgeInstance.getProposal(originChainID, expectedDepositNonce); + await TruffleAssert.passes(BridgeInstance.cancelProposal(originChainID, expectedDepositNonce, depositDataHash)) + const depositProposal = await BridgeInstance.getProposal(originChainID, expectedDepositNonce, depositDataHash); assert.deepInclude(Object.assign({}, depositProposal), expectedDepositProposal); await TruffleAssert.reverts(vote(relayer2Address), "proposal has already been passed, transferred, or cancelled.") @@ -177,8 +177,8 @@ contract('Bridge - [voteProposal with relayerThreshold == 3]', async (accounts) _status: '4' // Cancelled }; - await TruffleAssert.passes(BridgeInstance.cancelProposal(originChainID, expectedDepositNonce)) - await TruffleAssert.reverts(BridgeInstance.cancelProposal(originChainID, expectedDepositNonce), "Proposal already cancelled") + await TruffleAssert.passes(BridgeInstance.cancelProposal(originChainID, expectedDepositNonce, depositDataHash)) + await TruffleAssert.reverts(BridgeInstance.cancelProposal(originChainID, expectedDepositNonce, depositDataHash), "Proposal already cancelled") }); diff --git a/test/contractBridge/createDepositProposal.js b/test/contractBridge/createDepositProposal.js index 195927da..13c3eae8 100644 --- a/test/contractBridge/createDepositProposal.js +++ b/test/contractBridge/createDepositProposal.js @@ -94,7 +94,7 @@ contract('Bridge - [create a deposit proposal (voteProposal) with relayerThresho it("getProposal should be called successfully", async () => { await TruffleAssert.passes(BridgeInstance.getProposal( - destinationChainID, expectedDepositNonce + destinationChainID, expectedDepositNonce, dataHash )); }); @@ -116,7 +116,7 @@ contract('Bridge - [create a deposit proposal (voteProposal) with relayerThresho ); const depositProposal = await BridgeInstance.getProposal( - destinationChainID, expectedDepositNonce); + destinationChainID, expectedDepositNonce, dataHash); Helpers.assertObjectsMatch(expectedDepositProposal, Object.assign({}, depositProposal)); }); @@ -129,7 +129,7 @@ contract('Bridge - [create a deposit proposal (voteProposal) with relayerThresho { from: originChainRelayerAddress } ); const hasVoted = await BridgeInstance._hasVotedOnProposal.call( - destinationChainID, expectedDepositNonce, originChainRelayerAddress); + Helpers.nonceAndId(expectedDepositNonce, destinationChainID), dataHash, originChainRelayerAddress); assert.isTrue(hasVoted); }); @@ -252,7 +252,7 @@ contract('Bridge - [create a deposit proposal (voteProposal) with relayerThresho ); const depositProposal = await BridgeInstance.getProposal( - destinationChainID, expectedDepositNonce); + destinationChainID, expectedDepositNonce, dataHash); Helpers.assertObjectsMatch(expectedDepositProposal, Object.assign({}, depositProposal)); }); @@ -265,7 +265,7 @@ contract('Bridge - [create a deposit proposal (voteProposal) with relayerThresho { from: originChainRelayerAddress } ); const hasVoted = await BridgeInstance._hasVotedOnProposal.call( - destinationChainID, expectedDepositNonce, originChainRelayerAddress); + Helpers.nonceAndId(expectedDepositNonce, destinationChainID), dataHash, originChainRelayerAddress); assert.isTrue(hasVoted); }); diff --git a/test/contractBridge/depositERC20.js b/test/contractBridge/depositERC20.js index b3600ff5..b43624b2 100644 --- a/test/contractBridge/depositERC20.js +++ b/test/contractBridge/depositERC20.js @@ -109,7 +109,7 @@ contract('Bridge - [deposit - ERC20]', async (accounts) => { { from: depositerAddress } ); - const depositRecord = await BridgeInstance._depositRecords.call(destinationChainID, expectedDepositNonce); + const depositRecord = await BridgeInstance._depositRecords.call(expectedDepositNonce, destinationChainID); assert.strictEqual(depositRecord, depositData.toLowerCase(), "Stored depositRecord does not match original depositData"); }); diff --git a/test/contractBridge/depositERC721.js b/test/contractBridge/depositERC721.js index 49eaa3fb..6a5f4ffc 100644 --- a/test/contractBridge/depositERC721.js +++ b/test/contractBridge/depositERC721.js @@ -129,7 +129,7 @@ contract('Bridge - [deposit - ERC721]', async (accounts) => { { from: depositerAddress } ); - const depositRecord = await BridgeInstance._depositRecords.call(destinationChainID, expectedDepositNonce); + const depositRecord = await BridgeInstance._depositRecords.call(expectedDepositNonce, destinationChainID); assert.strictEqual(depositRecord, depositData.toLowerCase(), "Stored depositRecord does not match original depositData"); }); diff --git a/test/contractBridge/depositGeneric.js b/test/contractBridge/depositGeneric.js index 6cdb7992..7dbf0ede 100644 --- a/test/contractBridge/depositGeneric.js +++ b/test/contractBridge/depositGeneric.js @@ -74,7 +74,7 @@ contract('Bridge - [deposit - Generic]', async () => { depositData ); - const depositRecord = await BridgeInstance._depositRecords.call(destinationChainID, expectedDepositNonce); + const depositRecord = await BridgeInstance._depositRecords.call(expectedDepositNonce, destinationChainID); assert.strictEqual(depositRecord, depositData.toLowerCase(), "Stored depositRecord does not match original depositData"); }); diff --git a/test/contractBridge/fee.js b/test/contractBridge/fee.js index 27714511..35d1741d 100644 --- a/test/contractBridge/fee.js +++ b/test/contractBridge/fee.js @@ -101,17 +101,22 @@ contract('Bridge - [fee]', async (accounts) => { // check the balance is 0 assert.equal(web3.utils.fromWei((await web3.eth.getBalance(BridgeInstance.address)), "ether"), "0"); await BridgeInstance.deposit(destinationChainID, resourceID, depositData, {value: Ethers.utils.parseEther("1")}) + assert.equal(web3.utils.fromWei((await web3.eth.getBalance(BridgeInstance.address)), "ether"), "1"); + let b1Before = await web3.eth.getBalance(accounts[1]); + let b2Before = await web3.eth.getBalance(accounts[2]); + + let payout = Ethers.utils.parseEther("0.5") // Transfer the funds TruffleAssert.passes( await BridgeInstance.transferFunds( [accounts[1], accounts[2]], - [Ethers.utils.parseEther("0.5"), Ethers.utils.parseEther("0.5")] + [payout, payout] ) ) b1 = await web3.eth.getBalance(accounts[1]); b2 = await web3.eth.getBalance(accounts[2]); - assert.equal(web3.utils.fromWei(b1), "100.5"); - assert.equal(web3.utils.fromWei(b2), "100.5"); + assert.equal(b1, Ethers.utils.bigNumberify(b1Before).add(payout)); + assert.equal(b2, Ethers.utils.bigNumberify(b2Before).add(payout)); }) }); \ No newline at end of file diff --git a/test/contractBridge/voteDepositProposal.js b/test/contractBridge/voteDepositProposal.js index 21c0f824..7b685e50 100644 --- a/test/contractBridge/voteDepositProposal.js +++ b/test/contractBridge/voteDepositProposal.js @@ -66,7 +66,7 @@ contract('Bridge - [voteProposal with relayerThreshold == 3]', async (accounts) ]); vote = (relayer) => BridgeInstance.voteProposal(originChainID, expectedDepositNonce, resourceID, depositDataHash, {from: relayer}); - executeProposal = (relayer) => BridgeInstance.executeProposal(originChainID, expectedDepositNonce, depositData, {from: relayer}); + executeProposal = (relayer) => BridgeInstance.executeProposal(originChainID, expectedDepositNonce, depositData, resourceID, {from: relayer}); }); it ('[sanity] bridge configured with threshold and relayers', async () => { @@ -88,7 +88,7 @@ contract('Bridge - [voteProposal with relayerThreshold == 3]', async (accounts) }; const depositProposal = await BridgeInstance.getProposal( - originChainID, expectedDepositNonce); + originChainID, expectedDepositNonce, depositDataHash); assert.deepInclude(Object.assign({}, depositProposal), expectedDepositProposal); }); @@ -126,21 +126,21 @@ contract('Bridge - [voteProposal with relayerThreshold == 3]', async (accounts) await TruffleAssert.reverts(vote(relayer1Address), 'relayer has already voted on proposal'); }); - it("Should revert because dataHash doesn't match", async () => { + it("Should be able to create a proposal with a different hash", async () => { await TruffleAssert.passes(vote(relayer1Address)); - await TruffleAssert.reverts( + await TruffleAssert.passes( BridgeInstance.voteProposal( originChainID, expectedDepositNonce, resourceID, Ethers.utils.keccak256(depositDataHash), - {from: relayer2Address}), 'datahash mismatch'); + {from: relayer2Address})); }); it("Relayer's vote should be recorded correctly - yes vote", async () => { await TruffleAssert.passes(vote(relayer1Address)); const depositProposalAfterFirstVote = await BridgeInstance.getProposal( - originChainID, expectedDepositNonce); + originChainID, expectedDepositNonce, depositDataHash); assert.strictEqual(depositProposalAfterFirstVote._yesVotes.length, 1); assert.deepEqual(depositProposalAfterFirstVote._yesVotes, [relayer1Address]); assert.strictEqual(depositProposalAfterFirstVote._noVotes.length, 0); @@ -149,7 +149,7 @@ contract('Bridge - [voteProposal with relayerThreshold == 3]', async (accounts) await TruffleAssert.passes(vote(relayer2Address)); const depositProposalAfterSecondVote = await BridgeInstance.getProposal( - originChainID, expectedDepositNonce); + originChainID, expectedDepositNonce, depositDataHash); assert.strictEqual(depositProposalAfterSecondVote._yesVotes.length, 2); assert.deepEqual(depositProposalAfterSecondVote._yesVotes, [relayer1Address, relayer2Address]); assert.strictEqual(depositProposalAfterSecondVote._noVotes.length, 0); @@ -158,7 +158,7 @@ contract('Bridge - [voteProposal with relayerThreshold == 3]', async (accounts) await TruffleAssert.passes(vote(relayer3Address)); const depositProposalAfterThirdVote = await BridgeInstance.getProposal( - originChainID, expectedDepositNonce); + originChainID, expectedDepositNonce, depositDataHash); assert.strictEqual(depositProposalAfterThirdVote._yesVotes.length, 3); assert.deepEqual(depositProposalAfterThirdVote._yesVotes, [relayer1Address, relayer2Address, relayer3Address]); assert.strictEqual(depositProposalAfterThirdVote._noVotes.length, 0); @@ -167,7 +167,7 @@ contract('Bridge - [voteProposal with relayerThreshold == 3]', async (accounts) await TruffleAssert.passes(executeProposal(relayer1Address)); const depositProposalAfterExecute = await BridgeInstance.getProposal( - originChainID, expectedDepositNonce); + originChainID, expectedDepositNonce, depositDataHash); assert.strictEqual(depositProposalAfterExecute._yesVotes.length, 3); assert.deepEqual(depositProposalAfterExecute._yesVotes, [relayer1Address, relayer2Address, relayer3Address]); assert.strictEqual(depositProposalAfterExecute._noVotes.length, 0); @@ -178,7 +178,7 @@ contract('Bridge - [voteProposal with relayerThreshold == 3]', async (accounts) await TruffleAssert.passes(vote(relayer1Address)); const hasVoted = await BridgeInstance._hasVotedOnProposal.call( - originChainID, expectedDepositNonce, relayer1Address); + Helpers.nonceAndId(expectedDepositNonce, originChainID), depositDataHash, relayer1Address); assert.isTrue(hasVoted); }); diff --git a/test/e2e/erc20/differentChainsMock.js b/test/e2e/erc20/differentChainsMock.js index 35903027..1eb7eb7b 100644 --- a/test/e2e/erc20/differentChainsMock.js +++ b/test/e2e/erc20/differentChainsMock.js @@ -144,6 +144,7 @@ contract('E2E ERC20 - Two EVM Chains', async accounts => { originChainID, expectedDepositNonce, originDepositProposalData, + destinationResourceID, { from: destinationRelayer2Address } )); @@ -201,6 +202,7 @@ contract('E2E ERC20 - Two EVM Chains', async accounts => { destinationChainID, expectedDepositNonce, destinationDepositProposalData, + originResourceID, { from: originRelayer2Address } )); diff --git a/test/e2e/erc20/sameChain.js b/test/e2e/erc20/sameChain.js index 140d5fbe..9a945a15 100644 --- a/test/e2e/erc20/sameChain.js +++ b/test/e2e/erc20/sameChain.js @@ -106,6 +106,7 @@ contract('E2E ERC20 - Same Chain', async accounts => { chainID, expectedDepositNonce, depositProposalData, + resourceID, { from: relayer2Address } )); diff --git a/test/e2e/erc721/differentChainsMock.js b/test/e2e/erc721/differentChainsMock.js index 5cd98a62..cd12f4de 100644 --- a/test/e2e/erc721/differentChainsMock.js +++ b/test/e2e/erc721/differentChainsMock.js @@ -139,6 +139,7 @@ contract('E2E ERC721 - Two EVM Chains', async accounts => { originChainID, expectedDepositNonce, originDepositProposalData, + destinationResourceID, {from: destinationRelayer2Address} )); @@ -192,6 +193,7 @@ contract('E2E ERC721 - Two EVM Chains', async accounts => { destinationChainID, expectedDepositNonce, destinationDepositProposalData, + originResourceID, {from: originRelayer2Address} )); diff --git a/test/e2e/erc721/sameChain.js b/test/e2e/erc721/sameChain.js index fad49c0a..b51e59cc 100644 --- a/test/e2e/erc721/sameChain.js +++ b/test/e2e/erc721/sameChain.js @@ -115,6 +115,7 @@ contract('E2E ERC721 - Same Chain', async accounts => { chainID, expectedDepositNonce, proposalData, + resourceID, { from: relayer2Address } )); diff --git a/test/gasBenchmarks/executeProposal.js b/test/gasBenchmarks/executeProposal.js index 54b141ca..5ee8c7eb 100644 --- a/test/gasBenchmarks/executeProposal.js +++ b/test/gasBenchmarks/executeProposal.js @@ -52,7 +52,7 @@ contract('Gas Benchmark - [Execute Proposal]', async (accounts) => { const deposit = (resourceID, depositData) => BridgeInstance.deposit(chainID, resourceID, depositData, { from: depositerAddress }); const vote = (resourceID, depositNonce, depositDataHash) => BridgeInstance.voteProposal(chainID, depositNonce, resourceID, depositDataHash, { from: relayerAddress }); - const execute = (depositNonce, depositData) => BridgeInstance.executeProposal(chainID, depositNonce, depositData); + const execute = (depositNonce, depositData, resourceID) => BridgeInstance.executeProposal(chainID, depositNonce, depositData, resourceID); before(async () => { await Promise.all([ @@ -139,7 +139,7 @@ contract('Gas Benchmark - [Execute Proposal]', async (accounts) => { await deposit(erc20ResourceID, depositData); await vote(erc20ResourceID, depositNonce, depositDataHash, relayerAddress); - const executeTx = await execute(depositNonce, depositData); + const executeTx = await execute(depositNonce, depositData, erc20ResourceID); gasBenchmarks.push({ type: 'ERC20', @@ -162,7 +162,7 @@ contract('Gas Benchmark - [Execute Proposal]', async (accounts) => { await deposit(erc721ResourceID, depositData); await vote(erc721ResourceID, depositNonce, depositDataHash, relayerAddress); - const executeTx = await execute(depositNonce, depositData); + const executeTx = await execute(depositNonce, depositData, erc721ResourceID); gasBenchmarks.push({ type: 'ERC721', @@ -179,7 +179,7 @@ contract('Gas Benchmark - [Execute Proposal]', async (accounts) => { await deposit(centrifugeAssetResourceID, depositData); await vote(centrifugeAssetResourceID, depositNonce, depositDataHash, relayerAddress); - const executeTx = await execute(depositNonce, depositData); + const executeTx = await execute(depositNonce, depositData, centrifugeAssetResourceID); gasBenchmarks.push({ type: 'Generic - Centrifuge Asset', @@ -196,7 +196,7 @@ contract('Gas Benchmark - [Execute Proposal]', async (accounts) => { await deposit(noArgumentResourceID, depositData); await vote(noArgumentResourceID, depositNonce, depositDataHash, relayerAddress); - const executeTx = await execute(depositNonce, depositData); + const executeTx = await execute(depositNonce, depositData, noArgumentResourceID); gasBenchmarks.push({ type: 'Generic - No Argument', @@ -212,7 +212,7 @@ contract('Gas Benchmark - [Execute Proposal]', async (accounts) => { await deposit(oneArgumentResourceID, depositData); await vote(oneArgumentResourceID, depositNonce, depositDataHash, relayerAddress); - const executeTx = await execute(depositNonce, depositData); + const executeTx = await execute(depositNonce, depositData, oneArgumentResourceID); gasBenchmarks.push({ type: 'Generic - One Argument', @@ -231,7 +231,7 @@ contract('Gas Benchmark - [Execute Proposal]', async (accounts) => { await deposit(twoArgumentsResourceID, depositData); await vote(twoArgumentsResourceID, depositNonce, depositDataHash, relayerAddress); - const executeTx = await execute(depositNonce, depositData); + const executeTx = await execute(depositNonce, depositData, twoArgumentsResourceID); gasBenchmarks.push({ type: 'Generic - Two Argument', @@ -251,7 +251,7 @@ contract('Gas Benchmark - [Execute Proposal]', async (accounts) => { await deposit(threeArgumentsResourceID, depositData); await vote(threeArgumentsResourceID, depositNonce, depositDataHash, relayerAddress); - const executeTx = await execute(depositNonce, depositData); + const executeTx = await execute(depositNonce, depositData, threeArgumentsResourceID); gasBenchmarks.push({ type: 'Generic - Three Argument', diff --git a/test/handlers/generic/executeProposal.js b/test/handlers/generic/executeProposal.js index fd871179..6c4c35f2 100644 --- a/test/handlers/generic/executeProposal.js +++ b/test/handlers/generic/executeProposal.js @@ -96,6 +96,7 @@ contract('GenericHandler - [Execute Proposal]', async (accounts) => { chainID, expectedDepositNonce, depositData, + resourceID, { from: relayer2Address } )); @@ -136,6 +137,7 @@ contract('GenericHandler - [Execute Proposal]', async (accounts) => { chainID, expectedDepositNonce, depositData, + resourceID, { from: relayer2Address } ); diff --git a/test/helpers.js b/test/helpers.js index 63d8a025..6eecd1f8 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -91,6 +91,10 @@ const assertObjectsMatch = (expectedObj, actualObj) => { assert.deepEqual(expectedValue, actualValue, `expectedValue: ${expectedValue} does not match actualValue: ${actualValue}`); } }; +//uint72 nonceAndID = (uint72(depositNonce) << 8) | uint72(chainID); +const nonceAndId = (nonce, id) => { + return Ethers.utils.hexZeroPad(Ethers.utils.hexlify(nonce), 8) + Ethers.utils.hexZeroPad(Ethers.utils.hexlify(id), 1).substr(2) +} module.exports = { advanceBlock, @@ -102,5 +106,6 @@ module.exports = { createGenericDepositData, createERC721DepositProposalData, createResourceID, - assertObjectsMatch + assertObjectsMatch, + nonceAndId };