ink icon indicating copy to clipboard operation
ink copied to clipboard

Eth ABI compatibility: support RLP encoded input and output

Open ascjones opened this issue 2 years ago • 1 comments

In order to support compatibility of ink! contracts with Ethereum tooling (tracking issue), ink! will need to be able to:

  1. Detect whether the contract is being invoked with Eth compatibility, and input should be decoded from RLP and outputs should be decoded into RLP
  2. 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. U256 that are not rust priimitives.
  • How to handle mapping of AccountId type which is different (is this handled by pallet-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 1., how to do we determine whether we are dealing with RLP encoded call or regular SCALE encoded call?
    • pallet-contracts could prepend the input with a flag, or we could query pallet-contracts for that?

Origin: point 3 in this slide from @agryaznov

image

ascjones avatar Apr 13 '23 11:04 ascjones

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?

CertainLach avatar Nov 28 '23 15:11 CertainLach