-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add sparse Merkle tree advice set #269
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thank you! A few comments:
- Would be great to add doc comments about how the overall structure works. Doesn't need to be anything super extensive - but I think several sentences would help.
- For tests, would be good to test with trees which are not full. One approach could be to instantiate a regular Merkle tree with all zero nodes (e.g., of depth 8) and also have a blank Sparse Merkle tree. Then check their roots (they should be the same). Then add a leaf to a regular Merkle tree and the same leaf to the Sparse Merkle tree. Again, their roots should be the same, and the paths to this leaf returned from both should be the same. And perform a few other operations on both and make sure again the results we get are consistent. What do you think?
- Small nit: I'd prefer a slightly different way to organize the file. I've included a potential sketch below.
...
// SPARSE MERKLE TREE
// =============================
pub struct SparseMerkleTree {
...
}
impl SparseMerkleTree {
...
}
// STORE
// =============================
struct Store {
...
}
struct BranchNode {
...
}
impl Store {
...
}
I think tests for partially full trees are definitely needed. I'm not sure the approach you suggested would work without changing how the hashing of empty nodes work. Right now a default hash digest value is used for an empty node. To be equivalent with a regular Merkle tree, that digest value would need to depend on depth, and so we would need to have a lookup of the appropriate digest value for each depth. Unless the specific digest values are used elsewhere in Miden in the processing of these advice sets (for example, the expected root value of an empty tree is hardcoded in the constraints), it might not make sense to take this approach. Let me know what you think. |
Ah - I see! The approach when
In the second step, the hash co-processor computes For depth-specific hashes, we only need 63 values, right? How difficult would it be to change the structure use them? |
Right, but I don't think this depth-specific choice affects the path computation. The structure of the sparse Merkle path is the same as that of the regular Merkle tree, and the path leg verification in the hasher doesn't make any assumptions about the exact value of the sibling node hash. I might be missing something here.
Yes, it wouldn't be difficult to change this. |
Yes, but if we ever need to compute |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thank you! Could you fix the clippy errors? I'll merge after that.
This PR adds an SMT of variable depth (up to 63) and with no key compaction as an advice set. It follows the same interface as the balanced Merkle tree.