3

I know it is possible to verify historical ETH balances (for the last 256 blocks) using a merkle proof on-chain - are there any known implementations?

NB - I'm looking for Solidity code (i.e. on-chain) ways of doing this.

1

You probably need to build you own code on the top of these two libraries: https://github.com/hamdiallam/Solidity-RLP and https://github.com/commitground/solidity-patricia-tree

The former library allows decoding RLP encoded data structure. The second allows checking that certain data is stored in Merkle-Patricia tree.

Ethereum stores state of all addresses in Merkle-Patricia tree. Path to the leaf is an address, and leaf data is RLP encoding of four values nonce, balance, storageRoot, and codeHash.

Root hash of the tree is stored in block header among other things.

So here is what you need to do in your smart contract:

  1. Calculate hash of provided block header
  2. Check that this hash equals to the block hash of block provided block number
  3. Extract Merkle-Patricia root hash from block header
  4. Check that provided address state is actually in Merkle-Patricis tree at provided address
  5. Extract balance from address state
0

For anyone coming to this, I found the below - it is unproven though and has some limitations:

https://github.com/figs999/Ethereum/blob/master/EventStorage.sol

  • This code does not allow to do what you need. It seems to check for logged events rather than balances, and does so relying on bloom filter only which ma return false positives. So when this code says you that some data was logged that may or may not be the case, while is the code says that the data was not logged, then this is definitely so. – Mikhail Vladimirov Oct 9 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.