telescope icon indicating copy to clipboard operation
telescope copied to clipboard

telescope: ethermint support

Open pysel opened this issue 1 year ago • 7 comments

This will be a tracking issue on the progress of developing support for transpiling evmos messages.

Context on EVM messages (Thanks to @hanchon for context)

The general idea to convert the cosmos messages to EVM is to get the transaction in Animo format: https://github.com/evmos/evmos/blob/32e76bd281553e0225d6ff4454db323189847812/ethereum/eip712/encoding.go#L124 (If you already have the transaction in amino format, you can ignore the first step)

Then you use the signdoc bytes to generate the EVM payload, in the evmos code they verify the message before encoding it: https://github.com/evmos/evmos/blob/32e76bd281553e0225d6ff4454db323189847812/ethereum/eip712/encoding.go#L76

The last step is to wrap the transaction in a EIP712 object: https://github.com/evmos/evmos/blob/32e76bd281553e0225d6ff4454db323189847812/ethereum/eip712/eip712.go#L11

One of the Evmos developers made a helper in EvmosJS, but it only supports 3 messages and the types structure is not automatically generated: https://github.com/evmos/evmosjs/blob/main/packages/eip712/src/encoding/decodeAmino.ts#L61

The function that they call to generate the types is: https://github.com/evmos/evmosjs/blob/main/packages/eip712/src/messages/base.ts#L52 (That one has the types required by the EIP712 format, but is missing the specifics for each message, for example: MsgSend uses:

{
  MsgValue: [
    { name: 'from_address', type: 'string' },
    { name: 'to_address', type: 'string' },
    { name: 'amount', type: 'TypeAmount[]' },
  ],
  TypeAmount: [
    { name: 'denom', type: 'string' },
    { name: 'amount', type: 'string' },
  ],
}

)

IMPORTANT: the values must be in the correct order, because the array is hashed to generate the payload that needs to be signed!

The complex part is to get the EIP712 types right automatically.

Then the actual transactions values (that are also included in the EIP712 transaction), are just the json amino encoded values: https://github.com/evmos/evmosjs/blob/main/packages/eip712/src/messages/bank/send.ts#L12

pysel avatar Aug 08 '23 11:08 pysel

Can I work on this ?

hoangdv2429 avatar Aug 08 '23 13:08 hoangdv2429

hey @hoangdv2429! I was planning to work on this myself, but there have been some circumstances, so I won't be able to pick it up any time soon, so if you are down, feel free, please!

pysel avatar Aug 08 '23 20:08 pysel

Got ya 🔥

hoangdv2429 avatar Aug 08 '23 20:08 hoangdv2429

https://github.com/hoangdv2429/Cosmos-grcp-playground/tree/feat/evmos_ibc_transfer this one is working using keplr signing style.

hoangdv2429 avatar Sep 16 '23 17:09 hoangdv2429

this create signDoc, if we intend to sign it metamask EIP712 style then

  1. wrap signDoc to EIP712 obj
  2. signEIP712 instead of signDirect

note: as for getting types, we should have typeUrl/ type@ together with the message. This is also for getting the json fields order right.

hoangdv2429 avatar Sep 16 '23 17:09 hoangdv2429

https://github.com/cosmos/cosmjs/pull/1107/files this PR have code that handle ethAccount type as a reference.

hoangdv2429 avatar Oct 14 '23 18:10 hoangdv2429

multiple messages https://github.com/evmos/evmosjs/blob/e47e44b1683ffa57737cee2f6abbd138436d9fc3/packages/proto/src/transaction/transaction.ts#L192

pyramation avatar Jun 03 '24 21:06 pyramation