Skip to content

feat(platform)!: keep document sums in 128 bits when the summed property passes 2^27 (PV15) - #5987

Merged
QuantumExplorer merged 24 commits into
v5.1-devfrom
feat/wide-document-sums
Nov 19, 2026
Merged

QuantumExplorer merged 24 commits into
v5.1-devfrom
feat/wide-document-sums

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Basic explanation

What this does: A document type can sum one of its properties over its documents and its indexes. Drive keeps each of those sums as the total of a GroveDB tree, and that total is a 64-bit signed integer. From protocol version 15 a type whose summed property may hold large values keeps its sums in trees with a 128-bit total instead. A type whose summed property is declared small (a minimum and a maximum within plus or minus 2^27) keeps the 64-bit trees it has today.

Value: A sum of large values no longer has a ceiling a few values can reach. The document history contract sums sale and listing prices in credits, which are 64-bit amounts, so their sum can pass what a 64-bit total holds. With a 128-bit total the write that adds a price is applied whatever the prices before it were.

Risks: Medium, and confined to protocol version 15. It changes the trees Drive stores for the affected types, so it is consensus-breaking at that version, and the first block of the version converts trees stored earlier. Protocol versions 1 to 14 are unchanged, which the root hash pins confirm. A sum that passes 64 bits cannot be returned by a query yet: it is refused with an explicit error (see "Not in this pull request"). The pull request is a draft because it pins GroveDB at the head of dashpay/grovedb#1063, which is not merged.

Issue being fixed or feature implemented

A tree with a 64-bit sum refuses the write that would take its total past the i64 range, and Drive cannot apply that write. #5956 keeps the sums of user document types inside the range at protocol version 15 with a bound at registration and a check in state validation. The types only the protocol writes are exempt from that bound, and the document history contract's price is one: it declares no bound, since a price is any amount of credits.

Before, in a tree with a 64-bit sum:

price 9_223_372_036_854_775_807   recorded, total 9_223_372_036_854_775_807
price 1                           not applied: the total would pass the i64 range

After, at protocol version 15, in the tree with a 128-bit sum:

price 9_223_372_036_854_775_807   recorded
price 1                           recorded
price 9_223_372_036_854_775_807   recorded, count 3, total 18_446_744_073_709_551_615

Earlier protocol versions keep their trees and their outcomes; the tests pin both sides.

Supersedes #5966, whose tests this carries and extends.

What was done?

The rule

SystemLimits::max_summed_value_magnitude_in_64_bit_sums (None before, Some(1 << 27) in SYSTEM_LIMITS_V5). A document type keeps its sums in 128 bits unless its summed property declares both a minimum of at least -2^27 and a maximum of at most 2^27. There is no new keyword: the width follows the bounds the schema already declares.

summed property declares sums kept in
minimum: 0, maximum: 1000 64 bits, as today
minimum: -134217728, maximum: 134217728 64 bits, as today
minimum: 1, maximum: 4294967295 128 bits
no bounds (the history contract's price) 128 bits

dpp

  • The document type parser (shared body of generations 3 and 4, apply_summed_value_width) records the outcome on the type, DocumentTypeV2Getters::uses_big_sums(), and on every index level where a summing index ends, IndexLevelTypeInfo::big_sums. It runs in every build, with or without full validation, because it decides what Drive stores.
  • The stored (compiled) form of a document type keeps the flag, so a type reads back with the width it was stored with.

Drive, writes

tree_type_for_sum_width (drive/document/index_level_tree_types.rs) maps a tree to its 128-bit counterpart:

64-bit sum 128-bit sum
SumTree BigSumTree
CountSumTree CountBigSumTree
ProvableSumTree ProvableBigSumTree
ProvableCountSumTree ProvableCountProvableBigSumTree
ProvableCountProvableSumTree ProvableCountProvableBigSumTree
ProvableSumIndexedTree ProvableBigSumIndexedTree
ProvableCountProvableSumIndexedTree ProvableCountProvableBigSumIndexedTree

GroveDB has no tree with a provable count and a 128-bit sum outside its node hashes, so ProvableCountProvableBigSumTree stands in for ProvableCountSumTree.

It is applied to the value trees, the property-name trees (with IndexAxis::BigSum in place of IndexAxis::Sum for a ranked index), the entries trees and, through primary_key_tree_type 2, the primary tree. Contract registration and update create the new trees (both fell back to a plain tree for a type they did not name), and the wrappers that keep a continuation out of its parent's aggregates take them. A document's own value is still a 64-bit sum item.

Drive, reads

  • New query::sum_width: the sum, count and sum, and average readers, and the verifiers that read a sum off a proved element, read at either width. A sum is returned when it fits the 64 bits a result carries and refused otherwise. GroveDB's 64-bit accessors give 0 for a tree with a 128-bit sum, so none of these paths uses them for one.
  • Range sums and their proofs go through GroveDB's *big_sum* entry points for a type that keeps big sums (query_aggregate_big_sum, query_aggregate_count_and_big_sum, verify_aggregate_big_sum_query and the per-key verifiers).
  • Drive::fetch_document_type_sum and the sums a rule constraint reads (fetch_property_constraint_aggregate) read at either width.
  • Ranked top-k reads, HAVING ranges and their proofs rank a summing index of a type that keeps big sums on the big sum axis (index_axis_for), and present its results as the 64-bit sums a ranked entry carries.

Registration and update (dpp)

  • A contract update may not change the width a type keeps its sums in: document type update validation 2 refuses it (DocumentTypeUpdateError). The width follows the summed property's bounds, which an update may widen, and the type's trees were created at the width it had.
  • A sum ranking of a type that keeps big sums is on the big sum axis, whose 16-byte sort key leaves a group key 239 bytes (as for the average axis, against 247 for the sum axis). It is checked again once the width is known, including for a derived index property.

Activation

Drive::convert_document_sums_to_big_sums (drive/document/migration/big_sums.rs) runs on the first block of protocol version 15, after the retained histories are moved and in the same transaction. For every type in state that keeps big sums it converts the trees that hold its sums to their 128-bit counterparts where they stand (GroveDb::convert_to_big_sum_tree): the primary tree, and for each summing index the property tree, each value tree and its entries tree, a parent before the trees that add their sums to it. No document, index entry or reference is written again. The trees of an index that sums nothing and the counters of a summableOffCountIndex index keep their width. Each contract with such a type is marked as modified in the block and its block cache seeded with this version's reading (refresh_data_contract_cache_from_state), so a committed-state reader still at the earlier version cannot hand the block the earlier reading.

After the conversion a type's trees are the ones a chain born at the version holds for the same writes. A ranked tree that holds a key longer than 239 bytes and has no average axis is left as stored and counted, since the big sum axis does not rank such a key.

GroveDB

Pinned at 92c91657, the head of dashpay/grovedb#1063 (temporary, to be moved to its merge commit). Since 22f163c2 this brings the trees with a 128-bit sum, the big sum axis and the in-place conversion, all behind GROVE_V5 slots. Drive's exhaustive matches, its restated cost tables, rs-sdk-ffi and wasm-sdk name the new elements. Other GROVE_V5 changes that come with the pin: an average-case estimate sizes a wrapped tree with its wrapper's byte, a tree a batch creates and fills meets its insert checks, and a proof layer with subqueries under a per-instance limit stops where the limit is spent.

Not in this pull request

  • A sum past 64 bits cannot be returned: the getDocuments responses, drive-proof-verifier, the Rust SDK, wasm-sdk and rs-sdk-ffi carry 64-bit sums. Such a read fails with "the sum does not fit the 64 bits a sum result carries".
  • The registration bound and the type total check of fix(platform)!: hold a document write to the total its type keeps of its summed property #5956 are unchanged, and still hold a user type's total to the 64-bit range.
  • A single value above i64::MAX is not storable at either width, as before.
  • The activation walk reads the values of one index level in one query.
  • The v15.rs note and the book.

How Has This Been Tested?

Targeted runs, not the whole workspace. drive-abci needs RUST_MIN_STACK=16777216 locally.

  • rs-dpp try_from_schema/v3/summed_value_width_tests.rs: the width for bounds within and past the limit, with and without full validation, per index level, and 64 bits at protocol version 14 whatever the bounds.
  • rs-drive query/sum_width.rs: a 64-bit element reads as its own accessors read it; a 128-bit sum that fits is read; one past 64 bits is refused.
  • rs-drive insert/add_history_operations tests: listings and purchases whose prices sum past 64 bits are recorded at the latest version and refused at protocol version 14; range sum and count and sum proofs verify at both versions; a proved sum past 64 bits is refused as too wide.
  • rs-drive migration/big_sums_tests.rs: state written at protocol version 14 and converted equals, element by element, a chain born at protocol version 15 with the same writes, for the history contract, for a type with a wrapped continuation level and for a type with a ProvableCountSumTree, before and after one more write; a second run converts nothing; verify_grovedb is clean.
  • rs-drive-abci batch/tests/document/dpns.rs: should_record_a_listing_once_the_listed_prices_pass_64_bits through check_tx and a block, with its protocol version 13 and 14 twins unchanged.
  • rs-drive-abci upgrade tests: the activation gives the same root with the GROVE_V4 reference (the three 128-bit capability slots set) and GROVE_V5; the upgrade strategy tests pass, which check state against drive::structure.
  • Sets run: cargo test -p dpp --lib --all-features -- data_contract::document_type; cargo test -p drive --lib -- drive::document insert_contract update_contract query:: verify:: structure:: migration; cargo test -p drive --test deterministic_root_hash --test query_tests --test query_tests_history; cargo test -p drive-abci --lib -- batch::tests::document protocol_upgrade query::document_query query::document_history; cargo test -p drive-abci --test strategy_tests -- upgrade; cargo test -p dash-sdk --lib -- signed_version_tests; cargo test -p drive-proof-verifier.

rs-dpp/tests/fixtures/stored_contracts/stored.jsonl is regenerated (protocol version 15 is unreleased, as its README requires): each contract kept whole grows by one byte per document type, the index structure hashes change with the big_sums field of an index level, and the contracts with no document type are unchanged.

Pinned values that moved, all at protocol version 15 only: a stored contract is one byte larger per document type, which moves the contract roots and fees (deterministic_root_hash latest arm, six roots in query_tests.rs, one in query_tests_history.rs, the activation root, the token history growth row); a type that now keeps big sums has larger nodes (the tip jar estimates, four fees of the type total tests, one restore fee).

In-place changes to shipped generations

Each edit below is unreachable before protocol version 15, for one of two reasons.

The type does not keep big sums there. rs-dpp sets uses_big_sums() and IndexLevelTypeInfo::big_sums only when max_summed_value_magnitude_in_64_bit_sums is Some, and it is None in SYSTEM_LIMITS_V1 to V4 (protocol versions 1 to 14).

  • rs-dpp document type parser generation 3 body (protocol version 14; generation 4 reuses it): apply_summed_value_width returns on the None limit before reading anything.
  • rs-drive index_level_tree_types.rs: index_level_tree_types_with_continuation_demotion, terminal_member_tree_type, terminal_value_tree_type (insert, delete and update walkers of every version).
  • rs-drive ranked_index_tree_type.rs: property_name_tree_type_and_ranked_axes, ranked_axes_for_index_level_info, ranked_property_name_tree_type (reached by insert_contract 0 and update_contract 0, every version).
  • rs-dpp parser generation 3 (protocol version 14): ranked_level_key_length_limit takes the width, which every existing caller passes as false, and validate_big_sum_ranked_key_lengths returns before reading anything for a type that does not keep big sums; resolve_derived_index_properties passes the declaring type's width.
  • rs-drive ranked and HAVING readers and verifiers (verify_ranked_top_k_proof 0, verify_having_range_proof 0, unversioned executors): index_axis_for returns the axis of the same name unless the type keeps big sums.
  • rs-drive verifiers verify_aggregate_sum_proof 0, verify_aggregate_count_and_sum_proof 0, verify_carrier_aggregate_sum_proof 0, verify_carrier_aggregate_count_and_sum_proof 0, and the unproven range readers: the 128-bit branch is taken only for a type that keeps big sums.

No tree with a 128-bit sum exists there. GroveDB creates one only under GROVE_V5, which protocol version 15 alone selects.

  • rs-drive insert_contract 0 and update_contract 0: new match arms for the 128-bit tree types.
  • rs-drive time_range_ttl.rs (drain_expired_node, protocol version 14): arms for the two 128-bit indexed parents.
  • rs-drive zero_contribution_wrapper and the wrapper builders in fees/op.rs: new arms for the 128-bit tree types.
  • rs-drive fetch_property_constraint_aggregate 0 (protocol version 14) and the element verifiers verify_point_lookup_sum_proof 0, verify_point_lookup_count_and_sum_proof 0, verify_distinct_sum_proof 0, verify_distinct_count_and_sum_proof 0, verify_primary_key_sum_tree_proof 0, verify_primary_key_count_sum_tree_proof 0, with the unproven readers beside them: they read through big_sum_value_or_default and count_big_sum_value_or_default, which return what sum_value_or_default and count_sum_value_or_default return for every element that holds no 128-bit sum. query::sum_width's tests compare the two over the 64-bit elements.

Edited in place because only the unreleased protocol version selects them: primary_key_tree_type (new generation 2), document type validate_update 2, perform_events_on_first_block_of_protocol_change 3, fetch_document_type_sum 0, the stored form of a document type, and SYSTEM_LIMITS_V5.

Breaking Changes

Consensus, protocol version 15 only

  • A document type whose summed property is not declared within plus or minus 2^27 stores its sums in different trees. Each entry of such a tree takes 8 more bytes in its node and 8 in the link to it, so the type's documents cost more storage.
  • The first block of the version converts the trees such a type stored before.
  • A contract update that would change a type's sum width is refused (DocumentTypeUpdateError).
  • A type that keeps big sums may not register a sum ranking whose group key can pass 239 bytes.
  • A stored contract is one byte larger per document type.

Queries

  • A sum, or a count and a sum, past 64 bits is refused (QuerySyntaxError::Unsupported) where the tree holding it now accepts it. Before, no tree could hold one.

Rust API

  • SystemLimits has a new field, max_summed_value_magnitude_in_64_bit_sums: Option<u64>.
  • IndexLevelTypeInfo has a new public field, big_sums: bool.
  • DocumentTypeV2Getters has a new method, uses_big_sums(&self) -> bool.
  • Drive::fetch_document_type_sum returns (i128, FeeResult), was (i64, FeeResult).
  • New: Drive::convert_document_sums_to_big_sums(&self, transaction: &Transaction, platform_version: &PlatformVersion) -> Result<DocumentSumConversionStats, Error> and DocumentSumConversionStats { contracts, types, converted_trees, trees_left_as_stored }.
  • Through the GroveDB re-exports: new Element, TreeType and ElementType variants (CountBigSumTree, ProvableBigSumTree, ProvableBigSumIndexedTree, ProvableCountProvableBigSumIndexedTree), IndexAxis::BigSum, two more weights and two more All* variants on EstimatedSumTrees, and the proof node KVBackwardsReferencesValueHash is gone. Code matching these exhaustively needs the new arms.

SDK surfaces

  • rs-sdk-ffi path element queries render the new elements: count_big_sum_tree:<count>:<sum>, provable_big_sum_tree:<sum>, provable_big_sum_indexed_tree:<sum>, provable_count_provable_big_sum_indexed_tree:<count>:<sum>, with type names of the same spelling.
  • wasm-sdk GroveElementType gains countBigSumTree, provableBigSumTree, provableBigSumIndexedTree, provableCountProvableBigSumIndexedTree and their nonCounted, notSummed and notCountedOrSummed forms.

Checklist:

  • I have performed a self-review of my own code
  • My Rust, FFI, WASM, Swift or Kotlin changes follow the coding conventions
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed
  • If I added or changed GroveDB structure, I described it in the area's structure.rs, regenerated grovedb-structure.json, and checked the structure viewer link posted on this pull request
  • If I added or changed a system contract's document schemas, I checked the contract viewer link posted on this pull request

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

QuantumExplorer and others added 11 commits November 18, 2026 23:20
Moves the nine GroveDB crates from 22f163c2 to 2a79d035 (develop).

What comes in:

- Trees with a 128-bit sum: `CountBigSumTree`, `ProvableBigSumTree`,
  and the ranked `ProvableBigSumIndexedTree` and
  `ProvableCountProvableBigSumIndexedTree` with the big sum axis
  (`IndexAxis::BigSum`). All are creatable from `GROVE_V5` only. Drive
  names them in its exhaustive matches (cost tables, estimate keys,
  layout names, the structure description, empty tree construction) and
  creates none. `rs-sdk-ffi` and `wasm-sdk` render them when a path
  query returns one.
- `EstimatedSumTrees::SomeSumTrees` has two more weights
  (`count_big_sum_trees_weight`, `provable_big_sum_trees_weight`). Every
  estimate passes 0, which leaves it as it was.
- The referrer list of a bidirectional reference target is no longer in
  node hashes, and the proof node that carried it is gone. Drive stores
  no bidirectional reference.
- New `GROVE_V5` behaviour, which protocol version 15 selects and
  protocol version 14 and earlier (`GROVE_V4` and below) do not:
  an average-case estimate sizes a tree wrapped in `NonCounted`,
  `NotSummed` or `NotCountedOrSummed` with the byte of its wrapper, as
  the apply charges it; a tree a batch both creates and fills is held to
  the checks its insert alone meets; a proof layer with subqueries under
  a per-instance limit stops where the limit is spent; a verifier charges
  an empty tree that is a result row as the prover does; a conditional
  branch with no subquery returns the tree at its key as a row.

No pinned test value changed at any protocol version.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…rty passes 2^27 (PV15)

A document type sums one property across its documents and its indexes,
in GroveDB trees whose total is an `i64`. From protocol version 15 a
type keeps every such sum in the tree with an `i128` total instead,
unless its summed property declares a `minimum` and a `maximum` within
plus or minus 2^27 (`SystemLimits::max_summed_value_magnitude_in_64_bit_sums`,
`None` before). A property declared within the limit keeps the 64-bit
trees it has today.

dpp: the document type parser records the outcome on the type
(`DocumentTypeV2Getters::uses_big_sums`) and on every index level where
a summing index ends (`IndexLevelTypeInfo::big_sums`), with or without
full validation. The stored form of a document type keeps it.

drive: `tree_type_for_sum_width` maps a tree to its 128-bit counterpart
(`SumTree` to `BigSumTree`, `CountSumTree` to `CountBigSumTree`,
`ProvableSumTree` to `ProvableBigSumTree`, `ProvableCountSumTree` and
`ProvableCountProvableSumTree` to `ProvableCountProvableBigSumTree`, the
two ranked trees to theirs, with the big sum axis). It is applied to the
value trees, the property-name trees, the member buckets and, through
`primary_key_tree_type` 2, the primary tree. Contract registration and
update create the new trees, and the zero-contribution wrappers take
them. The sum, count and sum, and average readers read a 128-bit tree
through GroveDB's 128-bit entry points and return the sum when it fits
the 64 bits a result carries; a larger one is refused. The total of a
type and the sums a rule constraint reads are read at either width.

Shipped generations reach the edited helpers. They are unchanged there:
dpp marks a type as keeping big sums only when the limit is set, which
no limits table before protocol version 15 does.

Not in this commit: proofs of sums over a 128-bit tree and their
verifiers, ranked reads on the big sum axis, results wider than 64 bits
in the query responses and the SDKs, and the trees of types stored
before protocol version 15, which keep their width.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The verifiers that read a sum, or a count and a sum, off a proved tree
element used GroveDB's 64-bit accessors, which give 0 for a tree with a
128-bit sum. They now read the element through `query::sum_width`, as
the unproven readers do: the sum is returned when it fits the 64 bits a
result carries and refused when it does not.

For every element holding no 128-bit sum the two accessors agree, so a
proof of state before protocol version 15 verifies to what it verified
to.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Temporary: 320a9ab3 is the head of the open pull request that adds
`GroveDb::convert_to_big_sum_tree`, which the next commit calls. To be
moved to the merge commit on `develop` once the pull request merges.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…t block of protocol version 15

A document type whose summed property may pass 2^27 keeps its sums in
128 bits from protocol version 15. A type stored before that version
holds them in trees with a 64-bit total, so the first block of the
version converts those trees to their 128-bit counterparts where they
stand (`GroveDb::convert_to_big_sum_tree`), after the retained histories
are moved and in the same transaction. No document, index entry or
reference is written again.

`Drive::convert_document_sums_to_big_sums` walks every contract in
state. For a type that keeps big sums it converts the primary tree of a
type that sums its documents and, for every index summing the property,
the tree named after its last property, the tree of each of that
property's values and the entries tree in it, each before the trees
that add their sums to it. The trees of an index that sums nothing and
the counters of a `summableOffCountIndex` index keep their width.

After the conversion a type's trees are the ones a chain born at the
version holds for the same writes: the tests compare every element of
the two, for the document history contract and for a type with wrapped
continuation levels, before and after a further write.

Left as stored, and counted in the returned statistics: a
`ProvableCountSumTree`, which has no 128-bit counterpart to convert to
in place, and a ranked tree GroveDB refuses for a key too long for the
big sum axis, with the trees that add their sums to them.

The structure description of document trees lists the 128-bit kinds.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The head of dashpay/grovedb#1063 after its review rounds: the conversion
is refused for a tree whose element does not record what its tree holds
and holds every child to what the wide tree accepts, and a repair of an
indexed tree's secondaries writes each row as its own operation
(`GROVE_V5` only). Still temporary: to be moved to the merge commit.

No change was needed in Platform, and the conversion and upgrade tests
pass as before.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The head of dashpay/grovedb#1063, whose conversion now also takes a
`ProvableCountSumTree`, to a `ProvableCountProvableBigSumTree`. Still
temporary: to be moved to the merge commit once the pull request merges.

No change was needed in Platform to build against it.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
… sum at activation

The activation conversion of document sums left a `ProvableCountSumTree`
as stored, since GroveDB had no conversion for it. It now converts it to
a `ProvableCountProvableBigSumTree`, the tree a write of the type creates
in its place from protocol version 15, so a type with such a tree ends
up as a chain born at the version holds it, like every other.

Such a tree holds the entries of an index that counts with offsets and
sums without range sums, the values of an index that is countable, range
countable and summable without range sums, or the documents of a type
that is range countable and sums its documents without range sums.

The only tree still left as stored is a ranked tree holding a key too
long for the big sum axis.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The four verifiers of a sum, or a count and a sum, over a range of an
index (`verify_aggregate_sum_proof`, `verify_aggregate_count_and_sum_proof`
and the two per-key ones) call GroveDB's 128-bit verifiers for a document
type that keeps its sums in 128 bits, whose trees the 64-bit verifiers
refuse. The sum is returned when it fits the 64 bits a result carries
and refused when it does not.

No type keeps its sums in 128 bits before protocol version 15, so the
shipped generations verify as they did.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ded price

Adds four tests of a price update on a DPNS name, whose type records each
price in the document history contract: at the largest price the record
holds, after it, at zero, and above it. They pin today's results at protocol
versions 13, 14 and the latest, so a later change to them shows up in a test.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
(cherry picked from commit 5dd953e)
…s (PV15)

The latest-version test of a listing after one at the largest price a
signed 64-bit integer holds now shows the listing recorded: it passes
`check_tx`, executes, is paid for, uses the seller's nonce and lists the
name, and the tree holding the contract's listed prices has the sum past
64 bits. The protocol version 13 and 14 twins keep the outcome they pin:
the listing ends as an internal error.

A price above the signed 64-bit range is unchanged at every version.

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

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Too many files!

This PR contains 126 files, which is 26 over the limit of 100.

To get a review, reduce the PR to 100 files or fewer by splitting it into smaller PRs or changing its base branch.

Upgrade to a paid plan to raise the limit.

This review couldn't start because sufficient usage credits or metered capacity aren't available. Add credits or update usage-based reviews in the billing tab, then retry.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 083c865 and 5acaa40.

Files ignored due to path filters: 1

  • Cargo.lock is excluded by !**/*.lock
Files selected for processing: 126

  • Cargo.toml
  • packages/rs-dpp/src/data_contract/document_type/accessors/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/accessors/v2/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/v3/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/v3/summed_value_bounds_tests.rs
  • packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/v3/summed_value_width_tests.rs
  • packages/rs-dpp/src/data_contract/document_type/index_level/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/methods/validate_update/v2/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/serialized_version/v0/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/v2/accessors.rs
  • packages/rs-dpp/src/data_contract/document_type/v2/mod.rs
  • packages/rs-dpp/tests/fixtures/stored_contracts/stored.jsonl
  • packages/rs-drive-abci/src/execution/check_tx/v0/mod.rs
  • packages/rs-drive-abci/src/execution/platform_events/protocol_upgrade/perform_events_on_first_block_of_protocol_change/token_history_storage_flags_tests.rs
  • packages/rs-drive-abci/src/execution/platform_events/protocol_upgrade/perform_events_on_first_block_of_protocol_change/v3/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/document/document_type_sum_validation/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/dpns.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/keep_history.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/sum_overflow.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/token/shielded/nullifier_batch_guard.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/contract_user_moderation/tests/restore_constraints.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/contract_user_moderation/tests/type_total.rs
  • packages/rs-drive-proof-verifier/src/proof/document_average.rs
  • packages/rs-drive-proof-verifier/src/proof/document_having.rs
  • packages/rs-drive-proof-verifier/src/proof/document_ranked.rs
  • packages/rs-drive-proof-verifier/src/proof/document_sum.rs
  • packages/rs-drive-proof-verifier/src/verify.rs
  • packages/rs-drive/grovedb-structure.json
  • packages/rs-drive/src/drive/address_funds/estimated_costs/for_address_balance_update/v0/mod.rs
  • packages/rs-drive/src/drive/address_funds/estimated_costs/for_address_balance_update/v1/mod.rs
  • packages/rs-drive/src/drive/asset_lock/estimation_costs/add_estimation_costs_for_adding_asset_lock/v0/mod.rs
  • packages/rs-drive/src/drive/contract/estimation_costs/mod.rs
  • packages/rs-drive/src/drive/contract/fee_pots/estimated_costs/v0/mod.rs
  • packages/rs-drive/src/drive/contract/insert/insert_contract/v0/mod.rs
  • packages/rs-drive/src/drive/contract/update/update_contract/v0/mod.rs
  • packages/rs-drive/src/drive/document/cost/grove_costs.rs
  • packages/rs-drive/src/drive/document/cost/mod.rs
  • packages/rs-drive/src/drive/document/cost/tests.rs
  • packages/rs-drive/src/drive/document/cost/writes.rs
  • packages/rs-drive/src/drive/document/delete/mod.rs
  • packages/rs-drive/src/drive/document/delete/remove_reference_for_index_level_for_contract_operations/mod.rs
  • packages/rs-drive/src/drive/document/estimation_costs/estimated_sum_trees_for_value_tree_type.rs
  • packages/rs-drive/src/drive/document/expiration/add_estimation_costs_for_document_expiration/v0/mod.rs
  • packages/rs-drive/src/drive/document/fetch_property_constraint_aggregate/v0/mod.rs
  • packages/rs-drive/src/drive/document/index_level_tree_types.rs
  • packages/rs-drive/src/drive/document/insert/add_document_for_contract/time_range_index_e2e_tests.rs
  • packages/rs-drive/src/drive/document/insert/add_history_operations/mod.rs
  • packages/rs-drive/src/drive/document/insert/add_reference_for_index_level_for_contract_operations/mod.rs
  • packages/rs-drive/src/drive/document/layout.rs
  • packages/rs-drive/src/drive/document/lifecycle/tests.rs
  • packages/rs-drive/src/drive/document/migration/big_sums.rs
  • packages/rs-drive/src/drive/document/migration/big_sums_tests.rs
  • packages/rs-drive/src/drive/document/migration/mod.rs
  • packages/rs-drive/src/drive/document/primary_key_tree_type.rs
  • packages/rs-drive/src/drive/document/query/fetch_document_type_sum/mod.rs
  • packages/rs-drive/src/drive/document/query/fetch_document_type_sum/v0/mod.rs
  • packages/rs-drive/src/drive/document/ranked_index_tree_type.rs
  • packages/rs-drive/src/drive/document/structure.rs
  • packages/rs-drive/src/drive/document/time_range_ttl.rs
  • packages/rs-drive/src/drive/document/update/internal/update_document_for_contract_operations/v2/mod.rs
  • packages/rs-drive/src/drive/group/estimated_costs/for_add_group_action/v0/mod.rs
  • packages/rs-drive/src/drive/group/estimated_costs/for_add_groups/v0/mod.rs
  • packages/rs-drive/src/drive/identity/estimation_costs/for_balances/v0/mod.rs
  • packages/rs-drive/src/drive/prefunded_specialized_balances/estimation_costs/for_prefunded_specialized_balance_update/v0/mod.rs
  • packages/rs-drive/src/drive/prefunded_specialized_balances/estimation_costs/for_prefunded_specialized_balance_update/v1/mod.rs
  • packages/rs-drive/src/drive/shared/shared_estimation_costs/add_estimation_costs_for_contested_document_tree_levels_up_to_contract/v0/mod.rs
  • packages/rs-drive/src/drive/shared/shared_estimation_costs/add_estimation_costs_for_contested_document_tree_levels_up_to_contract_document_type_excluded/v0/mod.rs
  • packages/rs-drive/src/drive/shielded/estimated_costs.rs
  • packages/rs-drive/src/drive/system/estimation_costs/for_total_system_credits_update/v0/mod.rs
  • packages/rs-drive/src/drive/system/estimation_costs/for_total_system_credits_update/v1/mod.rs
  • packages/rs-drive/src/drive/tokens/estimated_costs/for_token_contract_infos/v0/mod.rs
  • packages/rs-drive/src/drive/tokens/estimated_costs/for_token_direct_selling_prices/v0/mod.rs
  • packages/rs-drive/src/drive/tokens/estimated_costs/for_token_identity_infos/v0/mod.rs
  • packages/rs-drive/src/drive/tokens/estimated_costs/for_token_status_infos/v0/mod.rs
  • packages/rs-drive/src/drive/tokens/estimated_costs/for_token_total_supply/v0/mod.rs
  • packages/rs-drive/src/drive/tokens/order_escrow/estimated_costs/v0/mod.rs
  • packages/rs-drive/src/drive/tokens/order_escrow/mod.rs
  • packages/rs-drive/src/drive/tokens/shielded_pool/estimated_costs.rs
  • packages/rs-drive/src/error/proof.rs
  • packages/rs-drive/src/fees/op.rs
  • packages/rs-drive/src/query/drive_document_count_and_sum_query/executors/per_in_value.rs
  • packages/rs-drive/src/query/drive_document_count_and_sum_query/executors/range_no_proof.rs
  • packages/rs-drive/src/query/drive_document_count_and_sum_query/executors/total.rs
  • packages/rs-drive/src/query/drive_document_having_query/execute_range.rs
  • packages/rs-drive/src/query/drive_document_having_query/mod.rs
  • packages/rs-drive/src/query/drive_document_having_query/mode_detection/v0/mod.rs
  • packages/rs-drive/src/query/drive_document_having_query/tests.rs
  • packages/rs-drive/src/query/drive_document_ranked_query/branches.rs
  • packages/rs-drive/src/query/drive_document_ranked_query/execute_top_k.rs
  • packages/rs-drive/src/query/drive_document_ranked_query/mod.rs
  • packages/rs-drive/src/query/drive_document_ranked_query/tests.rs
  • packages/rs-drive/src/query/drive_document_sum_query/execute_point_lookup.rs
  • packages/rs-drive/src/query/drive_document_sum_query/execute_range_sum.rs
  • packages/rs-drive/src/query/drive_document_sum_query/executors/total.rs
  • packages/rs-drive/src/query/mod.rs
  • packages/rs-drive/src/query/sum_width.rs
  • packages/rs-drive/src/structure/kinds.rs
  • packages/rs-drive/src/util/estimated_layers.rs
  • packages/rs-drive/src/util/grove_operations/grove_insert_empty_tree/v0/mod.rs
  • packages/rs-drive/src/verify/document/verify_document_history/tests.rs
  • packages/rs-drive/src/verify/document_having/verify_having_range_proof/v0/mod.rs
  • packages/rs-drive/src/verify/document_ranked/verify_ranked_top_k_proof/v0/mod.rs
  • packages/rs-drive/src/verify/document_sum/verify_aggregate_count_and_sum_proof/v0/mod.rs
  • packages/rs-drive/src/verify/document_sum/verify_aggregate_sum_proof/v0/mod.rs
  • packages/rs-drive/src/verify/document_sum/verify_carrier_aggregate_count_and_sum_proof/v0/mod.rs
  • packages/rs-drive/src/verify/document_sum/verify_carrier_aggregate_sum_proof/v0/mod.rs
  • packages/rs-drive/src/verify/document_sum/verify_distinct_count_and_sum_proof/v0/mod.rs
  • packages/rs-drive/src/verify/document_sum/verify_distinct_sum_proof/v0/mod.rs
  • packages/rs-drive/src/verify/document_sum/verify_point_lookup_count_and_sum_proof/v0/mod.rs
  • packages/rs-drive/src/verify/document_sum/verify_point_lookup_sum_proof/v0/mod.rs
  • packages/rs-drive/src/verify/document_sum/verify_primary_key_count_sum_tree_proof/v0/mod.rs
  • packages/rs-drive/src/verify/document_sum/verify_primary_key_sum_tree_proof/v0/mod.rs
  • packages/rs-drive/tests/deterministic_root_hash.rs
  • packages/rs-drive/tests/query_tests.rs
  • packages/rs-drive/tests/query_tests_history.rs
  • packages/rs-platform-version/src/version/drive_versions/drive_document_method_versions/v5.rs
  • packages/rs-platform-version/src/version/mocks/v2_test.rs
  • packages/rs-platform-version/src/version/system_limits/mod.rs
  • packages/rs-platform-version/src/version/system_limits/v1.rs
  • packages/rs-platform-version/src/version/system_limits/v2.rs
  • packages/rs-platform-version/src/version/system_limits/v3.rs
  • packages/rs-platform-version/src/version/system_limits/v4.rs
  • packages/rs-platform-version/src/version/system_limits/v5.rs
  • packages/rs-sdk-ffi/src/system/queries/path_elements.rs
  • packages/wasm-sdk/src/queries/system.rs
  • packages/wasm-sdk/tests/fixtures/contract-cache/signed-responses.json

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@github-actions github-actions Bot added this to the v5.1.0 milestone Nov 19, 2026
@QuantumExplorer
QuantumExplorer marked this pull request as ready for review November 19, 2026 00:07
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🌳 GroveDB structure

This pull request changes the described GroveDB structure. Open it in the structure viewer: new nodes glow, removed ones stay as ghosts, and the tour walks through each change.

Changed (5 nodes)

  • contracts.contract.documents.document_type.primary_key
  • contracts.contract.documents.document_type.index_property
  • contracts.contract.documents.document_type.index_property.value
  • contracts.contract.documents.document_type.index_property.value.members
  • contracts.contract.documents.document_type.index_property.value.next_property

Compared 083c865a22 with 5acaa40705. Updated at 2026-11-19T06:18:26.120Z

@github-actions

Copy link
Copy Markdown
Contributor

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Nov 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@thepastaclaw

thepastaclaw commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

🔍 Review in progress (commit 5acaa40) · live progress

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Final validation — Phase 1 + Phase 2

PV15’s wider sums address the document-history overflow, but the activation migration can reject valid legacy state or leave storage out of sync with the layout used by writers and readers. The Rust workspace check failed on clippy::items_after_test_module; the wasm32 and JS builds passed, and functional and end-to-end checks were still pending. Four verified non-blocking suggestions were omitted under the 10-finding budget.

🔴 9 blocking | 🟡 1 suggestion(s)

1 finding(s) not shown inline (the lines are not part of this PR's diff)

🟡 Suggestion: Preserve wide path-element sums on the JavaScript object round trip
packages/wasm-sdk/src/queries/system.rs:1117-1137

toObject() emits the full sum as a BigInt, but fromObject() first decodes through platform_value::Value. The pinned serde-wasm-bindgen implementation of deserialize_any rejects BigInts outside i64::MIN..=u64::MAX before the typed i128 field is reached. A path element with a sum of 1n << 64n therefore cannot read back its own object, independently of the document aggregate response limit. Decode the field as a typed i128 and add a round-trip test above u64::MAX; the existing fixture still fits within 64 bits.

source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, rust-quality, security-auditor)

Review provenance

Source: reviewer 1: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); reviewer 7: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 8: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.2-sol (effort low) — The diff changes consensus-visible GroveDB layouts and adds a first-block PV15 migration in packages/rs-drive/src/drive/document/migration/big_sums.rs that must convert existing trees deterministically.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — rust-quality (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-astra — general (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — ffi-engineer (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — platform-versioning (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — security-auditor (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.

In `packages/rs-drive/src/drive/document/migration/big_sums.rs`:
- [BLOCKING] packages/rs-drive/src/drive/document/migration/big_sums.rs:111-124: Isolate migrated user contracts from PV14 cache entries
  The activation walk bypasses the cache to compile the contract at PV15, but it neither marks the contract modified in the block nor seeds the block cache. The earlier cache clear does not prevent a concurrent unproved `getDataContract` from caching the committed PV14 definition. `DataContractCache::get` then lets transactional document validation fall back to that definition by contract ID, while a validator with a cache miss loads the PV15 definition. A write that creates an index group can therefore select a different tree type on the two validators. Isolate the compiled definitions by protocol version or mark and refresh affected contracts through the transactional cache before processing transitions.
- [BLOCKING] packages/rs-drive/src/drive/document/migration/big_sums.rs:224-233: Convert PV13 shared-prefix trees to the demoted layout
  PV13 could create a provable count-and-sum value tree and its `NotCountedOrSummed` continuation in the same batch. PV14 demoted newly created shared-prefix values to `CountSumTree` but left existing values in place. The pinned converter widens the stored variant to `ProvableCountProvableBigSumTree` and revalidates every child; that destination rejects the wrapper, and the error aborts activation. Convert this legacy shape to `CountBigSumTree`, which matches fresh writes and accepts the wrapper. Cover a value written at PV13 and retained through PV14; the existing wrapped-level fixture starts at PV14.
- [BLOCKING] packages/rs-drive/src/drive/document/migration/big_sums.rs:309-313: Keep the stored ranked layout consistent after a refused conversion
  GroveDB refuses to widen a ranked tree containing a key above 239 bytes, which the PV14 sum axis allowed. `LeftAsStored` keeps the parent and its contributors narrow, but only the migration stats retain that decision. Even a later insert with a short key for a new group creates a wide value tree from `IndexLevelTypeInfo::big_sums`; the retained narrow indexed parent rejects that child. Range readers likewise select the wide primitive for the narrow tree. Use a layout that migration, writers, estimators, and verifiers can all resolve, or convert to a representation that supports every legal legacy key. Test an upgrade followed by an insert into a new group and a proved read.
- [BLOCKING] packages/rs-drive/src/drive/document/migration/big_sums.rs:208-217: Bound activation conversion work and memory
  The contract cursor does not bound the inner walk: `insert_all` with no limit materializes an entire level, and the remaining siblings stay live while descendants convert. The pinned GroveDB converter independently loads and rewrites every node of a Merk and collects whole secondary row sets for indexed trees. Valid accumulated state can therefore exceed a validator's memory during the mandatory activation block, and retrying starts the same work again. Page the Drive traversal by exclusive last key, and establish an enforceable resource bound for the GroveDB rewrite and the activation transaction. Paging the Drive query alone does not bound peak memory.

In `packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/v3/mod.rs`:
- [BLOCKING] packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/v3/mod.rs:1768-1775: Prevent contract updates from changing the width of existing sum trees
  With `sizedIntegerTypes` disabled, raising a `documentsSummable` property's maximum from 2^27 to 2^27 + 1 with minimum 0 preserves its `i64` encoding and can pass schema compatibility without changing any index declaration. The parser then flips `big_sums`, which `validate_update_v2` does not check. The PV15 Drive update path delegates existing-type storage work to the insert-if-absent logic: it leaves the primary and existing index roots in place. Range readers then request wide aggregates from narrow trees, and new wide children can fail to contribute to narrow parents. Reject width changes in the versioned document-type update validator unless Drive converts the existing layout atomically.
- [BLOCKING] packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/v3/mod.rs:731-734: Validate ranked group keys against the selected sum axis
  `ranked_level_key_length_limit` allows 247 bytes for a sum ranking without an average axis. Drive now creates a `BigSum` secondary for wide sum rankings, and GroveDB allows only 239 bytes there because its sort prefix is 16 bytes. A new PV15 contract can therefore register a schema-valid 240-byte group key that fails when Drive applies the write. Resolve the ceiling from the physical axis chosen for that level and test the 239/240 boundary for wide and narrow rankings. The rule also needs to account for legacy schemas that permit longer keys but did not contain one at activation.

In `packages/rs-drive/src/drive/document/ranked_index_tree_type.rs`:
- [BLOCKING] packages/rs-drive/src/drive/document/ranked_index_tree_type.rs:89-94: Use the stored BigSum axis for ranked reads and proofs
  Wide ranked indexes maintain `IndexAxis::BigSum`, but the ranked index picker still admits them for `RankedAxis::Sum`, which maps unconditionally to `IndexAxis::Sum`. Top-k execution and proof verification use that mapping, and HAVING also encodes sum bounds as eight-byte sort keys. GroveDB rejects the missing axis even when every result fits in `i64`, so this is not just the documented limit on response width. Resolve the physical axis and bound encoding in shared Drive code, decode `AxisKeys::BigSum` and `AxisEntries::BigSum`, and narrow returned values at the existing response boundary.
- [BLOCKING] packages/rs-drive/src/drive/document/ranked_index_tree_type.rs:159-164: Handle wide indexed parents when draining expired time buckets
  Both new wide indexed variants can occur inside a TTL time bucket, but `time_range_ttl.rs::drain_expired_node` dispatches only the three narrow variants to dedicated delete APIs. A group under a wide indexed parent falls through to `drop_flat_subtree`, which GroveDB rejects because the generic removal cannot update the indexed secondary. Later writes retry that cleanup before applying their own changes. Dispatch both wide variants to their GroveDB indexed-delete APIs and test a write after a populated wide-ranked bucket expires.

In `packages/rs-drive/src/drive/document/primary_key_tree_type.rs`:
- [BLOCKING] packages/rs-drive/src/drive/document/primary_key_tree_type.rs:143-144: Move the primary-key tree helper before the test module
  The `Rust workspace tests / Tests` job (135233119272) fails to compile `drive`'s test target: Clippy reports `error: items after a test module` at line 82 and identifies `primary_key_tree_type_v1` at line 144. This PR extracted that function from the dispatch arm and placed it after `mod tests`. Move it above the test module so the workspace check can run.

In `packages/wasm-sdk/src/queries/system.rs`:
- [SUGGESTION] packages/wasm-sdk/src/queries/system.rs:1117-1137: Preserve wide path-element sums on the JavaScript object round trip
  `toObject()` emits the full sum as a BigInt, but `fromObject()` first decodes through `platform_value::Value`. The pinned `serde-wasm-bindgen` implementation of `deserialize_any` rejects BigInts outside `i64::MIN..=u64::MAX` before the typed `i128` field is reached. A path element with a sum of `1n << 64n` therefore cannot read back its own object, independently of the document aggregate response limit. Decode the field as a typed `i128` and add a round-trip test above `u64::MAX`; the existing fixture still fits within 64 bits.

@github-actions

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Nov 19, 2026
QuantumExplorer and others added 5 commits November 19, 2026 08:56
Clippy refuses an item after a test module (`items_after_test_module`).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…at keeps big sums

A contract whose types keep big sums reads differently at protocol
version 15 than at 14. During the activation block a committed-state
reader, still at 14, can put the earlier reading into the global cache,
and a transactional read falls back to the global cache for a contract
the block has not rewritten. The conversion therefore marks each such
contract as modified in the block and seeds the block cache with this
version's reading (`refresh_data_contract_cache_from_state`), as for a
contract the block rewrites.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…gs to the big sum axis key ceiling

Two registration rules for a type that keeps its sums in 128 bits
(protocol version 15):

- A contract update may not change the width a type keeps its sums in.
  The width follows the bounds of the summed property, which an update
  may widen, and the type's trees were created at the width it had.
  Document type update validation 2, which only protocol version 15
  selects, refuses it (`DocumentTypeUpdateError`).
- A sum ranking of such a type is on the big sum axis, whose 16-byte
  sort key leaves a group key 239 bytes, as the average axis does. The
  shared parser checks every ranked property against the 64-bit
  ceilings before the width is known, so a type that keeps big sums has
  its sum rankings checked again once it is, and a derived index
  property is checked against the declaring type's width.

Both are inert before protocol version 15, when no type keeps big sums.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… 128-bit sum

A group under a ranked tree leaves through the indexed-tree delete of its
parent's type, which keeps the ranking in step. The drain dispatched the
three 64-bit indexed trees only, so a group under a
`ProvableBigSumIndexedTree` or a `ProvableCountProvableBigSumIndexedTree`
fell through to the flat drop, which GroveDB refuses under an indexed
parent. Both now go through their own indexed delete. Such trees exist
only from protocol version 15.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e big sum axis

Ranked top-k reads, HAVING ranges and their proofs mapped a sum ranking
to GroveDB's sum axis, which a summing index of a type that keeps its
sums in 128 bits does not maintain: it ranks on the big sum axis. The
axis is now resolved by `index_axis_for` (a summing index of a type that
keeps big sums ranks on the big sum axis, every other ranking on the
axis of the same name), and the big sum results are presented as the
sum a ranked entry carries when they fit 64 bits. GroveDB's bounded and
top-k queries take the bounds typed, so a HAVING range needs nothing
else.

No type keeps big sums before protocol version 15, so earlier reads walk
the axis they walked.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw left review threads unresolved; resolve them.
Full checklist in the description.

…type's sums

Stored document type generation 0 now holds whether a type keeps its
sums in 128 bits (one byte per type), and an index level's `Debug`
rendering names `big_sums`. Protocol version 15 is unreleased, so the
fixture follows, as its README describes. Every contract with document
types changes: each contract kept whole grows by one byte per type, and
the index structure hashes change for every contract with an index
level that ends an index. The contracts with no document type are
unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them.
Full checklist in the description.

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-review — Final validation — Phase 1 + Phase 2

This head fixes six prior findings, but successfully converted legacy indexes can still reject schema-valid writes, and several wide-sum query paths can omit matches or reject valid proofs and representable results. The Kotlin SDK check passed; Rust workspace and WASM tests, builds, and PR Hygiene were pending at the time of this static review. One additional suggestion to update the PV15 protocol changelog was omitted under the ten-comment limit.

🔴 7 blocking | 🟡 2 suggestion(s)

1 finding(s) not shown inline (the lines are not part of this PR's diff)

🟡 Suggestion: Preserve wide path-element sums on the JavaScript object round trip
packages/wasm-sdk/src/queries/system.rs:1117-1137

toObject() emits the exact sum as a JavaScript BigInt, but fromObject() first decodes the object into platform_value::Value. The pinned serde-wasm-bindgen deserialize_any accepts BigInts only in i64::MIN..=u64::MAX, so a legitimate sum outside that interval fails before the i128 field is decoded. Preserve the BigInt API and bypass the narrow generic conversion for this field. Test the object round trip on both sides of that interval.

source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality); gpt-6.2-astra (phase2-reviewer: general, ffi-engineer, platform-versioning, rust-quality)

Still open from earlier rounds (3)

  • 🔴 Blocking: Convert PV13 shared-prefix trees to the demoted layout — packages/rs-drive/src/drive/document/migration/big_sums.rs:239-248 (thread)
  • 🔴 Blocking: Keep the stored ranked layout consistent after a refused conversion — packages/rs-drive/src/drive/document/migration/big_sums.rs:324-328 (thread)
  • 🔴 Blocking: Bound activation conversion work and memory — packages/rs-drive/src/drive/document/migration/big_sums.rs:223-232 (thread)
Follow-up candidates (optional) (1)

New non-blocking observations on code unchanged since the last full review. No inline threads are opened for them and later reviews do not repeat them: fix forward or track separately if they are worth it.

🟡 Suggestion: Price wide average-ranking rows with their actual zero payload
packages/rs-drive/src/drive/document/cost/writes.rs:119-124

Pinned GroveDB's axis_payload_sum writes a zero payload for Avg on a wide primary, but ranking_row serializes the document's contribution. When that contribution takes more bytes to encode than zero, the new-group storage estimate overstates the bytes GroveDB writes. Pass the primary's width into the row calculation: a wide index can declare Avg without declaring BigSum.

source: gpt-6.2-astra (phase2-reviewer: general)

Review provenance

Source: reviewer 1: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 3: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); reviewer 8: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.2-sol (effort low) — This is a large, intricate change to consensus-critical protocol-version behavior and persisted Drive storage, including a first-block tree migration that changes document sum representation and compatibility.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — rust-quality (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
  • Code unchanged since the last final review (23da6792): 2 new blocker(s) went to an independent confirmation pass (the final verifier's model in a fresh session, without its reasoning): 2 confirmed; 1 new suggestion(s) listed as follow-up candidates, not posted inline
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-astra — general (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — ffi-engineer (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — platform-versioning (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — security-auditor (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.

In `packages/rs-drive/src/drive/document/migration/big_sums.rs`:
- [BLOCKING] packages/rs-drive/src/drive/document/migration/big_sums.rs:183-193: Check the legacy ranked key domain even when conversion succeeds
  GroveDB checks the keys currently stored, so a PV14 `Sum` ranking can convert successfully while empty or while all its keys happen to fit. The trusted contract load skips full registration validation, so a schema that allowed a 240-byte group key still admits that key after conversion. Its first such write then reaches the BigSum secondary, which accepts at most 239 bytes, and fails during application. Choose the migrated layout from the keys the legacy schema permits, or enforce the new limit in document validation before issuing the write. Cover a successfully converted legacy index receiving its first key above the new ceiling.
- [BLOCKING] packages/rs-drive/src/drive/document/migration/big_sums.rs:239-248: Convert PV13 shared-prefix trees to the demoted layout
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4622895983)
- [BLOCKING] packages/rs-drive/src/drive/document/migration/big_sums.rs:324-328: Keep the stored ranked layout consistent after a refused conversion
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4622895993)
- [BLOCKING] packages/rs-drive/src/drive/document/migration/big_sums.rs:223-232: Bound activation conversion work and memory
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4622896029)

In `packages/rs-drive/src/query/drive_document_having_query/execute_range.rs`:
- [BLOCKING] packages/rs-drive/src/query/drive_document_having_query/execute_range.rs:104-119: Preserve open-ended HAVING bounds on the BigSum axis
  Mode detection lowers `HAVING SUM(x) >= 0` to `[0, i64::MAX]`, and `inclusive_bounds_i128` only casts those endpoints. A group totaling `i64::MAX + 1` is therefore excluded even if it belongs on the requested page, where the query should explicitly refuse the unrepresentable result. Proof verification reconstructs the same truncated interval. Preserve open endpoints until the physical axis is known, so an omitted upper bound is distinct from an explicit `<= i64::MAX`, and use the same lowering for reads and proofs.

In `packages/rs-drive/src/verify/document_sum/verify_aggregate_sum_proof/v0/mod.rs`:
- [BLOCKING] packages/rs-drive/src/verify/document_sum/verify_aggregate_sum_proof/v0/mod.rs:27-39: Resolve the proof layout at the signed protocol version
  The SDK selects verifier tables from response metadata but passes the original request through unchanged. `verify_sum_query` then takes the document type from `request.data_contract`, so a contract parsed at PV14 and retained across activation still selects the narrow verifier for a valid PV15 wide-sum proof. GroveDB does not accept the other width's proof, and activation need not change the contract ID or revision. Resolve the compiled layout at the response protocol version before choosing the aggregate verifier or ranked axis, and cover a request that spans activation.

  _Raised on code unchanged since the last review, and confirmed by an independent pass: A contract parsed and retained under PV14 has uses_big_sums() == false; after activation, a proved PV15 range-sum query for that contract supplies a valid big-sum proof, but verify_sum_query rebuilds the query from the stale request contract and verify_aggregate_sum_proof_v0 calls GroveDb::verify_aggregate_sum_query, which rejects the wide proof._

In `packages/rs-drive/src/query/drive_document_sum_query/execute_point_lookup.rs`:
- [BLOCKING] packages/rs-drive/src/query/drive_document_sum_query/execute_point_lookup.rs:56-66: Narrow the requested total, not each intermediate group
  This path returns one total for an `IN` query, but `element_sum` narrows each matched group before the fold. On a migrated signed-property index, group sums of `i64::MAX + 1` and `-1` produce a representable total of `i64::MAX`, yet the first group causes an error. The same early narrowing occurs in count-and-sum totals, compound range folds, and the proof path that decodes branches before combining them. Keep the wide intermediate sums through verification and accumulation, then narrow once for a total response. Split responses should still check each group they return.

  _Raised on code unchanged since the last review, and confirmed by an independent pass: For a PV15 wide-sum type queried with category IN [A,B], where A has a group total of i64::MAX + 1 and B has -1, the requested aggregate is i64::MAX, but execute_point_lookup and the point-proof verifier call element_sum on each group first and reject A before the groups can be combined._

In `packages/wasm-sdk/src/queries/system.rs`:
- [SUGGESTION] packages/wasm-sdk/src/queries/system.rs:1117-1137: Preserve wide path-element sums on the JavaScript object round trip
  `toObject()` emits the exact sum as a JavaScript `BigInt`, but `fromObject()` first decodes the object into `platform_value::Value`. The pinned serde-wasm-bindgen `deserialize_any` accepts BigInts only in `i64::MIN..=u64::MAX`, so a legitimate sum outside that interval fails before the `i128` field is decoded. Preserve the BigInt API and bypass the narrow generic conversion for this field. Test the object round trip on both sides of that interval.

In `packages/rs-drive/src/query/drive_document_ranked_query/branches.rs`:
- [SUGGESTION] packages/rs-drive/src/query/drive_document_ranked_query/branches.rs:217-225: Narrow ranked sums after selecting the final merged page
  Both the branched reader and verifier narrow each branch's candidates before `merge_branch_pages` sorts and truncates them. A bottom-one query with branch minima of `1` and `i64::MAX + 1` therefore fails even though its only output would be `1`. Compare candidates at full width and narrow only the entries selected for the final page.
Out-of-scope follow-up suggestions (1)

These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.

  • Preserve wide path-element sums on the JavaScript object round trip — The broader Number and JSON claims do not apply: the pinned decoder delivers safe integral Numbers through visit_i64, and the JSON API serializes sums as decimal strings. The Phase 2 example i64::MAX + 1 also fits the generic decoder's u64 branch. The kept finding covers the confirmed BigInt failure outside both 64-bit representations.
    • Follow-up: Consider creating a separate issue or author/maintainer-requested PR for this.

…erization

- The order escrow depth test read the proved sums of the token market
  `ask` type with the 64-bit accessor. That type's `remaining` declares
  no bound that keeps a 64-bit sum in range, so from protocol version 15
  its sums are kept in 128 bits: the test reads them at that width.
- The shielded token payment characterization renders the validated
  action with `Debug`, which now prints the sum width of the document
  type and its index levels: it is stripped like the lifecycle flag
  beside it. The `valid-payment` record still moved, by the contract
  fetch cost alone: a stored contract is one byte larger per document
  type. With that byte dropped from the stored form every validation
  record matched its pin. The settled records and the single-entry root
  hold GroveDB roots, which move with the stored contracts, and are
  re-pinned at the latest version.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw left review threads unresolved; resolve them.
Full checklist in the description.

…n check_tx

A compiled document type records the width of its sums, one byte, and a
stored contract's bytes are billed per byte. The DashPay v3 create
stores four more bytes (2,040 credits, 4,080 under the 100% fee
multiplier of the priority test), and the update reads four and stores
five, with the copied-in `preorder` type (2,290 credits). Latest
protocol version only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them.
Full checklist in the description.

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-review — Final validation — Phase 1 + Phase 2

The latest head resolves six prior findings around cache isolation, TTL cleanup, ranked-axis routing, schema validation, and helper placement. It still has activation and wide-sum query correctness issues, including one additional mixed-index width mismatch; three sibling aggregation reports are consolidated into the carried total-narrowing finding. Two lower-priority suggestions are omitted under the ten-finding budget. Kotlin SDK build/tests and PR Hygiene remain in progress, with no failed code checks in the supplied CI snapshot.

🔴 8 blocking | 🟡 2 suggestion(s)

1 finding(s) not shown inline (the lines are not part of this PR's diff)

🟡 Suggestion: Preserve wide path-element sums on the JavaScript object round trip
packages/wasm-sdk/src/queries/system.rs:1117-1137

toObject exposes the exact sum as a JavaScript BigInt, but fromObject first passes the complete object through platform_value_from_object, whose generic BigInt deserializer accepts only the i64/u64 range. A valid sum such as u64::MAX + 1 or a value below i64::MIN fails before the Option<i128> field visitor can decode it. Use an i128-capable field-aware conversion or emit and consume the same decimal-string representation on both sides, and cover both out-of-64-bit directions.

source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality); gpt-6.2-astra (phase2-reviewer: general, ffi-engineer, rust-quality)

Still open from earlier rounds (8)

  • 🟡 Suggestion: Narrow ranked sums after selecting the final merged page — packages/rs-drive/src/query/drive_document_ranked_query/branches.rs:217-225 (thread)
  • 🔴 Blocking: Narrow the requested total, not each intermediate group — packages/rs-drive/src/query/drive_document_sum_query/execute_point_lookup.rs:56-66 (thread)
  • 🔴 Blocking: Resolve the proof layout at the signed protocol version — packages/rs-drive/src/verify/document_sum/verify_aggregate_sum_proof/v0/mod.rs:27-39 (thread)
  • 🔴 Blocking: Preserve open-ended HAVING bounds on the BigSum axis — packages/rs-drive/src/query/drive_document_having_query/execute_range.rs:104-119 (thread)
  • 🔴 Blocking: Check the legacy ranked key domain even when conversion succeeds — packages/rs-drive/src/drive/document/migration/big_sums.rs:183-193 (thread)
  • 🔴 Blocking: Bound activation conversion work and memory — packages/rs-drive/src/drive/document/migration/big_sums.rs:208-217 (thread)
  • 🔴 Blocking: Keep the stored ranked layout consistent after a refused conversion — packages/rs-drive/src/drive/document/migration/big_sums.rs:309-313 (thread)
  • 🔴 Blocking: Convert PV13 shared-prefix trees to the demoted layout — packages/rs-drive/src/drive/document/migration/big_sums.rs:239-248 (thread)
Review provenance

Source: reviewer 1: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 5: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); reviewer 8: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.2-sol (effort low) — This is a large, intricate change that modifies protocol-versioned consensus behavior, persisted GroveDB storage layouts, and a first-block state migration for document sum trees.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — rust-quality (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
  • Code unchanged since the last final review (f9a4d629): 1 new blocker(s) went to an independent confirmation pass (the final verifier's model in a fresh session, without its reasoning): 1 confirmed
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-astra — general (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — ffi-engineer (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — platform-versioning (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — security-auditor (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.

In `packages/wasm-sdk/src/queries/system.rs`:
- [SUGGESTION] packages/wasm-sdk/src/queries/system.rs:1117-1137: Preserve wide path-element sums on the JavaScript object round trip
  `toObject` exposes the exact sum as a JavaScript BigInt, but `fromObject` first passes the complete object through `platform_value_from_object`, whose generic BigInt deserializer accepts only the i64/u64 range. A valid sum such as `u64::MAX + 1` or a value below `i64::MIN` fails before the `Option<i128>` field visitor can decode it. Use an i128-capable field-aware conversion or emit and consume the same decimal-string representation on both sides, and cover both out-of-64-bit directions.

In `packages/rs-drive/src/query/drive_document_sum_query/execute_range_sum.rs`:
- [BLOCKING] packages/rs-drive/src/query/drive_document_sum_query/execute_range_sum.rs:47-51: Select range-sum width from the index when counting counter-backed groups
  `DriveDocumentCountQuery::counter_sums_query` reuses this sum reader for a `summableOffCountIndex`, whose counter sums remain 64-bit even when the document type has a separate wide property-summing index. This code chooses `query_aggregate_big_sum` solely from `document_type.uses_big_sums()`, so a range count over the physically narrow counter index can be sent to the BigSum GroveDB primitive and fail with a tree-width mismatch. Select the width from the resolved index/layout, as `index_axis_for` does for ranked reads, and apply the same correction to the corresponding aggregate and carrier proof verifiers.

  _Raised on code unchanged since the last review, and confirmed by an independent pass: At protocol version 15, an index-only document type with an unbounded source `summable` property gets `document_type.uses_big_sums() == true`, while its `summableOffCountIndex` has no `summable` property and its counter trees remain 64-bit (`big_sums == false`). A range count over that counter index routes through `counter_sums_query`, and `read_aggregate_sum` then calls `query_aggregate_big_sum` against the narrow counter tree, causing a GroveDB tree-width mismatch instead of returning the document count; the aggregate and carrier proof verifiers make the same incorrect selection._

In `packages/rs-drive/src/query/drive_document_ranked_query/branches.rs`:
- [SUGGESTION] packages/rs-drive/src/query/drive_document_ranked_query/branches.rs:217-225: Narrow ranked sums after selecting the final merged page
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4623748807)

In `packages/rs-drive/src/query/drive_document_sum_query/execute_point_lookup.rs`:
- [BLOCKING] packages/rs-drive/src/query/drive_document_sum_query/execute_point_lookup.rs:56-66: Narrow the requested total, not each intermediate group
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4623748800)

In `packages/rs-drive/src/verify/document_sum/verify_aggregate_sum_proof/v0/mod.rs`:
- [BLOCKING] packages/rs-drive/src/verify/document_sum/verify_aggregate_sum_proof/v0/mod.rs:27-39: Resolve the proof layout at the signed protocol version
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4623748794)

In `packages/rs-drive/src/query/drive_document_having_query/execute_range.rs`:
- [BLOCKING] packages/rs-drive/src/query/drive_document_having_query/execute_range.rs:104-119: Preserve open-ended HAVING bounds on the BigSum axis
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4623748784)

In `packages/rs-drive/src/drive/document/migration/big_sums.rs`:
- [BLOCKING] packages/rs-drive/src/drive/document/migration/big_sums.rs:183-193: Check the legacy ranked key domain even when conversion succeeds
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4623748776)
- [BLOCKING] packages/rs-drive/src/drive/document/migration/big_sums.rs:208-217: Bound activation conversion work and memory
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4622896029)
- [BLOCKING] packages/rs-drive/src/drive/document/migration/big_sums.rs:309-313: Keep the stored ranked layout consistent after a refused conversion
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4622895993)
- [BLOCKING] packages/rs-drive/src/drive/document/migration/big_sums.rs:239-248: Convert PV13 shared-prefix trees to the demoted layout
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4622895983)

…stored width of a type's sums

The contract proofs in the vectors carry the contract as stored at the
latest protocol version, which now records one byte per document type for
the width of its sums. Regenerated with
generate_wasm_contract_cache_vectors (two identical runs); each contract
proof is one byte longer and the roots and signatures follow.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw left review threads unresolved; resolve them.
Full checklist in the description.

A HAVING sum bound is resolved to the 64-bit range a sum bound carries, so
`SUM(x) >= 0` became `[0, i64::MAX]`, and on the big sum axis of a type
that keeps its sums in 128 bits a group past `i64::MAX` was left out of
the page instead of reached. `DriveDocumentHavingQuery::index_axis_and_bounds`
now gives the reader and the verifier the axis and its bounds, with a
bound at the edge of 64 bits read as open on the big sum axis, so such a
group is refused where a page would return it.

Also notes why the range sum reader takes the type's width for the
counters of a `summableOffCountIndex` index.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them.
Full checklist in the description.

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-review — Final validation — Phase 2 only (queue backlog)

The latest HAVING change fixes the missing open-ended range, but it also widens explicit endpoints and can reject a page whose matching results all fit in 64 bits. Static review also confirmed that the document-create quote overprices wide average-ranking rows; one lower-priority suggestion about reusing GroveDB’s tree-type mapping is omitted under the comment budget. The Kotlin SDK build-and-test check was pending, and no failed code checks were reported for this head.

🔴 7 blocking | 🟡 2 suggestion(s)

1 finding(s) not shown inline (the lines are not part of this PR's diff)

🟡 Suggestion: Preserve wide path-element sums on the JavaScript object round trip
packages/wasm-sdk/src/queries/system.rs:1135-1137

toObject() emits the exact sum as a JS BigInt, but fromObject() goes through platform_value_from_object. The pinned serde-wasm-bindgen deserialize_any tries only i64 and u64, so a value such as 2^64 is rejected before the field's i128 visitor runs. Use a lossless typed decode for the sum and test fromObject(toObject(element)) above u64::MAX and below i64::MIN.

source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, rust-quality)

Still open from earlier rounds (7)

  • 🔴 Blocking: Convert PV13 shared-prefix trees to the demoted layout — packages/rs-drive/src/drive/document/migration/big_sums.rs:239-249 (thread)
  • 🔴 Blocking: Keep the stored ranked layout consistent after a refused conversion — packages/rs-drive/src/drive/document/migration/big_sums.rs:324-328 (thread)
  • 🔴 Blocking: Check the legacy ranked key domain even when conversion succeeds — packages/rs-drive/src/drive/document/migration/big_sums.rs:183-193 (thread)
  • 🔴 Blocking: Bound activation conversion work and memory — packages/rs-drive/src/drive/document/migration/big_sums.rs:223-232 (thread)
  • 🔴 Blocking: Resolve the proof layout at the signed protocol version — packages/rs-drive/src/verify/document_sum/verify_aggregate_sum_proof/v0/mod.rs:27-39 (thread)
  • 🔴 Blocking: Narrow the requested total, not each intermediate group — packages/rs-drive/src/query/drive_document_sum_query/execute_point_lookup.rs:56-66 (thread)
  • 🟡 Suggestion: Narrow ranked sums after selecting the final merged page — packages/rs-drive/src/query/drive_document_ranked_query/branches.rs:217-225 (thread)
Follow-up candidates (optional) (1)

New non-blocking observations on code unchanged since the last full review. No inline threads are opened for them and later reviews do not repeat them: fix forward or track separately if they are worth it.

🟡 Suggestion: Price wide average-ranking rows with their stored zero payload
packages/rs-drive/src/drive/document/cost/writes.rs:119-129

GroveDB's axis_payload_sum writes zero for Avg on a wide primary even when the group's sum fits in i64. Drive's quote instead sizes an Avg reference carrying the document's sum, so it reports extra storage bytes for a new group whose sum requires a multibyte encoding. Pass the primary width into row pricing and compare the quote with an actual wide Avg insert. The presence of a BigSum secondary is not a width test: an Avg-only ranking can have a wide primary.

source: gpt-6.2-astra (phase2-reviewer: general)

Review provenance

Source: reviewer 1: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.2-sol (effort low) — This is a large, intricate change that alters protocol-versioned consensus behavior and performs a persisted GroveDB storage migration for document sum trees, notably in rs-drive migration and protocol-upgrade code.
  • Phase 1 reviewers: not run (skipped for throughput: 16 PRs queued, above the 10 limit)
  • Code unchanged since the last final review (fa5a9913): 1 new suggestion(s) listed as follow-up candidates, not posted inline
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-astra — general (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — ffi-engineer (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — platform-versioning (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — security-auditor (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.

In `packages/rs-drive/src/query/drive_document_having_query/mod.rs`:
- [BLOCKING] packages/rs-drive/src/query/drive_document_having_query/mod.rs:357-367: Distinguish explicit HAVING endpoints from unbounded endpoints
  `bounds_for_operator` normalizes `HAVING SUM(x) = i64::MAX` to `[MAX, MAX]`, and this helper changes it to `[MAX, i128::MAX]` on BigSum. If the only group sums to `MAX + 1`, the result should be an empty page; the reader and verifier instead select that nonmatching group and fail to narrow it. Equality at `MIN` and finite `BETWEEN` endpoints have the same problem. Preserve whether each endpoint is unbounded during operator translation and expand only unbounded ends.

In `packages/wasm-sdk/src/queries/system.rs`:
- [SUGGESTION] packages/wasm-sdk/src/queries/system.rs:1135-1137: Preserve wide path-element sums on the JavaScript object round trip
  `toObject()` emits the exact sum as a JS `BigInt`, but `fromObject()` goes through `platform_value_from_object`. The pinned serde-wasm-bindgen `deserialize_any` tries only `i64` and `u64`, so a value such as `2^64` is rejected before the field's `i128` visitor runs. Use a lossless typed decode for the sum and test `fromObject(toObject(element))` above `u64::MAX` and below `i64::MIN`.

In `packages/rs-drive/src/drive/document/migration/big_sums.rs`:
- [BLOCKING] packages/rs-drive/src/drive/document/migration/big_sums.rs:239-249: Convert PV13 shared-prefix trees to the demoted layout
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4622895983)
- [BLOCKING] packages/rs-drive/src/drive/document/migration/big_sums.rs:324-328: Keep the stored ranked layout consistent after a refused conversion
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4622895993)
- [BLOCKING] packages/rs-drive/src/drive/document/migration/big_sums.rs:183-193: Check the legacy ranked key domain even when conversion succeeds
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4623748776)
- [BLOCKING] packages/rs-drive/src/drive/document/migration/big_sums.rs:223-232: Bound activation conversion work and memory
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4622896029)

In `packages/rs-drive/src/verify/document_sum/verify_aggregate_sum_proof/v0/mod.rs`:
- [BLOCKING] packages/rs-drive/src/verify/document_sum/verify_aggregate_sum_proof/v0/mod.rs:27-39: Resolve the proof layout at the signed protocol version
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4623748794)

In `packages/rs-drive/src/query/drive_document_sum_query/execute_point_lookup.rs`:
- [BLOCKING] packages/rs-drive/src/query/drive_document_sum_query/execute_point_lookup.rs:56-66: Narrow the requested total, not each intermediate group
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4623748800)

In `packages/rs-drive/src/query/drive_document_ranked_query/branches.rs`:
- [SUGGESTION] packages/rs-drive/src/query/drive_document_ranked_query/branches.rs:217-225: Narrow ranked sums after selecting the final merged page
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4623748807)

…axis

Reading a sum bound at the edge of 64 bits as open on the big sum axis
also widened a bound the clause states, so `HAVING SUM(x) = i64::MAX`
reached a group past it and refused the page instead of returning the
groups that match. The open ends are now kept apart from the stated ones:
`AxisRangeBounds::Sum` carries `i128` bounds, a stated bound within `i64`
and an open end at the 128-bit extreme. A read of 64-bit sums takes an
open end at their edge, so every read before protocol version 15 is
unchanged; the big sum axis keeps it open.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw left review threads unresolved; resolve them.
Full checklist in the description.

… without a sum

GroveDB writes a ranking row with no sum whenever the ranked tree's
entries hold 128-bit sums (`axis_payload_sum`), on the Avg axis as well as
the big sum one. The document create quote priced an Avg row of such a
tree with the document's sum, so it quoted more bytes than Drive charges.
`ranking_row` now takes whether the ranked tree keeps 128-bit sums, read
from the tree's type rather than from the axes it ranks on, since an
Avg-only ranking has no big sum axis.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them.
Full checklist in the description.

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-review — Final validation — Phase 1 + Phase 2

Request changes. The PV15 migration still has consensus-critical activation failures for valid legacy layouts, and the retained narrow-layout path is not represented in subsequent reads and writes. The proof and total-query paths also reject or misclassify valid wide results; CI workspace tests were skipped after runner selection failed, while Docker, wasm32, JS, and Swift checks remained pending or in progress. Two additional lower-priority suggestions were omitted due to the ten-finding budget.

🔴 8 blocking | 🟡 2 suggestion(s)

2 finding(s) not shown inline (the lines are not part of this PR's diff)

🔴 Blocking: Isolate migrated user contracts from PV14 cache entries
packages/rs-drive/src/cache/data_contract.rs:110-130

The activation refresh now protects transactional reads, but the cache generation is not keyed by protocol version. A query can select PV14 before activation and reach get_contract_with_fetch_info_and_add_to_operations_v0 after promotion; that method samples the current generation and can then insert a PV14-parsed copy into the global cache because the generation matches. The contract-version guard does not distinguish protocol interpretations of the same stored contract bytes. Key materializations by protocol version, or bind cache publication to the version selected by the caller, so a stale in-flight query cannot repopulate a narrow layout after PV15 activation.

source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality); gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, rust-quality, security-auditor, tenderdash-consensus-security)

🟡 Suggestion: Preserve wide path-element sums on the JavaScript object round trip
packages/wasm-sdk/src/queries/system.rs:1135-1137

toObject() emits the exact sum as a JavaScript BigInt, but fromObject() first converts the complete object through the generic platform_value decoder. At the pinned serializer revision, that decoder accepts BigInts only when they fit i64 or u64, so a valid sum such as 1n << 64n fails before the field's i128 deserializer can run. Use a lossless typed conversion for this field and cover values beyond both 64-bit ranges in the object round-trip tests.

source: muse-spark-1.3-contributor (phase1-reviewer: rust-quality); gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, rust-quality, tenderdash-consensus-security)

Still open from earlier rounds (7)

  • 🔴 Blocking: Convert PV13 shared-prefix trees to the demoted layout — packages/rs-drive/src/drive/document/migration/big_sums.rs:239-248 (thread)
  • 🔴 Blocking: Keep the stored ranked layout consistent after a refused conversion — packages/rs-drive/src/drive/document/migration/big_sums.rs:324-328 (thread)
  • 🔴 Blocking: Check the legacy ranked key domain even when conversion succeeds — packages/rs-drive/src/drive/document/migration/big_sums.rs:183-193 (thread)
  • 🔴 Blocking: Bound activation conversion work and memory — packages/rs-drive/src/drive/document/migration/big_sums.rs:223-232 (thread)
  • 🔴 Blocking: Resolve the proof layout at the signed protocol version — packages/rs-drive/src/verify/document_sum/verify_aggregate_sum_proof/v0/mod.rs:27-39 (thread)
  • 🔴 Blocking: Narrow the requested total, not each intermediate group — packages/rs-drive/src/query/drive_document_sum_query/execute_point_lookup.rs:56-66 (thread)
  • 🟡 Suggestion: Narrow ranked sums after selecting the final merged page — packages/rs-drive/src/query/drive_document_ranked_query/branches.rs:217-225 (thread)
Review provenance

Source: reviewer 1: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); reviewer 8: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 9: gpt-6.2-astra (agent: phase2-reviewer, role: tenderdash-consensus-security); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.2-sol (effort low) — The diff adds an intricate persisted-tree migration in packages/rs-drive/src/drive/document/migration/big_sums.rs and wires it into the first-block protocol-upgrade path, changing consensus state at PV15.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — rust-quality (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
  • Code unchanged since the last final review (4ada191f): 1 new blocker(s) went to an independent confirmation pass (the final verifier's model in a fresh session, without its reasoning): 1 confirmed
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-astra — general (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — ffi-engineer (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — platform-versioning (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — security-auditor (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — tenderdash-consensus-security (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.

In `packages/rs-drive/src/verify/document_sum/verify_aggregate_sum_proof/v0/mod.rs`:
- [BLOCKING] packages/rs-drive/src/verify/document_sum/verify_aggregate_sum_proof/v0/mod.rs:33-39: Authenticate a wide result before classifying it as unrepresentable
  For a valid wide proof, `sum_in_64_bits(sum)?` returns before the outer verifier calls `verify_tenderdash_proof`. The response therefore becomes a generic proof failure rather than an authenticated `UnusableVerifiedResult`; the SDK may retry and attribute the failure to an honest responder even though every honest node returns the same wide sum. Preserve the wide sum and reconstructed root through Tenderdash signature verification, then report the result-width limitation at the public-result boundary. Do not merely remap the current early error, because unauthenticated metadata must not be accepted as `UnusableVerifiedResult`.

  _Raised on code unchanged since the last review, and confirmed by an independent pass: For protocol 15, a valid aggregate proof over a big-sum document type whose total exceeds i64::MAX or is below i64::MIN reaches `verify_aggregate_big_sum_query`, then `sum_in_64_bits(sum)?` returns before the outer verifier calls `verify_tenderdash_proof`. The SDK therefore receives a generic proof/drive failure instead of `UnusableVerifiedResult`, retries or may penalize honest nodes, and cannot report the deterministic result-width limitation to the caller._
- [BLOCKING] packages/rs-drive/src/verify/document_sum/verify_aggregate_sum_proof/v0/mod.rs:27-39: Resolve the proof layout at the signed protocol version
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4623748794)

In `packages/rs-drive/src/cache/data_contract.rs`:
- [BLOCKING] packages/rs-drive/src/cache/data_contract.rs:110-130: Isolate migrated user contracts from PV14 cache entries
  The activation refresh now protects transactional reads, but the cache generation is not keyed by protocol version. A query can select PV14 before activation and reach `get_contract_with_fetch_info_and_add_to_operations_v0` after promotion; that method samples the current generation and can then insert a PV14-parsed copy into the global cache because the generation matches. The contract-version guard does not distinguish protocol interpretations of the same stored contract bytes. Key materializations by protocol version, or bind cache publication to the version selected by the caller, so a stale in-flight query cannot repopulate a narrow layout after PV15 activation.

In `packages/wasm-sdk/src/queries/system.rs`:
- [SUGGESTION] packages/wasm-sdk/src/queries/system.rs:1135-1137: Preserve wide path-element sums on the JavaScript object round trip
  `toObject()` emits the exact sum as a JavaScript `BigInt`, but `fromObject()` first converts the complete object through the generic `platform_value` decoder. At the pinned serializer revision, that decoder accepts BigInts only when they fit `i64` or `u64`, so a valid sum such as `1n << 64n` fails before the field's `i128` deserializer can run. Use a lossless typed conversion for this field and cover values beyond both 64-bit ranges in the object round-trip tests.

In `packages/rs-drive/src/drive/document/migration/big_sums.rs`:
- [BLOCKING] packages/rs-drive/src/drive/document/migration/big_sums.rs:239-248: Convert PV13 shared-prefix trees to the demoted layout
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4622895983)
- [BLOCKING] packages/rs-drive/src/drive/document/migration/big_sums.rs:324-328: Keep the stored ranked layout consistent after a refused conversion
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4622895993)
- [BLOCKING] packages/rs-drive/src/drive/document/migration/big_sums.rs:183-193: Check the legacy ranked key domain even when conversion succeeds
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4623748776)
- [BLOCKING] packages/rs-drive/src/drive/document/migration/big_sums.rs:223-232: Bound activation conversion work and memory
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4622896029)

In `packages/rs-drive/src/query/drive_document_sum_query/execute_point_lookup.rs`:
- [BLOCKING] packages/rs-drive/src/query/drive_document_sum_query/execute_point_lookup.rs:56-66: Narrow the requested total, not each intermediate group
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4623748800)

In `packages/rs-drive/src/query/drive_document_ranked_query/branches.rs`:
- [SUGGESTION] packages/rs-drive/src/query/drive_document_ranked_query/branches.rs:217-225: Narrow ranked sums after selecting the final merged page
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4623748807)

…ore refusing it

A Drive verifier refused a proved sum past the 64 bits a sum result
carries before the client checked the signature over the root, so the
SDK took the refusal for a proof the node got wrong: it retried another
node and could ban honest nodes, which all prove the same sum.

The sum, ranked and having verifiers now refuse such a sum with the root
their proof reconstructs (`ProofError::SumPastResultWidth`, code 6016).
The client wrappers verify the signature over that root first
(`MapProvedSumError`) and then report `UnusableVerifiedResult`, which the
SDK treats as the request's to change; a root the signature does not
authenticate stays the node's failure. Only the 128-bit trees of
protocol version 15 hold such a sum, so every earlier answer verifies
as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix.
Full checklist in the description.

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-review — Final validation — Phase 2 only (queue backlog)

The current head still contains four blocking activation or query correctness issues: point-lookup aggregation narrows intermediate values, activation work is unbounded, refused ranked-tree conversions leave incompatible layouts, and PV13 continuation layouts are not migrated to the PV15 shape. The branched ranked path and WASM object round trip also narrow wide values before the required final selection or conversion. No code check is failing in the supplied CI snapshot; the PastaClaw review and PR Hygiene checks remain pending.

🔴 4 blocking | 🟡 2 suggestion(s)

1 finding(s) not shown inline (the lines are not part of this PR's diff)

🟡 Suggestion: Preserve wide path-element sums on the JavaScript object round trip
packages/wasm-sdk/src/queries/system.rs:1117-1137

to_object writes sum as a JavaScript BigInt, but from_object first routes the object through platform_value_from_object, whose serde_wasm_bindgen intermediate deserializer represents JavaScript BigInts only as i64 or u64. Consequently, a valid i128 sum below i64::MIN or above u64::MAX cannot round-trip through toObject() and fromObject(), even though the field's custom serializer supports the full i128 range when deserializing the target type directly. Deserialize the object directly into PathElementWasm or otherwise use a conversion path that preserves the full BigInt range, and add a round-trip test for both signed extremes.

source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer)

Still open from earlier rounds (5)

  • 🟡 Suggestion: Narrow ranked sums after selecting the final merged page — packages/rs-drive/src/query/drive_document_ranked_query/branches.rs:219-227 (thread)
  • 🔴 Blocking: Narrow the requested total, not each intermediate group — packages/rs-drive/src/query/drive_document_sum_query/execute_point_lookup.rs:56-74 (thread)
  • 🔴 Blocking: Bound activation conversion work and memory — packages/rs-drive/src/drive/document/migration/big_sums.rs:223-232 (thread)
  • 🔴 Blocking: Keep the stored ranked layout consistent after a refused conversion — packages/rs-drive/src/drive/document/migration/big_sums.rs:324-328 (thread)
  • 🔴 Blocking: Convert PV13 shared-prefix trees to the demoted layout — packages/rs-drive/src/drive/document/migration/big_sums.rs:239-249 (thread)
Review provenance

Source: reviewer 1: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.2-sol (effort low) — This is a large, intricate change that modifies protocol-versioned consensus behavior and performs persisted GroveDB tree storage migrations for document sums.
  • Phase 1 reviewers: not run (skipped for throughput: 16 PRs queued, above the 10 limit)
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-astra — general (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — ffi-engineer (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — platform-versioning (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — security-auditor (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.

In `packages/wasm-sdk/src/queries/system.rs`:
- [SUGGESTION] packages/wasm-sdk/src/queries/system.rs:1117-1137: Preserve wide path-element sums on the JavaScript object round trip
  `to_object` writes `sum` as a JavaScript BigInt, but `from_object` first routes the object through `platform_value_from_object`, whose `serde_wasm_bindgen` intermediate deserializer represents JavaScript BigInts only as `i64` or `u64`. Consequently, a valid `i128` sum below `i64::MIN` or above `u64::MAX` cannot round-trip through `toObject()` and `fromObject()`, even though the field's custom serializer supports the full `i128` range when deserializing the target type directly. Deserialize the object directly into `PathElementWasm` or otherwise use a conversion path that preserves the full BigInt range, and add a round-trip test for both signed extremes.

In `packages/rs-drive/src/query/drive_document_ranked_query/branches.rs`:
- [SUGGESTION] packages/rs-drive/src/query/drive_document_ranked_query/branches.rs:219-227: Narrow ranked sums after selecting the final merged page
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4623748807)

In `packages/rs-drive/src/query/drive_document_sum_query/execute_point_lookup.rs`:
- [BLOCKING] packages/rs-drive/src/query/drive_document_sum_query/execute_point_lookup.rs:56-74: Narrow the requested total, not each intermediate group
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4623748800)

In `packages/rs-drive/src/drive/document/migration/big_sums.rs`:
- [BLOCKING] packages/rs-drive/src/drive/document/migration/big_sums.rs:223-232: Bound activation conversion work and memory
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4622896029)
- [BLOCKING] packages/rs-drive/src/drive/document/migration/big_sums.rs:324-328: Keep the stored ranked layout consistent after a refused conversion
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4622895993)
- [BLOCKING] packages/rs-drive/src/drive/document/migration/big_sums.rs:239-249: Convert PV13 shared-prefix trees to the demoted layout
  (carried; thread: https://github.com/dashpay/platform/pull/5987#discussion_r4622895983)

@QuantumExplorer

Copy link
Copy Markdown
Member Author

/self-reviewed

@QuantumExplorer
QuantumExplorer merged commit 0c6035b into v5.1-dev Nov 19, 2026
78 of 82 checks passed
@QuantumExplorer
QuantumExplorer deleted the feat/wide-document-sums branch November 19, 2026 07:52
@github-actions github-actions Bot removed the waiting-self-review Waiting for the author to post /self-reviewed label Nov 19, 2026
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