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

Implemented nullifier tree wrapper over Smt #275

Merged
merged 3 commits into from
Mar 14, 2024
Merged

Conversation

polydez
Copy link
Contributor

@polydez polydez commented Mar 12, 2024

Resolves: #269

@polydez polydez requested a review from bobbinth March 12, 2024 15:08
@polydez polydez self-assigned this Mar 12, 2024
@polydez polydez linked an issue Mar 12, 2024 that may be closed by this pull request
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! I left a few small comments inline.

store/src/errors.rs Outdated Show resolved Hide resolved
store/src/server/api.rs Outdated Show resolved Hide resolved
store/src/state.rs Outdated Show resolved Hide resolved
store/src/state.rs Outdated Show resolved Hide resolved
@polydez polydez requested a review from bobbinth March 13, 2024 06:34
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!

I've also tagged @hackaugusto to do another review.

@bobbinth bobbinth requested a review from hackaugusto March 13, 2024 23:18
Copy link
Contributor

@hackaugusto hackaugusto left a comment

Choose a reason for hiding this comment

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

LGTM, I left one nit about the insert API that would be nice to iron out though.

Comment on lines 54 to 57
Err(NullifierTreeError::NullifierAlreadyExists {
nullifier: *nullifier,
block_num: Self::leaf_value_to_block_num(value),
})
Copy link
Contributor

Choose a reason for hiding this comment

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

This error is misleading. It seems to imply the insert failed, because the nullifier already exists. But the existing nullifier is being replaced, since insert behaves like an insert_or_replace.

What was the intention here? To me, it seems that if we want the same behaviour, we should not have this error. OR, if we want to Err, then we have to do a check before the insert.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh! Great catch! Yes, definitely we should do a check and only then do the insert. Basically, if the error is returned, the state of the nullifier tree should not change.

Comment on lines 66 to 69
let value = self.0.get_value(&nullifier.inner());
if value == EMPTY_WORD {
return None;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels like a design flaw in SparseMerkleTree. We are required to encode the lack of a value as an EMPTY_WORD, but that implementation detail is leaking, and now on higher level abstractions we are having to special case it.

0xPolygonMiden/crypto#289

Copy link
Contributor

Choose a reason for hiding this comment

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

Building on 0xPolygonMiden/crypto#289 (comment), the correct check here would be if value == Smt::EMPTY_VALUE, since Smt::EMPTY_VALUE is part of the public API, but the fact that Smt::EMPTY_VALUE == EMPTY_WORD is an implementation detail.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, let's change this to if value == Smt::EMPTY_VALUE.

@polydez polydez requested review from bobbinth and hackaugusto March 14, 2024 17:03
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!

@polydez polydez merged commit 95d3fff into next Mar 14, 2024
5 checks passed
@polydez polydez deleted the polydez-nullifier-tree branch March 14, 2024 17:47
bobbinth pushed a commit that referenced this pull request Apr 12, 2024
* feat: implement nullifier tree wrapper over `Smt`

* refactor: move `NullifierTree` to separated file, renames ans small fixes

* fix: address review comments
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.

[Task]: Create nullifier tree wrapper over Smt
4 participants