Repository navigation
fix: canonical row order from the MMR and dense standalone verifiers; validate limited non-Merk pages (#854) - #871
Merged
Conversation
… 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]>
Contributor
|
Warning Review limit reachedNext included review available in 51 minutes. View limit detailsLimit 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. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (6)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 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
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
developThe 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::verifyandverify_and_get_rootnow return leaves in ascending leaf-index order (deduplicated by index, first occurrence kept — the same entry the root computation hashed). Sharedcanonical_leaveshelper; documented contract.grovedb-dense-fixed-sized-merkle-tree:verify_against_expected_root,verify_and_get_rootandverify_for_querynow yield entries in ascending position order; documented contract, including whyleft_to_rightis the limit-applying caller's concern.grovedb-bulk-append-treealready sorted invalues_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, limitsNone / 1 / 3 / 7under the globalSizedQuery::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.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