loomchain
loomchain copied to clipboard
Add EVM builtin function to get ed25519 address mapped to secp256k1 address
We should provide access to account mappings within Solidity contracts so devs can verify signed messages. Currently the address returned by ecrecover in a Solidity contract can't be matched to any DAppChain account (nor msg.sender).
It would look something like this:
// get the address matching the secp256k1 private key that signed the message
address signer = ecrecover(_message, _v, _r, _s);
// get the DAppChain address of the signer
address account = loom_native_api.mappedAccount('eth', signer);
This would need to be implemented as a precompiled EVM contract, we've got an example of doing so in https://github.com/loomnetwork/loomchain/blob/1521b61bc8b4af38a0d9ebc552886f858f006bb3/evm/evm_test.go#L71 and of course ecrecover and friends https://github.com/ethereum/go-ethereum/blob/master/core/vm/contracts.go
Going the other way (DAppChain address -> Eth address) would also be useful:
// lookup the mapping of the DAppChain address of msg.sender to an Eth address
address ethAccount = loom_native_api.mappedAccount('loom', msg.sender, 'eth')
address signer = ecrecover(_message, _v, _r, _s);
// can now compare ethAccount to signer to verify msg.sender signed the message
Implemented in https://github.com/loomnetwork/loomchain/pull/1526