Repository navigation
Commit 979d1c0
fix: address CodeRabbit findings for ProvableCountProvableSumTree PR
Addresses every actionable finding from the CodeRabbit review on PR #670.
**Critical security fix**
- verify.rs::extract_elements_and_leaf_keys: reject
Node::KVRefValueHashCountSum in the opaque-hash guard alongside
KVRefValueHash{,Count,Sum}. Without this, a forged trunk/branch proof
could smuggle an unauthenticated dereferenced value through the new
dual-axis reference node — the merk-level hash chain would still
appear valid because the embedded opaque hash is treated as
authoritative, but the verifier never gets to see the referenced
value at this layer. Also extend leaf-count extraction to include
KVCountSum.
**Major correctness fixes**
- grovedb/src/lib.rs::aggregate_consistency_labels: add explicit arm
for (ProvableCountProvableSumTree, ProvableCountAndProvableSum)
+ empty-merk identity case. Without this, valid PCPS trees fell into
the catch-all and were reported as aggregate mismatches.
- merk/src/proofs/tree.rs::execute_with_options: include
KVCountSum / KVDigestCountSum / KVRefValueHashCountSum in the
Op::Push and Op::PushInverted BST-order key checks so dual-axis
proofs enforce the same monotonic-key invariant as every other keyed
node type.
- merk/src/proofs/query/verify.rs: thread dual-axis nodes through
the lower/upper-bound `last_push` matches, the absence-proof
last-push match, the `boundaries_in_proof` helper, and
`key_exists_as_boundary_in_proof`. Without these, `Key + Range`
queries against ProvableCountProvableSumTree could be wrongly
rejected with "Cannot verify lower bound of queried range" or
miss legitimate boundaries entirely.
- merk/src/proofs/query/mod.rs::to_kv_value_hash_feature_type_node:
recognize ProvableCountAndProvableSum aggregates and surface
TreeFeatureType::ProvableCountedAndProvableSummedMerkNode (was
falling through to self.tree().feature_type(), which would carry
the local feature instead of the aggregated (count, sum) that is
actually committed in the node hash for KvRefValueHashCountSum
reference proofs).
- grovedb/src/batch/mod.rs: add ProvableCountProvableSumTree arms in
two sites — the LayeredValueDefinedCost match for flag updates and
the InsertTreeWithRootHash propagation branch. Without these,
valid dual-axis batch inserts fell into the
"insertion of element under a non tree" error path during upward
propagation.
- grovedb/src/operations/proof/generate.rs: add an
`is_aggregate_sum_query` short-circuit for empty
ProvableSumTree / ProvableCountProvableSumTree under an
AggregateSumOnRange carrier. Without this, empty sum-bearing hosts
fell through to the generic empty-tree branch and no lower-layer
ASOR proof got emitted.
- grovedb/src/tests/provable_count_sum_tree_tests.rs::get_node_count:
recognize the dual-axis KVCountSum / KVDigestCountSum /
KVRefValueHashCountSum variants so rotation/stress proof-tests no
longer silently skip dual-axis nodes when verifying counts.
Also recognize ProvableCountedAndProvableSummedMerkNode feature
types in KVValueHashFeatureType nodes.
**Minor error-classification fixes**
- merk/src/proofs/query/aggregate_count/{mod,emit}.rs: change all
prover-side aggregate invariant failures from InvalidProofError
(verifier-class) to CorruptedData (local-corruption-class) per the
repo error-handling convention. The corresponding unit test now
expects CorruptedData. The sum side already used CorruptedData;
this brings the count side into alignment.
**Doc updates**
- merk/src/merk/{get,prove}.rs: include
ProvableCountProvableSumTree in the rustdoc allow-lists for
count_aggregate_on_range / sum_aggregate_on_range /
prove_aggregate_*_on_range so the contracts match the runtime
guards.
- grovedb-element/src/element/serialize.rs: list the
ProvableSumTree and ProvableCountProvableSumTree variants in the
serialize() doc — the wrapper allowlist grew from four to six
sum-bearing variants.
**Test fixups**
- Two existing tests (shape_walk_rejects_kvdigestcountsum_outside_inherited_bounds_pcps,
same for the sum side) were relaxed to accept any InvalidProofError
message — adding KVDigestCountSum to the BST-order check means
Phase 1's key-ordering catches the malformed key before Phase 2's
inherited-bounds check does. Either rejection is correct; the goal
is that an out-of-bounds boundary key never produces a successful
verify.
All 1720 grovedb + 540 merk tests pass; cargo fmt clean.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>1 parent 527e3af commit 979d1c0
15 files changed
Lines changed: 230 additions & 59 deletions
File tree
- grovedb-element/src/element
- grovedb/src
- batch
- operations/proof
- tests
- merk/src
- merk
- proofs
- query
- aggregate_count
- aggregate_sum
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2910 | 2910 | | |
2911 | 2911 | | |
2912 | 2912 | | |
| 2913 | + | |
2913 | 2914 | | |
2914 | 2915 | | |
2915 | 2916 | | |
| |||
3242 | 3243 | | |
3243 | 3244 | | |
3244 | 3245 | | |
| 3246 | + | |
| 3247 | + | |
| 3248 | + | |
| 3249 | + | |
| 3250 | + | |
| 3251 | + | |
| 3252 | + | |
| 3253 | + | |
| 3254 | + | |
| 3255 | + | |
| 3256 | + | |
| 3257 | + | |
| 3258 | + | |
| 3259 | + | |
| 3260 | + | |
| 3261 | + | |
3245 | 3262 | | |
3246 | 3263 | | |
3247 | 3264 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1287 | 1287 | | |
1288 | 1288 | | |
1289 | 1289 | | |
| 1290 | + | |
| 1291 | + | |
1290 | 1292 | | |
1291 | 1293 | | |
1292 | 1294 | | |
| |||
1398 | 1400 | | |
1399 | 1401 | | |
1400 | 1402 | | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
1401 | 1422 | | |
1402 | 1423 | | |
1403 | 1424 | | |
| |||
1431 | 1452 | | |
1432 | 1453 | | |
1433 | 1454 | | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
1434 | 1459 | | |
1435 | 1460 | | |
1436 | 1461 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1239 | 1239 | | |
1240 | 1240 | | |
1241 | 1241 | | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
1242 | 1248 | | |
1243 | 1249 | | |
1244 | 1250 | | |
| |||
1620 | 1626 | | |
1621 | 1627 | | |
1622 | 1628 | | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
| 1636 | + | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
1623 | 1666 | | |
1624 | 1667 | | |
1625 | 1668 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2598 | 2598 | | |
2599 | 2599 | | |
2600 | 2600 | | |
2601 | | - | |
2602 | | - | |
| 2601 | + | |
| 2602 | + | |
| 2603 | + | |
2603 | 2604 | | |
2604 | 2605 | | |
2605 | 2606 | | |
2606 | 2607 | | |
2607 | 2608 | | |
2608 | | - | |
2609 | | - | |
2610 | | - | |
2611 | | - | |
| 2609 | + | |
| 2610 | + | |
| 2611 | + | |
| 2612 | + | |
| 2613 | + | |
2612 | 2614 | | |
2613 | 2615 | | |
2614 | 2616 | | |
| |||
2640 | 2642 | | |
2641 | 2643 | | |
2642 | 2644 | | |
| 2645 | + | |
| 2646 | + | |
| 2647 | + | |
2643 | 2648 | | |
2644 | 2649 | | |
2645 | 2650 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
34 | 40 | | |
35 | 41 | | |
36 | 42 | | |
| |||
57 | 63 | | |
58 | 64 | | |
59 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
60 | 79 | | |
61 | 80 | | |
62 | 81 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
365 | 365 | | |
366 | 366 | | |
367 | 367 | | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
372 | 373 | | |
373 | 374 | | |
374 | 375 | | |
| |||
412 | 413 | | |
413 | 414 | | |
414 | 415 | | |
415 | | - | |
416 | | - | |
417 | | - | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
418 | 420 | | |
419 | 421 | | |
420 | 422 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
154 | 155 | | |
155 | 156 | | |
156 | 157 | | |
| |||
191 | 192 | | |
192 | 193 | | |
193 | 194 | | |
194 | | - | |
195 | | - | |
196 | | - | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
197 | 199 | | |
198 | 200 | | |
199 | 201 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
107 | 111 | | |
108 | 112 | | |
109 | 113 | | |
| |||
133 | 137 | | |
134 | 138 | | |
135 | 139 | | |
136 | | - | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
137 | 145 | | |
138 | 146 | | |
139 | 147 | | |
| |||
178 | 186 | | |
179 | 187 | | |
180 | 188 | | |
181 | | - | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
182 | 192 | | |
183 | 193 | | |
184 | 194 | | |
| |||
260 | 270 | | |
261 | 271 | | |
262 | 272 | | |
263 | | - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
264 | 278 | | |
265 | 279 | | |
266 | 280 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
69 | 71 | | |
70 | 72 | | |
71 | 73 | | |
72 | 74 | | |
73 | 75 | | |
74 | 76 | | |
75 | | - | |
| 77 | + | |
76 | 78 | | |
77 | 79 | | |
78 | 80 | | |
| |||
0 commit comments