Skip to content

fix: canonical row order from the MMR and dense standalone verifiers; validate limited non-Merk pages (#854) - #871

Merged
QuantumExplorer merged 1 commit into
developfrom
claude/grovedb-issue-854-4d3028
Sep 6, 2026
Merged

QuantumExplorer merged 1 commit into
developfrom
claude/grovedb-issue-854-4d3028

Conversation

@QuantumExplorer

Copy link
Copy Markdown
Member

Fixes #854.

What the audit found

MMR and dense proofs authenticate the set of positions and the value bound to each position. The sequence a proof carries those rows in is not hashed. At the audited revision GroveDB's lower-layer verifiers checked the position set for completeness and then truncated the proof's own sequence to the query limit, so a prover could permute the rows and pick which authenticated rows survive a limited query without changing the root.

State on develop

The GroveDB-level ordering was already fixed by #847 (merged after the audited revision): the MMR, bulk-append, dense and commitment-tree lower-layer verifiers sort by authenticated position, reverse for a descending query, and only then apply the limit.

What this PR does

Aligns the standalone crate contracts with the integrated one, which the issue also asks for. Previously both crates handed back rows in whatever order the proof supplied them:

  • grovedb-merkle-mountain-range: MmrTreeProof::verify and verify_and_get_root now return leaves in ascending leaf-index order (deduplicated by index, first occurrence kept — the same entry the root computation hashed). Shared canonical_leaves helper; documented contract.
  • grovedb-dense-fixed-sized-merkle-tree: verify_against_expected_root, verify_and_get_root and verify_for_query now yield entries in ascending position order; documented contract, including why left_to_right is the limit-applying caller's concern.
  • grovedb-bulk-append-tree already sorted in values_in_range; unchanged.

Any consumer that pages or truncates a standalone verifier's result now sees the same page for every permutation of the same proof.

Completes the validation the issue lists (new grovedb/src/tests/non_merk_limited_page_tests.rs, plus standalone tests in both crates):

  • limited_pages_match_trusted_reads_in_both_directions: for MMR, dense, bulk-append and commitment trees, ascending and descending, limits None / 1 / 3 / 7 under the global SizedQuery::limit: the verified page has exactly the positions a trusted read would select, the limited page is a prefix of the unlimited one, and every value equals the per-position trusted read (mmr_tree_get_value, dense_tree_get, bulk_get_value, commitment_tree_get_value).
  • permuted_lower_layers_cannot_move_the_page: decodes the honest proof, reverses the lower layer's rows (MMR leaves; dense entries; both the chunk MMR leaves and the buffer entries for bulk / commitment trees), re-encodes, and requires the identical root hash and page. Confirmed to fail when the sorts are removed on both layers.
  • Standalone: reversed and shuffled proofs verify to the same root and the same ascending sequence; a duplicated MMR index keeps the hashed (first) value.

No wire-format or version-gate change: the proof bytes are untouched, only the order verifiers surface already-authenticated rows in.

🤖 Generated with Claude Code

… validate limited non-Merk pages (#854)

The GroveDB lower-layer verifiers already order rows by authenticated
position and query direction before applying a limit (#847). The
standalone crate verifiers still surfaced rows in the order the proof
carried them — a sequence the root does not bind — so any caller that
paged or truncated their result could be steered by a permuted proof.

- grovedb-merkle-mountain-range: `MmrTreeProof::verify` and
  `verify_and_get_root` return leaves in ascending leaf-index order
  (deduplicated, first occurrence kept — the entry the root hashed).
- grovedb-dense-fixed-sized-merkle-tree: all three verifiers yield
  entries in ascending position order; contract documented.
- New grovedb tests compare limited and unlimited pages against
  per-position trusted reads in both directions across MMR, dense,
  bulk-append and commitment trees, and require a proof with a
  permuted lower layer to yield the identical root and page.
- Standalone tests: reversed/shuffled proofs verify to the same root
  and the same ascending sequence.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 51 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: b321bdab-4c2f-41e9-a656-a7f953736116

📥 Commits

Reviewing files that changed from the base of the PR and between 6fc7e1e and 51cb966.

📒 Files selected for processing (6)
  • grovedb-dense-fixed-sized-merkle-tree/src/proof/tests.rs
  • grovedb-dense-fixed-sized-merkle-tree/src/verify.rs
  • grovedb-merkle-mountain-range/src/proof.rs
  • grovedb-merkle-mountain-range/src/tests/test_mmr.rs
  • grovedb/src/tests/mod.rs
  • grovedb/src/tests/non_merk_limited_page_tests.rs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Sep 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.58%. Comparing base (6fc7e1e) to head (51cb966).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #871      +/-   ##
===========================================
- Coverage    92.58%   92.58%   -0.01%     
===========================================
  Files          297      297              
  Lines        92293    92292       -1     
===========================================
- Hits         85448    85447       -1     
  Misses        6845     6845              
Components Coverage Δ
grovedb-core 90.80% <ø> (ø)
merk 93.27% <ø> (ø)
storage 91.70% <ø> (ø)
commitment-tree 96.38% <ø> (ø)
mmr 95.11% <100.00%> (-0.01%) ⬇️
bulk-append-tree 92.75% <ø> (ø)
element 97.98% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@QuantumExplorer QuantumExplorer left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Reviewed

@QuantumExplorer
QuantumExplorer merged commit 274ecfe into develop Sep 6, 2026
11 checks passed
@QuantumExplorer
QuantumExplorer deleted the claude/grovedb-issue-854-4d3028 branch September 6, 2026 18:18
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.

[audit][P03] MMR and dense limited proofs can select the wrong authenticated page

1 participant