Skip to content

Composite ordered timeline proof rejects valid page with "more data than limit" #4728

Closed

Description

@PastaPastaPasta

Expected Behavior

A valid documents.composite query should return at most the requested page limit and verify successfully when the page query is an explicitly ordered/range-based document query and a sub-query is bound to the page documents.

This shape is required for a feed: select the newest 20 posts from a declared [language, $createdAt] index, then run a bounded count lookup for each returned post. The composite API should support this because the page limit applies to the page result, while a bound sub-query is evaluated from that page. Internal index/proof look-ahead rows must not make an otherwise valid page proof unverifiable.

Current Behavior

On Platform 4.2.0-dev.9, the trusted/proof-verifying SDK rejects the composite proof with:

[WASM] grovedb: invalid proof: Invalid V1 proof verification parameters:
invalid proof error Proof returns more data than limit Some(20)

The failure is specific to combining an explicit ordered timeline page with a derived sub-query. It reproduces with one count sub-query, so it is independent of the number of enrichments.

The equivalent ordinary documents.query succeeds, and a composite query with the exact returned IDs ($id in [...]) succeeds with the same count sub-query. The failure reproduces against all five Moutai devnet DAPI seeds, which rules out a single unhealthy node and malformed application data.

Steps to Reproduce

The following is the minimal query shape used by Yappr against the freshly reset Moutai devnet. Replace DAPI_URL with each of the five URLs below.

import { EvoSDK } from '@dashevo/evo-sdk';

const DAPI_URL = 'https://seed-1.moutai.networks.dash.org:1443';
const YAPPR_CONTRACT_ID = '6WNGgXQC6jsJDJovUBWAABoQ3ujLnoQBbdYpo6F7649c';

const sdk = EvoSDK.create({
  network: 'devnet',
  dapiAddress: DAPI_URL,
  // Use the normal trusted/proof-verifying SDK path.
});
await sdk.connect();

const query = {
  dataContractId: YAPPR_CONTRACT_ID,
  documentType: 'post',
  where: [
    ['language', '==', 'en'],
    ['$createdAt', '>', 0],
  ],
  orderBy: [
    ['language', 'asc'],
    ['$createdAt', 'desc'],
  ],
  limit: 20,
  subQueries: [
    {
      documentType: 'like',
      kind: 'counts',
      bind: {
        source: 'page',
        sourceProperty: '$id',
        field: 'postId',
      },
    },
  ],
};

await sdk.documents.composite(query);
// Fails with: Proof returns more data than limit Some(20)

The same page selection succeeds without the composite sub-query:

await sdk.documents.query({
  dataContractId: YAPPR_CONTRACT_ID,
  documentType: 'post',
  where: [['language', '==', 'en'], ['$createdAt', '>', 0]],
  orderBy: [['language', 'asc'], ['$createdAt', 'desc']],
  limit: 20,
});

To isolate the composite merge from the ordered range page, first take the 20 IDs from that successful query and issue:

await sdk.documents.composite({
  dataContractId: YAPPR_CONTRACT_ID,
  documentType: 'post',
  where: [['$id', 'in', idsFromTheSuccessfulQuery]],
  limit: 20,
  subQueries: [{
    documentType: 'like',
    kind: 'counts',
    bind: { source: 'page', sourceProperty: '$id', field: 'postId' },
  }],
});
// Succeeds and returns 20 page documents plus the bound counts result.

Observed DAPI endpoints:

  • https://seed-1.moutai.networks.dash.org:1443
  • https://seed-2.moutai.networks.dash.org:1443
  • https://seed-3.moutai.networks.dash.org:1443
  • https://seed-4.moutai.networks.dash.org:1443
  • https://seed-5.moutai.networks.dash.org:1443

Why the query is valid

  • post has a declared languageTimeline index ordered by language and $createdAt; the equality predicate fixes language to en, and the explicit order is the index's natural order.
  • limit: 20 requests one page of 20 post documents. Returning an internal look-ahead row in a proof is an implementation detail; it must not cause verification to reject the proof as if the client requested more than 20 page documents.
  • The count sub-query is page-bound (source: 'page', $id → like.postId) and does not alter the page selection or request an unbounded page.
  • The same predicates and limit verify through ordinary documents.query, and the same sub-query verifies when the page is selected by exact IDs.
  • This is the first dev.9 release carrying documents.composite; the query is the intended use case for merged page/enrichment proofs.

Likely Area

The failure appears in the Platform Drive/GroveDB merged-proof path for an ordered/range page query. Platform composite end-to-end coverage currently exercises unordered pages and by-ID pages, but not an explicitly ordered timeline page with a bound derived query. A regression test should cover the shape above and assert that the page contains no more than 20 documents and verifies successfully.

Temporary Client Impact

Yappr has temporarily selected the page with ordinary documents.query, then passed those exact IDs to the by-ID composite path. This preserves verified composite enrichment and pagination, but it is a client-side mitigation for the ordered-page proof failure. The underlying composite ordered-page path should be fixed so clients can use one merged proof for the complete feed page.

Environment

Investigation / likely fix location

The dev.9 release commit is Platform d02e988851 and pins GroveDB 6816457d2b2df98653f286bf9a374f236a17748f.

The official composite-query documentation explicitly presents this supported shape: an ordered page with limit: 20, a bound count sub-query, and range-based pagination for the next page. Yappr is using that documented contract with the languageTimeline index.

The request is passed through the SDK and lowered by Platform Drive. In packages/rs-drive/src/query/composite_document_query/mod.rs, page_path_query() deliberately retains the limit for non-by-ID pages, and execute_composite_with_proof_internal() calls GroveDb::prove_query_many() over the page and derived sub-query path queries. This is the intended one-proof implementation; the JS/WASM SDK is not inventing an extra row or changing the result set.

The exact error is emitted by GroveDB's Merk verifier (merk/src/proofs/query/verify.rs) when execute_proof sees another matching result after the inherited limit has been exhausted. GroveDB's V1 merge code (grovedb/src/query/merge/v1.rs) lifts the page's global limit into a per-instance branch cap while combining the page branch with sub-query branches. The existing merge tests cover key-level limited grafts and by-ID/unordered composite shapes, but not an ordered secondary-index range page with a bound count.

My assessment is:

  1. Not an SDK bug. The SDK serializes the documented query and reports the proof-verification failure returned by WASM. SDK-side behavior can provide a client fallback, but cannot make this proof valid.
  2. Primary fix: GroveDB merged-query/proof limit accounting. The generator and verifier must agree on which rows consume the page branch's limit when an ordered/range branch is merged with derived sub-query branches. A proof-boundary/look-ahead row must not be treated as an additional returned page row, or the branch limit must be propagated so the generated proof and verifier use the same budget.
  3. Platform Drive should add the regression test and, if needed, a shape guard. The composite Drive test suite should exercise the exact ordered languageTimeline + bound count shape against prove_query_many and the authoritative verifier. If GroveDB cannot support this documented shape, Drive must reject it explicitly rather than emit a proof that every trusted client rejects; the preferred fix is to make the lower layer support the documented API.

This points to GroveDB's merge/proof accounting as the root fix, with Platform Drive owning the end-to-end regression test. The WASM/JS SDK should only receive a new release after the lower-layer test passes.

Activity

  1. added
    bug
    on Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugrs-sdk

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions