diff --git a/contracts b/contracts index 026dbfda..a5946e70 160000 --- a/contracts +++ b/contracts @@ -1 +1 @@ -Subproject commit 026dbfdac8eb067af078a69483f474051a8a6379 +Subproject commit a5946e7024caf598e562da916675a3b269ab293d diff --git a/monitor/utils/events.js b/monitor/utils/events.js index 57d89149..b97be18d 100644 --- a/monitor/utils/events.js +++ b/monitor/utils/events.js @@ -112,7 +112,26 @@ async function main(mode) { const bridgeTokensSwappedEvents = tokensSwappedEvents.filter(e => e.address === COMMON_FOREIGN_BRIDGE_ADDRESS) // Get transfer events for each previous erc20 - const uniqueTokenAddresses = [...new Set(bridgeTokensSwappedEvents.map(e => e.returnValues.from))] + const uniqueTokenAddressesSet = new Set(bridgeTokensSwappedEvents.map(e => e.returnValues.from)) + + // Exclude chai token from previous erc20 + try { + logger.debug('calling foreignBridge.chaiToken()') + const chaiToken = await foreignBridge.methods.chaiToken().call() + uniqueTokenAddressesSet.delete(chaiToken) + } catch (e) { + logger.debug('call to foreignBridge.chaiToken() failed') + } + // Exclude dai token from previous erc20 + try { + logger.debug('calling foreignBridge.erc20token()') + const daiToken = await foreignBridge.methods.erc20token().call() + uniqueTokenAddressesSet.delete(daiToken) + } catch (e) { + logger.debug('call to foreignBridge.erc20token() failed') + } + + const uniqueTokenAddresses = [...uniqueTokenAddressesSet] await Promise.all( uniqueTokenAddresses.map(async tokenAddress => { const halfDuplexTokenContract = new web3Foreign.eth.Contract(ERC20_ABI, tokenAddress) diff --git a/oracle-e2e/test/ercToNative.js b/oracle-e2e/test/ercToNative.js index 0b431390..8e92b4aa 100644 --- a/oracle-e2e/test/ercToNative.js +++ b/oracle-e2e/test/ercToNative.js @@ -552,4 +552,122 @@ describe('erc to native', () => { } }) }) + + describe('handling of chai swaps', async () => { + before(async () => { + // Next tests check validator nonces, this will force every validator to submit signature/affirmation + // Set 3 required signatures for home bridge + await setRequiredSignatures({ + bridgeContract: homeBridge, + web3: homeWeb3, + requiredSignatures: 3, + options: { + from: validator.address, + gas: '4000000' + } + }) + + // Set 3 required signatures for foreign bridge + await setRequiredSignatures({ + bridgeContract: foreignBridge, + web3: foreignWeb3, + requiredSignatures: 3, + options: { + from: validator.address, + gas: '4000000' + } + }) + }) + + it('should not handle transfer event in paying interest', async () => { + await foreignBridge.methods.setInterestReceiver(user.address).send({ + from: validator.address, + gas: '1000000' + }) + const initialNonce = await homeWeb3.eth.getTransactionCount(validator.address) + await foreignBridge.methods.payInterest().send({ + from: user.address, + gas: '1000000' + }) + + await promiseRetry(async (retry, number) => { + if (number < 6) { + retry() + } else { + const nonce = await homeWeb3.eth.getTransactionCount(validator.address) + assert( + nonce === initialNonce, + 'Validator should not process transfer event originated during converting Chai => Dai' + ) + } + }) + }) + + it('should not handle chai withdrawal transfer event in executeSignatures as a regular transfer', async () => { + await foreignBridge.methods.setMinDaiTokenBalance('0').send({ + from: validator.address, + gas: '1000000' + }) // set investing limit to 0 + await foreignBridge.methods.convertDaiToChai().send({ + from: validator.address, + gas: '1000000' + }) // convert all existing dai tokens on bridge account to chai, in order to start from zero balance + + const initialNonce = await homeWeb3.eth.getTransactionCount(validator.address) + + const originalBalance = await erc20Token.methods.balanceOf(user.address).call() + // send transaction to home bridge + await homeWeb3.eth.sendTransaction({ + from: user.address, + to: COMMON_HOME_BRIDGE_ADDRESS, + gasPrice: '1', + gas: '1000000', + value: homeWeb3.utils.toWei('0.01') + }) + + // check that balance increases + await uniformRetry(async retry => { + const balance = await erc20Token.methods.balanceOf(user.address).call() + if (toBN(balance).lte(toBN(originalBalance))) { + retry() + } + }) + + await promiseRetry(async (retry, number) => { + if (number < 6) { + retry() + } else { + const nonce = await homeWeb3.eth.getTransactionCount(validator.address) + assert( + nonce === initialNonce + 1, + 'Validator should not process transfer event originated during converting Chai => Dai' + ) + } + }) + }) + + after(async () => { + // Set 2 required signatures for home bridge + await setRequiredSignatures({ + bridgeContract: homeBridge, + web3: homeWeb3, + requiredSignatures: 2, + options: { + from: validator.address, + gas: '4000000' + } + }) + + // Set 2 required signatures for foreign bridge + await setRequiredSignatures({ + bridgeContract: foreignBridge, + web3: foreignWeb3, + requiredSignatures: 2, + options: { + from: validator.address, + gas: '4000000' + } + }) + }) + }) }) diff --git a/parity/chain-foreign.json b/parity/chain-foreign.json index 10473494..cb05533f 100644 --- a/parity/chain-foreign.json +++ b/parity/chain-foreign.json @@ -106,7 +106,7 @@ }, "7cc4b1851c35959d34e635a470f6b5c43ba3c9c9": { "balance": "0", - "code": "0x6080604052600436106100fb5763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166305d2035b811461010057806306fdde0314610129578063095ea7b3146101b357806318160ddd146101d757806323b872dd146101fe578063313ce5671461022857806340c10f191461025357806342966c6814610277578063661884631461029157806370a08231146102b5578063715018a6146102d65780637d64bcb4146102eb5780638da5cb5b1461030057806395d89b4114610331578063a9059cbb14610346578063d73dd6231461036a578063dd62ed3e1461038e578063f2fde38b146103b5575b600080fd5b34801561010c57600080fd5b506101156103d6565b604080519115158252519081900360200190f35b34801561013557600080fd5b5061013e6103f7565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610178578181015183820152602001610160565b50505050905090810190601f1680156101a55780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156101bf57600080fd5b50610115600160a060020a0360043516602435610485565b3480156101e357600080fd5b506101ec6104eb565b60408051918252519081900360200190f35b34801561020a57600080fd5b50610115600160a060020a03600435811690602435166044356104f1565b34801561023457600080fd5b5061023d610656565b6040805160ff9092168252519081900360200190f35b34801561025f57600080fd5b50610115600160a060020a036004351660243561065f565b34801561028357600080fd5b5061028f60043561076a565b005b34801561029d57600080fd5b50610115600160a060020a0360043516602435610777565b3480156102c157600080fd5b506101ec600160a060020a0360043516610866565b3480156102e257600080fd5b5061028f610881565b3480156102f757600080fd5b506101156108ef565b34801561030c57600080fd5b50610315610995565b60408051600160a060020a039092168252519081900360200190f35b34801561033d57600080fd5b5061013e6109a4565b34801561035257600080fd5b50610115600160a060020a03600435166024356109fe565b34801561037657600080fd5b50610115600160a060020a0360043516602435610acd565b34801561039a57600080fd5b506101ec600160a060020a0360043581169060243516610b66565b3480156103c157600080fd5b5061028f600160a060020a0360043516610b91565b60065474010000000000000000000000000000000000000000900460ff1681565b6000805460408051602060026001851615610100026000190190941693909304601f8101849004840282018401909252818152929183018282801561047d5780601f106104525761010080835404028352916020019161047d565b820191906000526020600020905b81548152906001019060200180831161046057829003601f168201915b505050505081565b336000818152600560209081526040808320600160a060020a038716808552908352818420869055815186815291519394909390927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925928290030190a350600192915050565b60045490565b600160a060020a03831660009081526003602052604081205482111561051657600080fd5b600160a060020a038416600090815260056020908152604080832033845290915290205482111561054657600080fd5b600160a060020a038316151561055b57600080fd5b600160a060020a038416600090815260036020526040902054610584908363ffffffff610bb116565b600160a060020a0380861660009081526003602052604080822093909355908516815220546105b9908363ffffffff610bc316565b600160a060020a0380851660009081526003602090815260408083209490945591871681526005825282812033825290915220546105fd908363ffffffff610bb116565b600160a060020a0380861660008181526005602090815260408083203384528252918290209490945580518681529051928716939192600080516020610d44833981519152929181900390910190a35060019392505050565b60025460ff1681565b600654600090600160a060020a0316331461067957600080fd5b60065474010000000000000000000000000000000000000000900460ff16156106a157600080fd5b6004546106b4908363ffffffff610bc316565b600455600160a060020a0383166000908152600360205260409020546106e0908363ffffffff610bc316565b600160a060020a038416600081815260036020908152604091829020939093558051858152905191927f0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea20544137d412139688592918290030190a2604080518381529051600160a060020a03851691600091600080516020610d448339815191529181900360200190a350600192915050565b6107743382610bd6565b50565b336000908152600560209081526040808320600160a060020a03861684529091528120548083106107cb57336000908152600560209081526040808320600160a060020a0388168452909152812055610800565b6107db818463ffffffff610bb116565b336000908152600560209081526040808320600160a060020a03891684529091529020555b336000818152600560209081526040808320600160a060020a0389168085529083529281902054815190815290519293927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060019392505050565b600160a060020a031660009081526003602052604090205490565b600654600160a060020a0316331461089857600080fd5b600654604051600160a060020a03909116907ff8df31144d9c2f0f6b59d69b8b98abd5459d07f2742c4df920b25aae33c6482090600090a26006805473ffffffffffffffffffffffffffffffffffffffff19169055565b600654600090600160a060020a0316331461090957600080fd5b60065474010000000000000000000000000000000000000000900460ff161561093157600080fd5b6006805474ff00000000000000000000000000000000000000001916740100000000000000000000000000000000000000001790556040517fae5184fba832cb2b1f702aca6117b8d265eaf03ad33eb133f19dde0f5920fa0890600090a150600190565b600654600160a060020a031681565b60018054604080516020600284861615610100026000190190941693909304601f8101849004840282018401909252818152929183018282801561047d5780601f106104525761010080835404028352916020019161047d565b33600090815260036020526040812054821115610a1a57600080fd5b600160a060020a0383161515610a2f57600080fd5b33600090815260036020526040902054610a4f908363ffffffff610bb116565b3360009081526003602052604080822092909255600160a060020a03851681522054610a81908363ffffffff610bc316565b600160a060020a038416600081815260036020908152604091829020939093558051858152905191923392600080516020610d448339815191529281900390910190a350600192915050565b336000908152600560209081526040808320600160a060020a0386168452909152812054610b01908363ffffffff610bc316565b336000818152600560209081526040808320600160a060020a0389168085529083529281902085905580519485525191937f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929081900390910190a350600192915050565b600160a060020a03918216600090815260056020908152604080832093909416825291909152205490565b600654600160a060020a03163314610ba857600080fd5b61077481610cc5565b600082821115610bbd57fe5b50900390565b81810182811015610bd057fe5b92915050565b600160a060020a038216600090815260036020526040902054811115610bfb57600080fd5b600160a060020a038216600090815260036020526040902054610c24908263ffffffff610bb116565b600160a060020a038316600090815260036020526040902055600454610c50908263ffffffff610bb116565b600455604080518281529051600160a060020a038416917fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca5919081900360200190a2604080518281529051600091600160a060020a03851691600080516020610d448339815191529181900360200190a35050565b600160a060020a0381161515610cda57600080fd5b600654604051600160a060020a038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a36006805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03929092169190911790555600ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa165627a7a72305820d0e5d0b7b0df4e2a06bb4d81bf6574bb34947120791873e3eccd4bf676f7b9f30029", + "code": "0x6080604052600436106100fb5763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166305d2035b811461010057806306fdde0314610129578063095ea7b3146101b357806318160ddd146101d757806323b872dd146101fe578063313ce5671461022857806340c10f191461025357806342966c6814610277578063661884631461029157806370a08231146102b5578063715018a6146102d65780637d64bcb4146102eb5780638da5cb5b1461030057806395d89b4114610331578063a9059cbb14610346578063d73dd6231461036a578063dd62ed3e1461038e578063f2fde38b146103b5575b600080fd5b34801561010c57600080fd5b506101156103d6565b604080519115158252519081900360200190f35b34801561013557600080fd5b5061013e6103f7565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610178578181015183820152602001610160565b50505050905090810190601f1680156101a55780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156101bf57600080fd5b50610115600160a060020a0360043516602435610485565b3480156101e357600080fd5b506101ec6104eb565b60408051918252519081900360200190f35b34801561020a57600080fd5b50610115600160a060020a03600435811690602435166044356104f1565b34801561023457600080fd5b5061023d610656565b6040805160ff9092168252519081900360200190f35b34801561025f57600080fd5b50610115600160a060020a036004351660243561065f565b34801561028357600080fd5b5061028f60043561078a565b005b34801561029d57600080fd5b50610115600160a060020a0360043516602435610797565b3480156102c157600080fd5b506101ec600160a060020a0360043516610886565b3480156102e257600080fd5b5061028f6108a1565b3480156102f757600080fd5b5061011561090f565b34801561030c57600080fd5b506103156109b5565b60408051600160a060020a039092168252519081900360200190f35b34801561033d57600080fd5b5061013e6109c4565b34801561035257600080fd5b50610115600160a060020a0360043516602435610a1e565b34801561037657600080fd5b50610115600160a060020a0360043516602435610aed565b34801561039a57600080fd5b506101ec600160a060020a0360043581169060243516610b86565b3480156103c157600080fd5b5061028f600160a060020a0360043516610bb1565b60065474010000000000000000000000000000000000000000900460ff1681565b6000805460408051602060026001851615610100026000190190941693909304601f8101849004840282018401909252818152929183018282801561047d5780601f106104525761010080835404028352916020019161047d565b820191906000526020600020905b81548152906001019060200180831161046057829003601f168201915b505050505081565b336000818152600560209081526040808320600160a060020a038716808552908352818420869055815186815291519394909390927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925928290030190a350600192915050565b60045490565b600160a060020a03831660009081526003602052604081205482111561051657600080fd5b600160a060020a038416600090815260056020908152604080832033845290915290205482111561054657600080fd5b600160a060020a038316151561055b57600080fd5b600160a060020a038416600090815260036020526040902054610584908363ffffffff610bd116565b600160a060020a0380861660009081526003602052604080822093909355908516815220546105b9908363ffffffff610be316565b600160a060020a0380851660009081526003602090815260408083209490945591871681526005825282812033825290915220546105fd908363ffffffff610bd116565b600160a060020a0380861660008181526005602090815260408083203384528252918290209490945580518681529051928716939192600080516020610d64833981519152929181900390910190a35060019392505050565b60025460ff1681565b600654600090600160a060020a031633148061068e57507306af07097c9eeb7fd685c692751d5c66db49c21533145b151561069957600080fd5b60065474010000000000000000000000000000000000000000900460ff16156106c157600080fd5b6004546106d4908363ffffffff610be316565b600455600160a060020a038316600090815260036020526040902054610700908363ffffffff610be316565b600160a060020a038416600081815260036020908152604091829020939093558051858152905191927f0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea20544137d412139688592918290030190a2604080518381529051600160a060020a03851691600091600080516020610d648339815191529181900360200190a350600192915050565b6107943382610bf6565b50565b336000908152600560209081526040808320600160a060020a03861684529091528120548083106107eb57336000908152600560209081526040808320600160a060020a0388168452909152812055610820565b6107fb818463ffffffff610bd116565b336000908152600560209081526040808320600160a060020a03891684529091529020555b336000818152600560209081526040808320600160a060020a0389168085529083529281902054815190815290519293927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060019392505050565b600160a060020a031660009081526003602052604090205490565b600654600160a060020a031633146108b857600080fd5b600654604051600160a060020a03909116907ff8df31144d9c2f0f6b59d69b8b98abd5459d07f2742c4df920b25aae33c6482090600090a26006805473ffffffffffffffffffffffffffffffffffffffff19169055565b600654600090600160a060020a0316331461092957600080fd5b60065474010000000000000000000000000000000000000000900460ff161561095157600080fd5b6006805474ff00000000000000000000000000000000000000001916740100000000000000000000000000000000000000001790556040517fae5184fba832cb2b1f702aca6117b8d265eaf03ad33eb133f19dde0f5920fa0890600090a150600190565b600654600160a060020a031681565b60018054604080516020600284861615610100026000190190941693909304601f8101849004840282018401909252818152929183018282801561047d5780601f106104525761010080835404028352916020019161047d565b33600090815260036020526040812054821115610a3a57600080fd5b600160a060020a0383161515610a4f57600080fd5b33600090815260036020526040902054610a6f908363ffffffff610bd116565b3360009081526003602052604080822092909255600160a060020a03851681522054610aa1908363ffffffff610be316565b600160a060020a038416600081815260036020908152604091829020939093558051858152905191923392600080516020610d648339815191529281900390910190a350600192915050565b336000908152600560209081526040808320600160a060020a0386168452909152812054610b21908363ffffffff610be316565b336000818152600560209081526040808320600160a060020a0389168085529083529281902085905580519485525191937f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929081900390910190a350600192915050565b600160a060020a03918216600090815260056020908152604080832093909416825291909152205490565b600654600160a060020a03163314610bc857600080fd5b61079481610ce5565b600082821115610bdd57fe5b50900390565b81810182811015610bf057fe5b92915050565b600160a060020a038216600090815260036020526040902054811115610c1b57600080fd5b600160a060020a038216600090815260036020526040902054610c44908263ffffffff610bd116565b600160a060020a038316600090815260036020526040902055600454610c70908263ffffffff610bd116565b600455604080518281529051600160a060020a038416917fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca5919081900360200190a2604080518281529051600091600160a060020a03851691600080516020610d648339815191529181900360200190a35050565b600160a060020a0381161515610cfa57600080fd5b600654604051600160a060020a038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a36006805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03929092169190911790555600ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa165627a7a723058202a7961c4a1262b1c97bda31945e4da4acd5a5180a88e8a2af25d1e7768b467610029", "storage": { "0x0": "0x6461690000000000000000000000000000000000000000000000000000000006", "0x1": "0x4441490000000000000000000000000000000000000000000000000000000006", @@ -139,11 +139,16 @@ }, "06af07097c9eeb7fd685c692751d5c66db49c215": { "balance": "0", - "code": "0x6080604052600436106100565763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416633b4da69f811461005b5780636c25b3461461008e578063be22f546146100ce575b600080fd5b34801561006757600080fd5b5061008c73ffffffffffffffffffffffffffffffffffffffff6004351660243561010c565b005b34801561009a57600080fd5b506100bc73ffffffffffffffffffffffffffffffffffffffff600435166101c5565b60408051918252519081900360200190f35b3480156100da57600080fd5b506100e36101cc565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b60008054604080517f23b872dd00000000000000000000000000000000000000000000000000000000815233600482015230602482015260448101859052905173ffffffffffffffffffffffffffffffffffffffff909216926323b872dd926064808401936020939083900390910190829087803b15801561018d57600080fd5b505af11580156101a1573d6000803e3d6000fd5b505050506040513d60208110156101b757600080fd5b505060018054909101905550565b5060015490565b60005473ffffffffffffffffffffffffffffffffffffffff16815600a165627a7a72305820d01d11b7ea4dad7896e3fbb5d06966bf715276ebd69a35990fa39c3158ca489d0029", + "code": "0x60806040526004361061008d5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416633b4da69f81146100925780634a03707c146100b85780634ba2363a146100dc5780636c25b3461461010d57806370a082311461010d578063a9059cbb14610140578063be22f54614610164578063ef693bed146100b8575b600080fd5b34801561009e57600080fd5b506100b6600160a060020a0360043516602435610179565b005b3480156100c457600080fd5b506100b6600160a060020a0360043516602435610225565b3480156100e857600080fd5b506100f16102db565b60408051600160a060020a039092168252519081900360200190f35b34801561011957600080fd5b5061012e600160a060020a03600435166102ea565b60408051918252519081900360200190f35b34801561014c57600080fd5b506100b6600160a060020a03600435166024356102f1565b34801561017057600080fd5b506100f161034d565b60008054604080517f23b872dd000000000000000000000000000000000000000000000000000000008152336004820152306024820152604481018590529051600160a060020a03909216926323b872dd926064808401936020939083900390910190829087803b1580156101ed57600080fd5b505af1158015610201573d6000803e3d6000fd5b505050506040513d602081101561021757600080fd5b505060018054909101905550565b60015481111561023457600080fd5b60018054829003905560008054604080517f40c10f19000000000000000000000000000000000000000000000000000000008152336004820152602481018590529051600160a060020a03909216926340c10f19926044808401936020939083900390910190829087803b1580156102ab57600080fd5b505af11580156102bf573d6000803e3d6000fd5b505050506040513d60208110156102d557600080fd5b50505050565b600254600160a060020a031681565b5060015490565b60015481111561030057600080fd5b600180548290039055604080518281529051600160a060020a0384169133917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a35050565b600054600160a060020a0316815600a165627a7a7230582011ff7c42c246a010e46c840aed33c06d1e2e77b750f54f5446eda005d2fa7b7f0029", "storage": { "0x0": "0x7cC4B1851c35959D34e635A470F6b5C43bA3C9c9", - "0x1": "0x38d7ea4c68000" + "0x1": "0x38d7ea4c68000", + "0x2": "0xEA190DBDC7adF265260ec4dA6e9675Fd4f5A78bb" } + }, + "ea190dbdc7adf265260ec4da6e9675fd4f5a78bb": { + "balance": "0", + "code": "0x608060405260043610605c5763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166320aba08b81146061578063487bf0821460615780639f678cca146085578063c92aecc4146061575b600080fd5b348015606c57600080fd5b5060736097565b60408051918252519081900360200190f35b348015609057600080fd5b50607360a7565b6b033b2e3c9fd0803ce800000081565b6b033b2e3c9fd0803ce8000000905600a165627a7a7230582035a724f9b8947f3a7ea91927b11f1bef35a051f81ff9ee6d5066a26b2e0b50a70029" } } }