I would like to propose to add an opcode that allows accessing the storage trie root hash for an account. This would allow to perform storage verification and gas optimizations.
Verification
Currently it is impossible to verify that nothing has changed inside the storage tree of a specific account. There are some cases where this is very interesting to know. E.g. assuming you have a smart contract wallet and you want to ensure that nothing is changed in the storage tree during an execution of a internal transaction. Currently this would be quite expensive or impossible (as you would have to know all storage slots and compare them before and after). By comparing the storage tree root hash this could be simplified.
Gas optimizations
A big chunk of gas costs are related to storage read. By adding read access to the storage trie root hash it is possible to write contracts in a “hybrid” stateless manner. E.g. provide the state to the user still via view functions, but for function that do on chain computations the state could be provided via the calldata and verified against the root hash. This could be done even for other accounts than the own, potentially allowing contracts to “access” state of other accounts.
Considerations
- The gas costs should probably be similar to EXTCODEHASH
- If contracts perform verification on the root hash, they might break if a different hashing algorithm (instead of a merkle trie) is used.
- Should this be an opcode or rather a precompile.
Would love to hear some opinions on this opcode