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

feat: refactor Merkle proof for ergonomics #692

Merged
merged 7 commits into from
Oct 24, 2024
Merged

feat: refactor Merkle proof for ergonomics #692

merged 7 commits into from
Oct 24, 2024

Conversation

mrain
Copy link
Contributor

@mrain mrain commented Oct 15, 2024

closes: #642, #658

This PR:

  • Remove leaf information (index, element) from the MerkleProof struct.
  • Change the verifications APIs to take a Merkle commitment instead of a simple root digest.

This PR does not:

Key places to review:


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (main)
  • Linked to GitHub issue with discussion and accepted design OR have an explanation in the PR that describes this work.
  • Wrote unit tests
  • Updated relevant documentation in the code
  • Added relevant changelog entries to the CHANGELOG.md of touched crates.
  • Re-reviewed Files changed in the GitHub PR explorer

@mrain mrain marked this pull request as ready for review October 21, 2024 18:10
@mrain mrain requested a review from alxiong as a code owner October 21, 2024 18:10
@mrain mrain requested a review from ggutoski October 21, 2024 18:10
@ggutoski
Copy link
Contributor

Change the verifications APIs to take a Merkle commitment instead of a simple root digest.

Why is this needed?

@mrain
Copy link
Contributor Author

mrain commented Oct 21, 2024

Why is this needed?

I think it looks nicer.

And make sure that users won't miss this check: https://github.com/EspressoSystems/zkrollup-integration/blob/89e86d0ea3f6ea25b92e310d131d177512b0ff80/sp1/program/src/main.rs#L82

Copy link
Contributor

@ggutoski ggutoski left a comment

Choose a reason for hiding this comment

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

Thanks @mrain .

  • I did not spot any issues but it's hard to follow the code from the diff.
  • Anything specific to review with greater care? Seems like most changes are boilerplate: renaming variables, accommodating the removal of (index, element) from merkle proof, etc.
  • @alxiong should review the gadget stuff. I'm unfamiliar with our gadget code.

@ggutoski
Copy link
Contributor

And make sure that users won't miss this check: https://github.com/EspressoSystems/zkrollup-integration/blob/89e86d0ea3f6ea25b92e310d131d177512b0ff80/sp1/program/src/main.rs#L82

Sorry but I don't understand this comment.

@mrain
Copy link
Contributor Author

mrain commented Oct 21, 2024

Sorry but I don't understand this comment.

This is an additional check that the height information is correct. With previous API users may forget. to do so.
But I'm not quite sure whether it is necessary now. cc @alxiong

Anything specific to review with greater care? Seems like most changes are boilerplate: renaming variables, accommodating the removal of (index, element) from merkle proof, etc.

True. Most of them are boilerplate. Changes in forget_internal() and remember_internal() may require additional care. But they are all covered by unit tests. And this is also kind of internal audit.

@alxiong
Copy link
Contributor

alxiong commented Oct 22, 2024

Sorry but I don't understand this comment.

This is an additional check that the height information is correct. With previous API users may forget. to do so.
But I'm not quite sure whether it is necessary now. cc @alxiong

This is to ensure correct tree height is being used to prevent extension attack (i.e. find a root collision via much larger tree)

meanwhile, I agree it's unclear from API design that why we need this check outside, instead of being part of BlockMerkleTree::verify() 🤔

@mrain
Copy link
Contributor Author

mrain commented Oct 22, 2024

meanwhile, I agree it's unclear from API design that why we need this check outside, instead of being part of BlockMerkleTree::verify() 🤔

Therefore it's checked inside verify() now.
My point is, as we are supplying the leaf information to verify(), is the height check still necessary to prevent the extension attack?

merkle_tree/src/internal.rs Outdated Show resolved Hide resolved
merkle_tree/src/internal.rs Outdated Show resolved Hide resolved
merkle_tree/src/internal.rs Show resolved Hide resolved
merkle_tree/src/internal.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@alxiong alxiong left a comment

Choose a reason for hiding this comment

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

I agree with the trait changes.

  • Why are we completely removing namespaced_merkle_tree?

merkle_tree/src/light_weight.rs Outdated Show resolved Hide resolved
merkle_tree/src/internal.rs Show resolved Hide resolved
merkle_tree/src/internal.rs Outdated Show resolved Hide resolved
@mrain
Copy link
Contributor Author

mrain commented Oct 23, 2024

  • Why are we completely removing namespaced_merkle_tree?

Because it's no longer in use and takes too much efforts to refactor.

@alxiong
Copy link
Contributor

alxiong commented Oct 24, 2024

Why are we completely removing namespaced_merkle_tree?

Because it's no longer in use and takes too much efforts to refactor.

wait, so we are not going to use them? are we sticking to using a normal MT with a Namespace table to delineate the boundary of different namespaces?
I thought might be useful to keep a NMT, if the effort is high, we can do it in a separate PR?

@mrain
Copy link
Contributor Author

mrain commented Oct 24, 2024

wait, so we are not going to use them? are we sticking to using a normal MT with a Namespace table to delineate the boundary of different namespaces? I thought might be useful to keep a NMT, if the effort is high, we can do it in a separate PR?

No we are not. The namespace table now is just a plain vector with offsets @ggutoski

I think it's better to bring back NMT on request.

@ggutoski
Copy link
Contributor

wait, so we are not going to use them? are we sticking to using a normal MT with a Namespace table to delineate the boundary of different namespaces? I thought might be useful to keep a NMT, if the effort is high, we can do it in a separate PR?

No we are not. The namespace table now is just a plain vector with offsets @ggutoski

I think it's better to bring back NMT on request.

I was not even aware we have a NMT implementation. 😳 We don't need one IMO. We can revive it later if we find that we do need NMT.

@mrain
Copy link
Contributor Author

mrain commented Oct 24, 2024

Also do you think we should merge #685 together?
cc @alxiong @ggutoski

@alxiong
Copy link
Contributor

alxiong commented Oct 24, 2024

Also do you think we should merge #685 together?

we should keep them as two PRs, but yeah, we can rebase that PR after this is merge and then got that one in as well.

Copy link
Contributor

@alxiong alxiong left a comment

Choose a reason for hiding this comment

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

In principle approval, LGTM. I'll let Gus have the final call.

@mrain mrain merged commit 582d1dd into main Oct 24, 2024
5 checks passed
@mrain mrain deleted the cl/merkle-tree branch October 24, 2024 14:56
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.

Ergonomics of jf-merkle-tree
3 participants