Skip to content
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

Implement SimpleSmt::set_subtree #232

Merged
merged 7 commits into from
Dec 5, 2023
Merged

Implement SimpleSmt::set_subtree #232

merged 7 commits into from
Dec 5, 2023

Conversation

plafer
Copy link
Contributor

@plafer plafer commented Dec 4, 2023

Closes #220

Note that set_subtree() returns Result<(), MerkleError> instead of Result<Word, MerkleError>, because I didn't know which value to return. The hash of the internal node where the subtree root was inserted? Is this relevant information?

I would also suggest we change the interface to

pub fn set_subtree(&mut self, index: NodeIndex, subtree: SimpleSmt) -> Result<(), MerkleError>

This would result in caller code that's easier to read (since the depth of the insertion is determined at the call site). I believe callers should always know the depth at which they want to insert, such as in miden-node where we want to insert a subtree of depth 13 at depth 8.

@plafer plafer requested a review from bobbinth December 4, 2023 22:02
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you!

Note that set_subtree() returns Result<(), MerkleError> instead of Result<(), MerkleError>, because I didn't know which value to return.

I was thinking we'd return the new root.

I would also suggest we change the interface to

pub fn set_subtree(&mut self, index: NodeIndex, subtree: SimpleSmt) -> Result<(), MerkleError>

This would result in caller code that's easier to read (since the depth of the insertion is determined at the call site). I believe callers should always know the depth at which they want to insert, such as in miden-node where we want to insert a subtree of depth 13 at depth 8.

I don't mind this change, but I do think that having to construct NodeIndex might complicate the interface a bit. But not a strong opinion by any means.

Copy link

sonarqubecloud bot commented Dec 5, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@plafer
Copy link
Contributor Author

plafer commented Dec 5, 2023

I was thinking we'd return the new root.

Changed it return the root (as an RpoDigest since this is how we represent the root elsewhere).

@plafer plafer merged commit 9b4430f into next Dec 5, 2023
11 checks passed
@plafer plafer deleted the plafer-smt-set-subtree branch December 5, 2023 14:25
bobbinth pushed a commit that referenced this pull request Dec 21, 2023
* recompute_nodes_from_indeX_to_root

* MerkleError variant

* set_subtree

* test_simplesmt_set_subtree

* test_simplesmt_set_subtree_entire_tree

* test

* set_subtree: return root
bobbinth pushed a commit that referenced this pull request Feb 14, 2024
* recompute_nodes_from_indeX_to_root

* MerkleError variant

* set_subtree

* test_simplesmt_set_subtree

* test_simplesmt_set_subtree_entire_tree

* test

* set_subtree: return root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants