loomchain
loomchain copied to clipboard
Update Address Mapper contract for multi-chain use
The Address Mapper contract was initially written to support mapping an Ethereum account to a DAppChain account, the code assumes the mapping is always between those two chains. Now that we're adding support for TRON & EOS accounts we either have to deploy multiple instances of the Address Mapper - one for each chain, or the contract needs to be extended to properly deal with all these chains.
There are a couple of issues with the current implementation:
- Mapping a single DAppChain account to multiple chains isn't possible, only the first mapping will be allowed.
- Signature verification doesn't take into account the chain IDs, need to investigate if that can be exploited somehow in a replay attack.
Also related https://github.com/loomnetwork/loomchain/issues/229
Requirements for the improved Address Mapper:
- DAppChain account can be mapped to multiple foreign accounts on the same foreign chain.
- DAppChain account can be mapped to foreign accounts on multiple foreign chains.
- Account mappings can be removed provided they aren't used anymore, though perhaps we should only allow this when more than one mapping exists, to minimize the chances of a user losing access to their tokens on the DAppChain.
The hash that's signed to prove account ownership will need to include the chain IDs of the accounts, as well as a nonce to prevent replays.
Need to check what the side effects of removing an account mapping would be, deposits to the Ethereum Gateway will end up as unclaimed tokens in the DAppChain Gateway, the depositor can then reclaim them using another account mapping (or we can do this automatically every so often), so deposits should be fine. Can withdrawals get stuck? Do we have to ensure there are no in-progress withdrawals before removing an account mapping?
First step is to handle the multi chain mapping better, the removal of mappings can be implemented later once we've considered the implications of doing so.
The hash that's signed to prove account ownership will need to include the chain IDs of the accounts, as well as a nonce to prevent replays.
Can you describe more about the nonce?
Is it the same as nonce on dappchain that can be aqquired from /rpc/nonce?
No, this is a separate nonce that needs to be tracked for each DAppChain address we create a mapping for. For example if you map a local (DAppChain) account A to an Ethereum account B the nonce will be zero for that first mapping, then if you map local account A to a Binance account C the nonce will be one for that mapping. So each time a mapping is created for a local account we need to increment the nonce by one.
As far as I know, We have two different ways to upgrade the address mapper contract to support multi-chain mapping.
Current :
prefixKey : byteAddress -> address mapping protobuf (from,to)
-
Store new type of protobuf as list of address, Map as one to many. key --> List of address
prefixKey : byteAddress --> list of address mapping protobuf [(from to)].DAPP --> [ eth:.. binance:.. binance:.. tron:...] eth --> [ DAPP] binance --> [ DAPP ] binance --> [ DAPP ] tron --> [ DAPP ] -
Use more complex keys . No need to change protobuf, Map as one to one. key:chainid:sequence -> address
prefixKey : byteAddress : TargetchainID : sequence --> address mapping protobuf (from,to)DAPP:eth:1 -> eth: … DAPP:binance:1 -> binance: … DAPP:binance:2 -> binance: … DAPP:tron:1 -> tron: …. eth:DAPP:1 -> dapp: .... binance:DAPP:1 -> dapp: ... binance:DAPP:1 -> dapp: ... tron:DAPP:1 -> dapp: ... This way I think it's will be easier to do.
Need someone suggestion.