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.
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.
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:
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
Just in case someone needs this, here's the onchain implementation of account and storage proof verification: https://github.com/lidofinance/curve-merkle-oracle/blob/main/contracts/StateProofVerifier.sol.
And if you need to verify transaction inclusion, here's another repo (which the repo linked above is actually based upon): https://github.com/lorenzb/proveth/blob/master/onchain/ProvethVerifier.sol.