cosmology-tech / telescope

A TypeScript Transpiler for Cosmos Protobufs ⚛️
https://cosmology.zone/products/telescope
Apache License 2.0
140 stars 39 forks source link

telescope: ethermint support #431

Open pysel opened 11 months ago

pysel commented 11 months ago

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

hoangdv2429 commented 11 months ago

Can I work on this ?

pysel commented 11 months ago

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!

hoangdv2429 commented 11 months ago

Got ya 🔥

hoangdv2429 commented 9 months ago

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

hoangdv2429 commented 9 months ago

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 commented 8 months ago

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

pyramation commented 1 month ago

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