Skip to content

fix(merk): opaque proof nodes must stay childless (#853) - #873

Merged
QuantumExplorer merged 1 commit into
developfrom
claude/issue-853-a2bf9d
Sep 6, 2026
Merged

QuantumExplorer merged 1 commit into
developfrom
claude/issue-853-a2bf9d

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Sep 6, 2026 •

Copy link
Copy Markdown
Member

Fixes #853.

Problem

Node::Hash, HashWithCount, HashWithSum and HashWithCountAndSum compute their hash from embedded fields only. Tree::attach nevertheless let Parent/Child ops hang children beneath them, and nothing rejected the resulting shape:

  • the query verifier consumes pushes in push order, so a forged KV parked under a collapsed Hash leaf was emitted as a result row while the root hash still matched the honest tree;
  • the chunk restorer walks the reconstructed tree, so the same shape wrote an unauthenticated row into storage.

Both were reproduced at runtime (new tests fail on develop): a proof for the honest 3-node tree [3] <- [5] -> [7] verifies against the honest root while claiming key 3 holds "forged".

Fix

Tree::attach now refuses to attach anything beneath an opaque node (Tree::is_opaque), so every consumer of execute inherits the rule: query verification, chunk restore, branch proofs and the aggregate verifiers. The aggregate verifiers' own leaf-shape checks are retained as defense in depth.

No version gate: honest provers never emit an opaque node with children, so no legitimate proof changes acceptance. The merk execute path is shared by V0 and V1 and no wire format changes.

Tests

  • test_forged_row_under_hash_node_is_rejected / ..._right_hash_node_...: forged row under a Hash node in a query proof.
  • test_forged_kv_under_hash_boundary_node_is_rejected: forged KV under a Hash boundary in a restore chunk; nothing reaches storage.
  • attach_to_opaque_node_is_rejected / attach_to_kvhash_node_is_allowed.
  • Existing shape-walk tests that spliced children under opaque leaves now accept the earlier attach rejection; the proof resource-limit tests build their synthetic chains from KVHash instead of Hash.

Docs: recorded the invariant in docs/merk-deep-dive.md and the book's proof-system chapter.

Local run: merk 726/726, grovedb 2994/2994, rest of workspace 2201/2201 (all-features minus grovedbg, whose build script needs network here). Clippy under a local clippy 1.97 reports lints in files this PR does not touch (CI's toolchain is clean); no lints in the changed regions.

🤖 Generated with Claude Code

`Node::Hash`, `HashWithCount`, `HashWithSum` and `HashWithCountAndSum`
compute their hash from embedded fields only, ignoring any children the
`Parent`/`Child` ops hang beneath them in the reconstructed proof tree.
The query verifier consumes pushes in push order and the chunk restorer
walks the reconstructed tree, so a prover could park a forged `KV` under a
collapsed `Hash` leaf: the forged row was emitted as a query result (or
written to storage during restore) while the root hash still matched the
honest tree.

`Tree::attach` now refuses to attach anything beneath an opaque node, so
every consumer of `execute` (query verification, chunk restore, branch
proofs, aggregate verifiers) inherits the rule. The aggregate verifiers'
own leaf-shape checks are kept as defense in depth.

No version gate: honest provers never emit an opaque node with children,
so no legitimate proof changes acceptance.

Tests: forged row under a `Hash` node in a query proof (both sides),
forged `KV` under a `Hash` boundary in a restore chunk, `attach` unit
tests; the existing shape-walk tests that spliced children under opaque
leaves now accept the earlier `attach` rejection, and the resource-limit
tests build their synthetic chains from `KVHash` instead of `Hash`.

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 34 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: 0b1e37f9-25ed-4e3f-8066-88dc07b44e6d

📥 Commits

Reviewing files that changed from the base of the PR and between 3be2eb6 and 4d97929.

📒 Files selected for processing (8)
  • docs/book/src/proof-system.md
  • docs/merk-deep-dive.md
  • merk/src/merk/restore.rs
  • merk/src/proofs/query/aggregate_count/tests.rs
  • merk/src/proofs/query/aggregate_count_and_sum/tests.rs
  • merk/src/proofs/query/aggregate_sum/tests.rs
  • merk/src/proofs/query/merk_integration_tests.rs
  • merk/src/proofs/tree.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.54%. Comparing base (6fc7e1e) to head (4d97929).
⚠️ Report is 2 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #873      +/-   ##
===========================================
- Coverage    92.58%   92.54%   -0.04%     
===========================================
  Files          297      297              
  Lines        92293    92380      +87     
===========================================
+ Hits         85448    85494      +46     
- Misses        6845     6886      +41     
Components Coverage Δ
grovedb-core 90.80% <ø> (ø)
merk 93.10% <100.00%> (-0.17%) ⬇️
storage 91.70% <ø> (ø)
commitment-tree 96.38% <ø> (ø)
mmr 95.12% <ø> (ø)
bulk-append-tree 92.78% <ø> (+0.02%) ⬆️
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 d998d76 into develop Sep 6, 2026
13 checks passed
@QuantumExplorer
QuantumExplorer deleted the claude/issue-853-a2bf9d branch September 6, 2026 18: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.

[audit][P02] Verified query and restore results may include data outside the committed tree

1 participant