ethereum / go-verkle

A go implementation of Verkle trees
The Unlicense
209 stars 63 forks source link

tree: add new method GetAndLoadForProof #383

Open jsign opened 1 year ago

jsign commented 1 year ago

This PR adds a new helper method that will assist clients in preloading the tree for proof generation.

See https://github.com/gballet/go-ethereum/pull/255

jsign commented 11 months ago

Left some comments. I am not sure I understand why you don't simply use Get?

When you call Get, it will resolve all internal nodes directly in the path to the corresponding leaf. As in, the minimal node loading needed to reach the desired leaf (as expected).

This method does something extra needed for proof generation. When we want to generate a proof for a leaf value, we also need all the internal node children in that path. That's because we need all the evaluations of the vector in that internal node to prove the opening in internal nodes. This part of the PR code is exactly doing this (also note some code comment a few lines above).

Doing all this at the Geth layer is very complicated and confusing. This API is providing a way of asking: "Load the tree for this key, and also all the auxiliary stuff that I'll need to generate a proof without any further resolving" (as you'd have with using Get).

That means that Geth can call this method for every key in the witness. After finishing with these simple calls it will know the loaded tree is fully ready to generate a proof (without a resolver or anything extra for proof generation).

That's exactly the idea of the referenced Geth PR in the PR description. While the EVM is collecting accessed keys in the witness, we use this API to load in the background the needed tree with all the resolved stuff. When the EVM finishes, the Witness already has loaded all that it needs so Geth can use this tree to generate the proof.

gballet commented 11 months ago

ah right of course. LGTM.