Skip to content

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

Merged
Maddiaa0 merged 6 commits into
masterfrom
md/defensive-typing
May 23, 2023
Merged

fix(merkle-tree): make sibling path generic over its length#647
Maddiaa0 merged 6 commits into
masterfrom
md/defensive-typing

Conversation

@Maddiaa0

@Maddiaa0 Maddiaa0 commented May 22, 2023

Copy link
Copy Markdown
Contributor

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

@LHerskind LHerskind left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
Contributor

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
AztecBot added a commit that referenced this pull request Jul 24, 2026
…4936)

Forward-ports the **barretenberg secp256r1 unique-lookup-index soundness
fix** to `next` — missed by the initial area-bucketed sweep because its
PR-numbered wrapper (#24842) is a merge commit and its content commits
carry no `(#N)` suffix (they arrived via merge PR #647), so both the
`--no-merges` and `(#N)` filters dropped them.

## Applied (clean cherry-picks, chronological)
- `c6ab912228` fix(bb): assign unique secp256r1 lookup table indices
- `3a53c977e4` test(bb): generalize lookup table-index invariant across
all tables
- `f013e4497f` comment cleanup

Corresponds to v5-next #24842. Part of the manual v5-next → next backlog
sweep.

---------

Co-authored-by: AztecBot <tech@aztec-labs.com>
Co-authored-by: ledwards2225 <l.edwards.d@gmail.com>
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