Skip to content

chore: merkle tree audit 2#21475

Merged
nishatkoti merged 5 commits into
merge-train/barretenbergfrom
nk/merkle-tree-two
Apr 6, 2026
Merged

chore: merkle tree audit 2#21475
nishatkoti merged 5 commits into
merge-train/barretenbergfrom
nk/merkle-tree-two

Conversation

@nishatkoti

@nishatkoti nishatkoti commented Mar 13, 2026

Copy link
Copy Markdown
Contributor
  • Addresses TODO World state append-only trees: handle index errors #17755 by resolving the bounds-related issues and documenting the current leaf-read semantics in content_addressed_append_only_tree.hpp:
    • leaf_index >= max_size_ → failure (out of tree range)
    • leaf_index < max_size_ but leaf not written → return 0 with success = true
    • (Historical reads at a block) leaf_index >= blockData.size → failure (out of block range)
    • (Historical reads at a block) leaf_index < blockData.size but leaf not written → return 0 with success = true
  • Update audit headers

@nishatkoti nishatkoti marked this pull request as ready for review March 17, 2026 08:03
@nishatkoti nishatkoti requested a review from ledwards2225 March 17, 2026 08:04

@ledwards2225 ledwards2225 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.

LGTM just a few things to resolve before merging


// TODO(#17755): This does not consider maximum leaf index and will wrap around to give incorrect values.
// e.g. if leaf_index = maximum + 1, returns the leaf at index + 1. See #17684
// Improvement: For out-of-range reads, define the desired native/TS behavior (e.g.

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.

Does the throw above effectively resolve this issue?

@nishatkoti nishatkoti Mar 24, 2026

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.

It resolved only the bounds off-by-one issue earlier. The remainder is now resolved by documenting the current behaviour as the intended behaviour.

// TODO(#17755): Throw error to world state -> TS? (native_world_state_instance.ts -> call()
// translates this to null)
if (max_size_ <= leaf_index) {
// Improvement: clarify the contract for reads beyond tree capacity and align native/TS handling

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.

Can you try to get clarity on this from Miranda (or Phil?) then resolve one way or the other? Seems we shoudl be able to make a decision if this is production code? Same with the other TODOs

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 discussed with Phil and we decided to document the current behaviour in code as the intended behaviour and close the TODO. I’ve updated the comments in the code accordingly and closed the TODOs.

return;
}
if (blockData.size < leaf_index) {
if (blockData.size <= leaf_index) {

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.

nice!


Repository: https://github.com/AztecProtocol/aztec-packages
Commit hash: TBD (link)
Commit hash: 158dd845c99f8f702979c20f1625730d126c4b20

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.

Can you update this to:

Suggested change
Commit hash: 158dd845c99f8f702979c20f1625730d126c4b20
Commit hash: Most recent commit on branch 'next'

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.

Updated with the latest commit from next

Base automatically changed from merge-train/barretenberg to next March 24, 2026 00:19
@nishatkoti nishatkoti changed the base branch from next to merge-train/barretenberg March 24, 2026 13:06
@nishatkoti nishatkoti requested a review from ledwards2225 March 24, 2026 13:09
Base automatically changed from merge-train/barretenberg to next March 26, 2026 15:45
@ledwards2225 ledwards2225 changed the base branch from next to merge-train/barretenberg April 2, 2026 20:18
@nishatkoti nishatkoti force-pushed the nk/merkle-tree-two branch from 46a9859 to 40e2604 Compare April 6, 2026 11:50
@nishatkoti nishatkoti merged commit f6f0327 into merge-train/barretenberg Apr 6, 2026
12 checks passed
@nishatkoti nishatkoti deleted the nk/merkle-tree-two branch April 6, 2026 13:04
github-merge-queue Bot pushed a commit that referenced this pull request Apr 6, 2026
BEGIN_COMMIT_OVERRIDE
fix: reject VK with log_circuit_size=0 in UltraKeccak verifier (#22319)
chore: merkle tree audit 2 (#21475)
fix: graceful failures in verifier code paths + other fixes (#22311)
fix: Fr::from_u64 big-endian encoding to match C++ msgpack format
(#22233)
fix: corrupt low-order bytes in batch verifier test to avoid
non-canonical field encoding (#22333)
fix: skip MsgpackRejectsNonCanonical test in WASM builds (#22335)
END_COMMIT_OVERRIDE
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