ethereumjs-monorepo
ethereumjs-monorepo copied to clipboard
Trie: Add support for partial trees
I'd love to do some local VM state caching, and so this would require a way of storing a trusted root, and only adding things that match the root.
Maybe a set of methods like trie.setTrustedRoot(rootHash), and trie.putDataSafely('key', 'value', merkleProof) which will throw if you try to put data that doesn't match the current trusted root.
I have no idea what precise format merkleProof would be. I'd love if it was a schema format supplied by an RPC method, but looks like the current RPC may lack the methods for that. Maybe ipld-ethereum has some methods we could use? @kumavis?
So this will enable creating a partial tree from a proof here. And/or you can make a new tree and set the root, then add more poofs to it later by calling this function with your trie (optional proofTrie argument).
the function doesn't check that the proof is valid. The way you can do that is to call get on the key you want out of the tree. If the proof is valid it will come out, if not, you will get a "missing node" error.
Unsure if we want to close here or not, will keep this open for now and transfer to the monorepo.
Although there is no direct interface, partial trees are supported, you only need to write directly to DB. Example here.
Not sure if we want to add an interface here?
I'm pretty sure this is addressed in Trie's fromProof method. What you do here is first you set the root of whatever root the merkle proof should be, and then dump in the merkle proof into the fromProof. The key/value pairs are not necessary here.
Will close here.