Eth ABI compatibility: support RLP encoded input and output
In order to support compatibility of ink! contracts with Ethereum tooling (tracking issue), ink! will need to be able to:
- Detect whether the contract is being invoked with Eth compatibility, and input should be decoded from RLP and outputs should be decoded into RLP
- Types used as input arguments and outputs (return types from messages) would need to derive RLP encoding using e.g. https://docs.rs/rlp-derive/latest/rlp_derive/
Things to figure out:
- How to handle Sum types (Rust
enums)- Just use raw bytes and let the user deal with them?
- How to handle any built-in ethereum types e.g.
U256that are not rust priimitives. - How to handle mapping of
AccountIdtype which is different (is this handled bypallet-contracts - Contract size: RLP decoding routines could blow up contract sizes
- For
2.can we disable eth compat/RLP decoding via a feature flag to reduce contract size?
- For
- For
1., how to do we determine whether we are dealing with RLP encoded call or regular SCALE encoded call?pallet-contractscould prepend the input with a flag, or we could querypallet-contractsfor that?
Origin: point 3 in this slide from @agryaznov

At UniqueNetwork, we have developed and used evm-coder: https://forum.polkadot.network/t/introducing-evm-coder-a-library-for-seamless-call-translation-between-rust-and-solidity/2551
This crate provides evm abi compatibility with syntax, which is close to ink! macroses and solidity interface generation (With scale-info-like type introspection, but a little dumber).
We have been using this crate for a long time in production now for representing our collections (i.e. NFT tokens) as Ethereum precompiles, yet it is also usable in contracts (It is ink!-compatible)
Some code to look at: Our NFT contract definition: https://github.com/UniqueNetwork/unique-chain/blob/bfab6035a1231419fcb490c7fa549e252dcd0cd1/pallets/nonfungible/src/erc.rs
And the generated interfaces for it: https://github.com/UniqueNetwork/unique-chain/blob/bfab6035a1231419fcb490c7fa549e252dcd0cd1/js-packages/tests/eth/api/UniqueNFT.sol
Do you need any help with this?