The ethstate
module provides an interface to store and verify the state data of an Ethereum contract slot within the Cosmos chain. By collaborating with the ethquery
module, it fetches the Ethereum data, verifies its authenticity, and makes it available for querying within the Cosmos chain.
Users can initiate the retrieval process by executing the get-slot-data-from-eth
command.
cosmicetherd tx ethstate get-slot-data-from-eth CONTRACT_ADDRESS SLOT_NUMBER BLOCK_HEIGHT
cosmicetherd tx ethstate get-slot-data-from-eth 0x314159265dD8dbb310642f98f50C066173C1259b 0x02 18077318
By running the command, users specify:
- CONTRACT_ADDRESS: Ethereum contract address of interest.
- SLOT_NUMBER: Slot of interest within the contract.
- BLOCK_HEIGHT: Height of the Ethereum block to consider.
On execution:
- A user submits this command which results in a Cosmos transaction.
- This action creates two records in the
ethquery
module: one for fetching the storage data (getStorage
) and another for fetching the block by its number (getBlockByNumber
).
- The
cosmic-relayer
identifies the unservicedethquery
requests. - It then retrieves the respective data from Ethereum using RPC calls in batches.
- The fetched data, while unverified, is submitted back to the Cosmos chain by the relayer.
- Upon the receipt of the Ethereum data, designated callbacks (
GetStorageCallback
andGetBlockCallback
) are invoked, storing the data appropriately. - Periodically, the stored data undergoes verification checks using the Merkle Patricia Trie (MPT) and associated proofs.
Users can retrieve the stored and verified data with the following commands:
- Slot Data Query:
cosmicetherd q ethstate slot-data CONTRACT_ADDRESS SLOT_NUMBER
- Contract Data Query:
cosmicetherd q ethstate contract-data CONTRACT_ADDRESS
- Block Header Query:
cosmicetherd q ethstate eth-block BLOCK_NUMBER
The verification of Ethereum data involves several functions:
- VerifyAccountProof: Confirms the authenticity of an Ethereum account's state by matching the provided state against the root hash using the MPT.
- VerifyProof: Verifies whether the given value, at the provided key, matches the state in the root hash using the MPT.
- VerifyEthStorageProof: Uses
VerifyProof
to confirm the legitimacy of the provided storage data against its hash. - VerifyEIP1186: Validates storage proofs in compliance with the EIP-1186 standard.
- VerifyEthAccountProof: Confirms both the storage and account state by comparing them against the provided proofs and root hash.
- VerifyMPTForSlotData: Comprehensive function that verifies the data for a particular slot using the MPT, ensuring both storage and account data are legitimate.
These verification functions leverage Ethereum's Merkle Patricia Trie to ensure the correctness of the data. They use cryptographic proofs, hashes, and the MPT structure to validate that a particular piece of data, given its hash and accompanying proof, genuinely belongs to a particular state or block.