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

fix(merkle-tree): make sibling path generic over its length #647

Merged
merged 6 commits into from
May 23, 2023

Conversation

Maddiaa0
Copy link
Member

@Maddiaa0 Maddiaa0 commented May 22, 2023

Description

Try to prevent: #639
More broadly part of: #645

Issues occurred when migrating the Nullifier Tree to a new location when the subtree and full tree heights were mixed up, leading to hard to decipher circuit messages.
This pr aims to prevent this issue by strongly typing the nullifier tree batch insertion method.

  1. Just as @ludamad did to the MembershipWitness file in his msgpack work, SiblingPaths are now generic over their height and this height is checked.
  2. When a subtree is created for the sibling paths, it is now generic over the difference between the tree height and the subtree height. This way the type checker should prevent somebody from returning a tree of the wrong size.
  3. Lots of naked sibling path conversions from Buffer[] -> Fr[] (path.data.map(f => Fr.fromBuffer(f)) yuck) have been replaced with SiblingPath.toFieldArray()

Checklist:

  • I have reviewed my diff in github, line by line.
  • Every change is related to the PR description.
  • I have linked this pull request to the issue(s) that it resolves.
  • There are no unexpected formatting changes, superfluous debug logs, or commented-out code.
  • The branch has been merged or rebased against the head of its merge target.
  • I'm happy for the PR to be merged at the reviewer's next convenience.

@Maddiaa0 Maddiaa0 requested a review from ludamad May 22, 2023 17:29
@Maddiaa0 Maddiaa0 marked this pull request as ready for review May 22, 2023 17:31
Copy link
Contributor

@LHerskind LHerskind left a comment

Choose a reason for hiding this comment

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

Tiny nits. Looks good to me.
🧚


// ensure the committed state is correct
const initialSiblingPath = new SiblingPath([initialLeafHash, level1ZeroHash, level2ZeroHash]);
const initialSiblingPath = new SiblingPath(3, [initialLeafHash, level1ZeroHash, level2ZeroHash]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const initialSiblingPath = new SiblingPath(3, [initialLeafHash, level1ZeroHash, level2ZeroHash]);
const initialSiblingPath = new SiblingPath(TEST_TREE_DEPTH, [initialLeafHash, level1ZeroHash, level2ZeroHash]);

height,
),
);
return new MembershipWitness(height, index, assertLength(path.toFieldArray(), height));
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you know about this todo? Not fully clear to me what conversion it is related to.

Copy link
Member Author

Choose a reason for hiding this comment

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

I dont think it applies anymore? The only number type here is the generic that will never be that big? @spalladino do you know if this is resolved?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep, it seems it doesn't apply anymore. IIRC there was an explicit Number(bigintVariable) here, but seems like it's gone (or moved elsewhere).

@Maddiaa0 Maddiaa0 enabled auto-merge (squash) May 23, 2023 16:04
@Maddiaa0 Maddiaa0 merged commit 3a5f99e into master May 23, 2023
@Maddiaa0 Maddiaa0 deleted the md/defensive-typing branch May 23, 2023 16:09
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.

3 participants