feat(indexer): shielded-flow classification, non-attribution and note discovery without actor linkage #1585

Open
opened 2026-10-29 00:33:27 +00:00 by PlasticDigits · 0 comments
Owner

Problem and scope

Make the indexer and its public API honest and non-attributing for shielded activity, and give shielded clients a way to discover their notes without handing the indexer a user key or wallet address.

The indexer must:

  1. classify pool-originated swaps and deposits correctly (shielded vs ordinary) from trusted on-chain evidence;
  2. include shielded swaps in economic aggregates (pair volume/candles, protocol volume/fees, TVL, DeFiLlama/GT/CG/CMC surfaces) so totals do not undercount;
  3. exclude shielded flows from social/attribution surfaces (/api/v1/traders/{addr}, leaderboard, positions/P&L, trader CSV) and never invent a note owner;
  4. serve note discovery in a form that does not let the API become a per-wallet or per-key balance oracle;
  5. guarantee that no note opening, note key, private key, wallet address from a shielded request, or user conversation is persisted, logged, exported or documented.

This issue does not implement the pool (#1583), the swap (#1584), the dApp (#1586) or the security/abuse program (#1587). It depends on the emitted event shapes defined by #1583/#1584 and must be implemented against a final event schema, not a guess.

Current codebase and investigation

Reviewed checkout: 38c154958.

  • indexer/migrations/20260310000001_initial_schema.sql creates swap_events with sender VARCHAR(64) NOT NULL, receiver VARCHAR(64), tx_hash, offer_amount, return_amount, and idx_swaps_sender (sender, block_timestamp DESC). swap_events.sender is the DEX-visible counterparty (the pair's CW20 sender: a wallet for a direct swap, the router for a routed swap). There is no shielded/source column.
  • indexer/src/db/queries/swap_events.rs selects by sender for trader histories; indexer/src/db/queries/positions.rs keys trader_positions.trader_address; indexer/src/indexer/trader_tracker.rs and position_tracker.rs build trader/position state from swaps.
  • Public routes in indexer/src/api/mod.rs: /api/v1/pairs/{addr}/trades (returns TradeResponse.sender, api/pairs.rs around line 524–588), /api/v1/traders/leaderboard, /api/v1/traders/{addr} and /trades, /limit-fills, /limit-placements, /limit-cancellations (CSV export in frontend-dapp/src/services/indexer/client.ts around lines 476–557), /api/v1/compliance/blacklist-check (takes wallet), /api/v1/evidence/daily (schema 2, no actor identifiers), plus GT/CG/CMC, DeFiLlama and protocol fee/volume endpoints.
  • indexer/src/api/route_solver.rs accepts trader/sender (lines ~46, 92–124) and caches (trader, sender) -> discount_bps; frontend-dapp/src/services/indexer/client.ts always sends the connected wallet as trader for ordinary quotes. This is a direct wallet-to-intent leak if reused for shielded quotes.
  • indexer/src/indexer/parser.rs walks wasm events; event_amount.rs normalises amounts; asset_code_id_freeze.rs and listing_exclude.rs already classify assets by code id/listing. docs/indexer-invariants.md is the invariant home; docs/indexer-http.md is the HTTP pack/OpenAPI source; #1397 is the precedent for schema-2 evidence with explicit non-anonymity language.
  • There is no shielded/pool/note concept in the schema, parser, API, OpenAPI or docs. A new pool address would today be stored as swap_events.sender and would appear as a "trader" with volume, positions, a leaderboard rank and CSV history.

Why a new implementation is needed

If the pool's swaps are indexed like any other swap, the public API will publish the pool as a trader, rank it, compute positions and P&L, and serve its history under /api/v1/traders/{pool}. That is not a direct user-address leak, but it is misleading analytics, it creates an attribution surface the feature explicitly must not create, and it invites scraping/correlation of shielded flows. Conversely, dropping shielded swaps from the tape would undercount pair volume, protocol fees, TVL and every external listing (GT/CG/CMC/DeFiLlama), breaking existing accounting invariants.

Clients also need note discovery. If the API offers "notes for pubkey P", it becomes a per-key balance oracle and the indexer sees the user's key in every request. If it offers nothing, the dApp must scan all chain history itself, which is not viable on mobile. A range-based, cacheable, opaque-payload endpoint with strict budgets is the compromise.

Relevant files

  • indexer/migrations/ (new migration; follow the date-prefixed pattern, include a revert)
  • indexer/src/indexer/{parser,trader_tracker,position_tracker,volume_aggregator,protocol_fees,asset_code_id_freeze}.rs
  • indexer/src/db/queries/{swap_events,positions,traders,pairs,pair_volume_usd,protocol_fee_series,evidence_daily,evidence_digest}.rs
  • indexer/src/api/{mod,pairs,traders,compliance,route_solver,evidence,gt,cg,cmc,defillama,protocol_volume,protocol_fees,overview}.rs
  • indexer/src/config.rs (shielded pool addresses/allowlist; read-only env)
  • indexer/tests/ (integration tests; Postgres under #1396)
  • docs/indexer-http.md, docs/indexer-invariants.md, docs/qa/issue-<N>/README.md, skills/AGENTS_INDEXER_SHIELDED.md
  • Read-only reference: indexer/src/api/route_solver.rs (no-RPC and discount cache), indexer/src/api/evidence.rs (schema 2), docs/qa/issue-1397/README.md and docs/qa/issue-694/README.md (budgets)
  1. Trusted classification, not heuristics. Configure SHIELDED_POOL_ADDRESSES (and the pool's code id/checksum pin) in indexer config. Mark a swap shielded only when on-chain evidence is unambiguous: the pair's receiver is the pool and/or the initiating sender is the pool, or the pool emits its own action=shielded_swap attribute. Do not trust a user-supplied shielded flag or a token metadata field. If the evidence is ambiguous, leave the row unclassified (fail-closed for non-attribution) and surface an internal counter; do not guess.

  2. Schema. Add a small, explicit classification to swap_events (e.g. venue_source TEXT NOT NULL DEFAULT 'dex' with values dex, shielded_pool, plus shielded_pool_id/shielded_pool_address nullable) or a dedicated shielded_swaps table; choose the option that keeps pair/protocol queries simple and does not duplicate economic rows. Add an index for the classifier. Backfill is not required for pre-deployment rows, but the migration must be idempotent and re-runnable and must not rewrite history. Do not store note commitments, nullifiers, openings, owner pubkeys or change notes in the indexer. The indexer's job is the swap/transfer, not the note graph.

  3. Economic inclusion. Pair volume/candles, protocol volume, protocol fees, TVL, DeFiLlama UTC-day volume/fees, GT/CG/CMC trade and pair surfaces and the overview must include shielded swaps exactly once. Guard against double counting: the pair emits the swap and the pool emits settlement; the parser must not write two swap_events rows for one swap. Add an invariant test that sums the shielded + non-shielded rows against the pair's own swap count for a fixture.

  4. Non-attribution. trader_tracker and position_tracker must skip rows where venue_source = 'shielded_pool'. GET /api/v1/traders/{addr} for the pool address returns a documented 404/not_attributable response (not a 200 with zeroed stats, which invites "the pool has no activity" confusion); leaderboard queries exclude the pool; CSV exports must not include shielded rows under a wallet identity. GET /api/v1/pairs/{addr}/trades may keep the pool address as sender (it is public on chain) but must add shielded: true so clients can label it without a user identity. Do not add a per-note or per-owner field anywhere.

  5. Note discovery endpoint. Add GET /api/v1/shielded/notes?pool=<addr>&from_leaf=<n>&limit=<n> returning a bounded page of opaque note payloads emitted by the pool (leaf index, commitment, token, amount, owner pubkey, blinding/opening if phase-1 policy makes them public, plus the insert height and root). Requirements: query only by pool + leaf range; no pubkey/wallet/owner filter; no authentication that ties a request to a user; limit ≤ e.g. 200; from_leaf monotonic; cacheable with a short TTL; no note payload in access logs; API4-style in-flight/output caps (#694/#1397) and a 429/400 policy for oversize or malformed ranges. If the pool later encrypts the payload, the endpoint returns ciphertext unchanged and the contract is unchanged. Document that the endpoint reveals the public note set and is not an anonymity service.

  6. Quote privacy. Shielded quotes must use the pool address or no trader/sender; never the user's wallet. Validate and normalise the quote parameters, keep the existing no-request-triggered-RPC rule, and ensure the discount cache key can never mix the user's address into a shielded quote. Add an indexer test that a shielded quote with a wallet trader is rejected or ignored deterministically, and a frontend contract (with #1586) that the wallet is not sent.

  7. Evidence and listings. Evidence schema remains schema 2 with no actor identifiers; shielded swaps are included in the economic rows with the pool address (public) and no note/owner data. Confirm schema/privacy-policy strings remain accurate and update the "retained public transaction hashes" language if needed. GT/CG/CMC/DeFiLlama can include shielded volume/trades; no new actor fields. Keep the existing no-actor guarantees of #1397.

  8. Operations and docs. Update docs/indexer-http.md/OpenAPI with the new field/endpoint and explicit privacy language; update docs/indexer-invariants.md with the classification, double-count and non-attribution invariants; add a runbook note for the pool address/code-id pin and for re-ingesting after a pool upgrade.

Constraints and guardrails

  • No actor data: no note keys, openings, nullifiers, wallet addresses from shielded requests, or conversation text in DB, logs, metrics, OpenAPI examples, fixtures or docs. Redact query strings for shielded endpoints; do not log from_leaf together with a client identifier; retain only aggregate counters.
  • No behavioural change for non-shielded users: existing trade rows, trader endpoints, leaderboards, positions, CSVs, evidence and listing schemas stay compatible; the new field is additive. Any breaking change needs an explicit versioning plan and consumer notice.
  • No economic exclusion: shielded swaps count in volume/fees/TVL and external listings exactly once. Do not "hide" shielded volume to protect privacy; do not double count it to inflate stats.
  • Budgets: every new endpoint and page obeys the existing per-request caps, in-flight limits, SQL timeouts and pagination rules (#694/#1397); no full-history scans, no unbounded limit, no per-key query. Caches must be keyed by pool + leaf range, not by client.
  • No request-triggered chain calls: classification comes from indexed data; note discovery comes from indexed events. A request must never cause an LCD/RPC query, an ingestion pass, or a pool state read.
  • Least privilege: runtime DB role under #1396; disposable integration DB per test process; never mutate production data or the production indexer for reproduction.
  • Failure posture: unknown/malformed pool events, a pool address/code-id mismatch, a missing pool config or an ambiguous classifier fail closed (unclassified, counted as a data-quality alert) rather than attributing to a wallet or dropping economic rows.
  • Migration safety: additive, idempotent, re-runnable, with a revert; no table rewrite that locks the production DB beyond the documented maintenance window; test on a copy.

Acceptance criteria

  • AC1: A configured pool address is classified from trusted on-chain evidence; a spoofed shielded attribute from a non-pool contract or a user-supplied flag cannot classify a row.
  • AC2: /api/v1/pairs/{addr}/trades marks shielded rows without a user identity and keeps the pool address (public) where the chain shows it; pair/protocol volume, fees, candles and TVL include shielded swaps exactly once.
  • AC3: /api/v1/traders/{pool}, the leaderboard, positions/P&L and CSV exports never attribute shielded activity; the pool is excluded (or returns the documented non-attributable response) and non-shielded trader surfaces are unchanged.
  • AC4: GET /api/v1/shielded/notes returns bounded, cacheable opaque pages by pool + leaf range only; there is no pubkey/wallet filter and no per-key balance surface; caps and error codes are documented and tested.
  • AC5: Shielded quotes never carry the user's wallet; the indexer rejects/ignores a wallet trader for shielded quotes; no request-triggered RPC and no cache-key cross-contamination with wallet-discount entries.
  • AC6: Evidence and external listing surfaces (DeFiLlama/GT/CG/CMC) include shielded economics and remain free of note/owner/wallet data; schema-2 privacy language stays accurate.
  • AC7: A DB/API test fixture proves no double counting between pair swap rows and pool settlement events, and that a re-ingest/reorg is idempotent.
  • AC8: No shielded request's query string, note data, key or wallet is logged, exported, documented or used as a cache key; redaction tests and an OpenAPI example review pass.
  • AC9: docs/indexer-http.md, docs/indexer-invariants.md, the OpenAPI spec, docs/qa/issue-<N>/README.md and skills/AGENTS_INDEXER_SHIELDED.md are updated; make verify-issue-<N> exists.
  • AC10: All existing indexer integration tests pass unchanged, and the new migration has a tested revert and a documented rollback path.

Test plan: functional paths

Path Required checks
Parser/classification Direct pool→pair swap, pool→router→pair swap, multi-hop with pool input and pool output, shielded deposit transfer, pool withdraw transfer, non-pool swap, spoofed shielded attribute, missing/duplicate pool config, pool code-id drift, ambiguous evidence.
Economic totals Pair volume/candles, protocol volume/fees, TVL/hub prices, DeFiLlama UTC-day, GT/CG/CMC pair/trade surfaces, overview totals, and repeated re-ingest; assert exact-once inclusion.
Trader surfaces /api/v1/traders/{addr} for a user, the pool and an unknown address; leaderboard before/after shielded volume; positions/P&L; CSV exports; limit fills/placements/cancellations; assert no shielded attribution.
Trade tape /api/v1/pairs/{addr}/trades ordering, pagination, sender=pool, shielded flag, amount/price fields, mixed shielded/non-shielded pages, cursor stability.
Note discovery Empty pool, first page, middle page, last page, from_leaf at/after the end, max limit, over-cap, malformed/negative/non-numeric ranges, cross-pool request, cache hit/miss, payload with future encrypted/phase-2 shape.
Quote privacy Shielded quote with no trader, pool trader, wallet trader, sender set, mixed case, invalid address, cached discount entries; assert request path and cache keys.
Evidence/listings Schema 2 unchanged, shielded rows included, no actor fields, GT/CG/CMC/DeFiLlama shapes unchanged, pagination/cursors, empty day, reorg/re-ingest.
Migration Fresh DB, existing DB copy, run twice, revert, old rows default unclassified, indexes present, query plans for the hot endpoints remain bounded.

Test plan: attacks, hacks and abuse

  • Re-identification: query trader/sender/wallet parameters on shielded paths, cache keys keyed by wallet, response timing differences, CSV/OpenAPI examples, Referer/query-string logging, and public API joins. Prove no endpoint returns a note owner or a user wallet for shielded activity, and no cache key contains a user address.
  • Spoofing: a non-pool contract emits action=shielded_swap or a fake pool address; a user supplies a shielded flag; a token metadata field claims shielding; the pool address is copied by an attacker contract. Classification must use the configured pool and verified code id, never self-report.
  • Economic manipulation: double-count shielded swaps (pair + settlement), hide shielded volume to flatter trader stats, count a failed/reverted swap, count a deposit as volume, or count the same tx twice across router/pair events. Assert exact-once and reorg-safe accounting.
  • Note oracle: repeated from_leaf scans, combining the endpoint with public deposits, adding a pubkey filter, or using response sizes/timings to infer a user's note count. Enforce range-only queries, caps, caching, no per-key aggregation and no request-time key handling.
  • Privacy through the back door: new DB columns, logs, metrics labels, traces, error messages, OpenAPI examples, CSV headers, evidence exports, Grafana panels or issue docs containing note keys/wallet addresses. Add a static scan for forbidden fields and a log-capture test.
  • Accessibility/consumer breakage: a schema/field change that breaks frontend parsing, a 404 that the UI treats as "no history", or a leaderboard that silently includes the pool. Contract tests for the frontend payload parsers.
  • Resource abuse: huge leaf ranges, parallel note scans, repeated 429s, oversized pages, expensive SQL, and cache poisoning. Verify API4 caps, SQL timeouts, in-flight limits and bounded memory.
  • Supply chain / config: a malicious SHIELDED_POOL_ADDRESSES update, a pool code-id drift, or an attacker-controlled pool upgrade that changes event names. Fail closed, alert, and do not reclassify old rows.

Verification criteria

  • make verify-issue-<N> runs indexer fmt/clippy/build, the new migration up/down, integration tests against disposable Postgres (#1396), OpenAPI/schema checks, doc cross-links and the existing indexer suites (cargo test --lib, relevant --test bins).
  • A fixture with shielded and non-shielded swaps proves: pair volume includes both, trader/leaderboard/positions include only non-shielded, the trade tape marks shielded, DeFiLlama/GT/CG/CMC totals are exact, and the evidence response has no actor/note fields.
  • A request-capture test proves shielded endpoints receive no wallet, note key or owner filter; a log-capture test proves no note/key/wallet redaction failure.
  • docs/qa/issue-<N>/README.md records executed checks, explicit skips (e.g. deployed-indexer verification) and the agent checklist. Executed failures remain FAIL; unavailable checks may be explicit SKIP with PASS WITH SKIPS, without claiming deployed acceptance.
  • No conversation, personal data, reporter attribution, wallet-owner identity or private key appears in issue text, docs, fixtures, logs or receipts.

Out of scope / follow-ups

  • Pool contract and note layer (#1583); private swap execution (#1584).
  • dApp vault, quote and UX (#1586); threat model/abuse/rollout (#1587).
  • Encrypted note payloads or ZK proofs (phase 2); per-key note queries (not planned); hiding public chain linkage (not possible).
## Problem and scope Make the indexer and its public API **honest and non-attributing** for shielded activity, and give shielded clients a way to discover their notes without handing the indexer a user key or wallet address. The indexer must: 1. classify pool-originated swaps and deposits correctly (shielded vs ordinary) from trusted on-chain evidence; 2. include shielded swaps in **economic** aggregates (pair volume/candles, protocol volume/fees, TVL, DeFiLlama/GT/CG/CMC surfaces) so totals do not undercount; 3. exclude shielded flows from **social/attribution** surfaces (`/api/v1/traders/{addr}`, leaderboard, positions/P&L, trader CSV) and never invent a note owner; 4. serve note discovery in a form that does not let the API become a per-wallet or per-key balance oracle; 5. guarantee that no note opening, note key, private key, wallet address from a shielded request, or user conversation is persisted, logged, exported or documented. This issue does not implement the pool (#1583), the swap (#1584), the dApp (#1586) or the security/abuse program (#1587). It depends on the emitted event shapes defined by #1583/#1584 and must be implemented against a final event schema, not a guess. ## Current codebase and investigation Reviewed checkout: `38c154958`. - `indexer/migrations/20260310000001_initial_schema.sql` creates `swap_events` with `sender VARCHAR(64) NOT NULL`, `receiver VARCHAR(64)`, `tx_hash`, `offer_amount`, `return_amount`, and `idx_swaps_sender (sender, block_timestamp DESC)`. `swap_events.sender` is the DEX-visible counterparty (the pair's CW20 sender: a wallet for a direct swap, the router for a routed swap). There is no shielded/source column. - `indexer/src/db/queries/swap_events.rs` selects by `sender` for trader histories; `indexer/src/db/queries/positions.rs` keys `trader_positions.trader_address`; `indexer/src/indexer/trader_tracker.rs` and `position_tracker.rs` build trader/position state from swaps. - Public routes in `indexer/src/api/mod.rs`: `/api/v1/pairs/{addr}/trades` (returns `TradeResponse.sender`, `api/pairs.rs` around line 524–588), `/api/v1/traders/leaderboard`, `/api/v1/traders/{addr}` and `/trades`, `/limit-fills`, `/limit-placements`, `/limit-cancellations` (CSV export in `frontend-dapp/src/services/indexer/client.ts` around lines 476–557), `/api/v1/compliance/blacklist-check` (takes `wallet`), `/api/v1/evidence/daily` (schema 2, no actor identifiers), plus GT/CG/CMC, DeFiLlama and protocol fee/volume endpoints. - `indexer/src/api/route_solver.rs` accepts `trader`/`sender` (lines ~46, 92–124) and caches `(trader, sender) -> discount_bps`; `frontend-dapp/src/services/indexer/client.ts` always sends the connected wallet as `trader` for ordinary quotes. This is a direct wallet-to-intent leak if reused for shielded quotes. - `indexer/src/indexer/parser.rs` walks wasm events; `event_amount.rs` normalises amounts; `asset_code_id_freeze.rs` and `listing_exclude.rs` already classify assets by code id/listing. `docs/indexer-invariants.md` is the invariant home; `docs/indexer-http.md` is the HTTP pack/OpenAPI source; #1397 is the precedent for schema-2 evidence with explicit non-anonymity language. - There is **no** shielded/pool/note concept in the schema, parser, API, OpenAPI or docs. A new pool address would today be stored as `swap_events.sender` and would appear as a "trader" with volume, positions, a leaderboard rank and CSV history. ## Why a new implementation is needed If the pool's swaps are indexed like any other swap, the public API will publish the pool as a trader, rank it, compute positions and P&L, and serve its history under `/api/v1/traders/{pool}`. That is not a direct user-address leak, but it is misleading analytics, it creates an attribution surface the feature explicitly must not create, and it invites scraping/correlation of shielded flows. Conversely, dropping shielded swaps from the tape would undercount pair volume, protocol fees, TVL and every external listing (GT/CG/CMC/DeFiLlama), breaking existing accounting invariants. Clients also need note discovery. If the API offers "notes for pubkey P", it becomes a per-key balance oracle and the indexer sees the user's key in every request. If it offers nothing, the dApp must scan all chain history itself, which is not viable on mobile. A range-based, cacheable, opaque-payload endpoint with strict budgets is the compromise. ## Relevant files - `indexer/migrations/` (new migration; follow the date-prefixed pattern, include a revert) - `indexer/src/indexer/{parser,trader_tracker,position_tracker,volume_aggregator,protocol_fees,asset_code_id_freeze}.rs` - `indexer/src/db/queries/{swap_events,positions,traders,pairs,pair_volume_usd,protocol_fee_series,evidence_daily,evidence_digest}.rs` - `indexer/src/api/{mod,pairs,traders,compliance,route_solver,evidence,gt,cg,cmc,defillama,protocol_volume,protocol_fees,overview}.rs` - `indexer/src/config.rs` (shielded pool addresses/allowlist; read-only env) - `indexer/tests/` (integration tests; Postgres under #1396) - `docs/indexer-http.md`, `docs/indexer-invariants.md`, `docs/qa/issue-<N>/README.md`, `skills/AGENTS_INDEXER_SHIELDED.md` - Read-only reference: `indexer/src/api/route_solver.rs` (no-RPC and discount cache), `indexer/src/api/evidence.rs` (schema 2), `docs/qa/issue-1397/README.md` and `docs/qa/issue-694/README.md` (budgets) ## Recommended direction 1. **Trusted classification, not heuristics.** Configure `SHIELDED_POOL_ADDRESSES` (and the pool's code id/checksum pin) in indexer config. Mark a swap shielded only when on-chain evidence is unambiguous: the pair's `receiver` is the pool and/or the initiating sender is the pool, or the pool emits its own `action=shielded_swap` attribute. Do not trust a user-supplied `shielded` flag or a token metadata field. If the evidence is ambiguous, leave the row unclassified (fail-closed for non-attribution) and surface an internal counter; do not guess. 2. **Schema.** Add a small, explicit classification to `swap_events` (e.g. `venue_source TEXT NOT NULL DEFAULT 'dex'` with values `dex`, `shielded_pool`, plus `shielded_pool_id`/`shielded_pool_address` nullable) or a dedicated `shielded_swaps` table; choose the option that keeps pair/protocol queries simple and does not duplicate economic rows. Add an index for the classifier. Backfill is not required for pre-deployment rows, but the migration must be idempotent and re-runnable and must not rewrite history. Do **not** store note commitments, nullifiers, openings, owner pubkeys or change notes in the indexer. The indexer's job is the swap/transfer, not the note graph. 3. **Economic inclusion.** Pair volume/candles, protocol volume, protocol fees, TVL, DeFiLlama UTC-day volume/fees, GT/CG/CMC trade and pair surfaces and the overview must include shielded swaps exactly once. Guard against double counting: the pair emits the swap and the pool emits settlement; the parser must not write two `swap_events` rows for one swap. Add an invariant test that sums the shielded + non-shielded rows against the pair's own swap count for a fixture. 4. **Non-attribution.** `trader_tracker` and `position_tracker` must skip rows where `venue_source = 'shielded_pool'`. `GET /api/v1/traders/{addr}` for the pool address returns a documented `404`/`not_attributable` response (not a 200 with zeroed stats, which invites "the pool has no activity" confusion); leaderboard queries exclude the pool; CSV exports must not include shielded rows under a wallet identity. `GET /api/v1/pairs/{addr}/trades` may keep the pool address as `sender` (it is public on chain) but must add `shielded: true` so clients can label it without a user identity. Do not add a per-note or per-owner field anywhere. 5. **Note discovery endpoint.** Add `GET /api/v1/shielded/notes?pool=<addr>&from_leaf=<n>&limit=<n>` returning a bounded page of **opaque** note payloads emitted by the pool (leaf index, commitment, token, amount, owner pubkey, blinding/opening if phase-1 policy makes them public, plus the insert height and root). Requirements: query only by pool + leaf range; no pubkey/wallet/owner filter; no authentication that ties a request to a user; `limit` ≤ e.g. 200; `from_leaf` monotonic; cacheable with a short TTL; no note payload in access logs; API4-style in-flight/output caps (#694/#1397) and a 429/400 policy for oversize or malformed ranges. If the pool later encrypts the payload, the endpoint returns ciphertext unchanged and the contract is unchanged. Document that the endpoint reveals the public note set and is not an anonymity service. 6. **Quote privacy.** Shielded quotes must use the pool address or no `trader`/`sender`; never the user's wallet. Validate and normalise the quote parameters, keep the existing no-request-triggered-RPC rule, and ensure the discount cache key can never mix the user's address into a shielded quote. Add an indexer test that a shielded quote with a wallet `trader` is rejected or ignored deterministically, and a frontend contract (with #1586) that the wallet is not sent. 7. **Evidence and listings.** Evidence schema remains schema 2 with no actor identifiers; shielded swaps are included in the economic rows with the pool address (public) and no note/owner data. Confirm schema/privacy-policy strings remain accurate and update the "retained public transaction hashes" language if needed. GT/CG/CMC/DeFiLlama can include shielded volume/trades; no new actor fields. Keep the existing no-actor guarantees of #1397. 8. **Operations and docs.** Update `docs/indexer-http.md`/OpenAPI with the new field/endpoint and explicit privacy language; update `docs/indexer-invariants.md` with the classification, double-count and non-attribution invariants; add a runbook note for the pool address/code-id pin and for re-ingesting after a pool upgrade. ## Constraints and guardrails - **No actor data:** no note keys, openings, nullifiers, wallet addresses from shielded requests, or conversation text in DB, logs, metrics, OpenAPI examples, fixtures or docs. Redact query strings for shielded endpoints; do not log `from_leaf` together with a client identifier; retain only aggregate counters. - **No behavioural change for non-shielded users:** existing trade rows, trader endpoints, leaderboards, positions, CSVs, evidence and listing schemas stay compatible; the new field is additive. Any breaking change needs an explicit versioning plan and consumer notice. - **No economic exclusion:** shielded swaps count in volume/fees/TVL and external listings exactly once. Do not "hide" shielded volume to protect privacy; do not double count it to inflate stats. - **Budgets:** every new endpoint and page obeys the existing per-request caps, in-flight limits, SQL timeouts and pagination rules (#694/#1397); no full-history scans, no unbounded `limit`, no per-key query. Caches must be keyed by pool + leaf range, not by client. - **No request-triggered chain calls:** classification comes from indexed data; note discovery comes from indexed events. A request must never cause an LCD/RPC query, an ingestion pass, or a pool state read. - **Least privilege:** runtime DB role under #1396; disposable integration DB per test process; never mutate production data or the production indexer for reproduction. - **Failure posture:** unknown/malformed pool events, a pool address/code-id mismatch, a missing pool config or an ambiguous classifier fail closed (unclassified, counted as a data-quality alert) rather than attributing to a wallet or dropping economic rows. - **Migration safety:** additive, idempotent, re-runnable, with a revert; no table rewrite that locks the production DB beyond the documented maintenance window; test on a copy. ## Acceptance criteria - [ ] AC1: A configured pool address is classified from trusted on-chain evidence; a spoofed `shielded` attribute from a non-pool contract or a user-supplied flag cannot classify a row. - [ ] AC2: `/api/v1/pairs/{addr}/trades` marks shielded rows without a user identity and keeps the pool address (public) where the chain shows it; pair/protocol volume, fees, candles and TVL include shielded swaps exactly once. - [ ] AC3: `/api/v1/traders/{pool}`, the leaderboard, positions/P&L and CSV exports never attribute shielded activity; the pool is excluded (or returns the documented non-attributable response) and non-shielded trader surfaces are unchanged. - [ ] AC4: `GET /api/v1/shielded/notes` returns bounded, cacheable opaque pages by pool + leaf range only; there is no pubkey/wallet filter and no per-key balance surface; caps and error codes are documented and tested. - [ ] AC5: Shielded quotes never carry the user's wallet; the indexer rejects/ignores a wallet `trader` for shielded quotes; no request-triggered RPC and no cache-key cross-contamination with wallet-discount entries. - [ ] AC6: Evidence and external listing surfaces (DeFiLlama/GT/CG/CMC) include shielded economics and remain free of note/owner/wallet data; schema-2 privacy language stays accurate. - [ ] AC7: A DB/API test fixture proves no double counting between pair swap rows and pool settlement events, and that a re-ingest/reorg is idempotent. - [ ] AC8: No shielded request's query string, note data, key or wallet is logged, exported, documented or used as a cache key; redaction tests and an OpenAPI example review pass. - [ ] AC9: `docs/indexer-http.md`, `docs/indexer-invariants.md`, the OpenAPI spec, `docs/qa/issue-<N>/README.md` and `skills/AGENTS_INDEXER_SHIELDED.md` are updated; `make verify-issue-<N>` exists. - [ ] AC10: All existing indexer integration tests pass unchanged, and the new migration has a tested revert and a documented rollback path. ## Test plan: functional paths | Path | Required checks | | --- | --- | | Parser/classification | Direct pool→pair swap, pool→router→pair swap, multi-hop with pool input and pool output, shielded deposit transfer, pool withdraw transfer, non-pool swap, spoofed `shielded` attribute, missing/duplicate pool config, pool code-id drift, ambiguous evidence. | | Economic totals | Pair volume/candles, protocol volume/fees, TVL/hub prices, DeFiLlama UTC-day, GT/CG/CMC pair/trade surfaces, overview totals, and repeated re-ingest; assert exact-once inclusion. | | Trader surfaces | `/api/v1/traders/{addr}` for a user, the pool and an unknown address; leaderboard before/after shielded volume; positions/P&L; CSV exports; limit fills/placements/cancellations; assert no shielded attribution. | | Trade tape | `/api/v1/pairs/{addr}/trades` ordering, pagination, sender=pool, `shielded` flag, amount/price fields, mixed shielded/non-shielded pages, cursor stability. | | Note discovery | Empty pool, first page, middle page, last page, `from_leaf` at/after the end, max `limit`, over-cap, malformed/negative/non-numeric ranges, cross-pool request, cache hit/miss, payload with future encrypted/phase-2 shape. | | Quote privacy | Shielded quote with no trader, pool trader, wallet trader, `sender` set, mixed case, invalid address, cached discount entries; assert request path and cache keys. | | Evidence/listings | Schema 2 unchanged, shielded rows included, no actor fields, GT/CG/CMC/DeFiLlama shapes unchanged, pagination/cursors, empty day, reorg/re-ingest. | | Migration | Fresh DB, existing DB copy, run twice, revert, old rows default unclassified, indexes present, query plans for the hot endpoints remain bounded. | ## Test plan: attacks, hacks and abuse - **Re-identification:** query `trader`/`sender`/wallet parameters on shielded paths, cache keys keyed by wallet, response timing differences, CSV/OpenAPI examples, `Referer`/query-string logging, and public API joins. Prove no endpoint returns a note owner or a user wallet for shielded activity, and no cache key contains a user address. - **Spoofing:** a non-pool contract emits `action=shielded_swap` or a fake pool address; a user supplies a `shielded` flag; a token metadata field claims shielding; the pool address is copied by an attacker contract. Classification must use the configured pool and verified code id, never self-report. - **Economic manipulation:** double-count shielded swaps (pair + settlement), hide shielded volume to flatter trader stats, count a failed/reverted swap, count a deposit as volume, or count the same tx twice across router/pair events. Assert exact-once and reorg-safe accounting. - **Note oracle:** repeated `from_leaf` scans, combining the endpoint with public deposits, adding a pubkey filter, or using response sizes/timings to infer a user's note count. Enforce range-only queries, caps, caching, no per-key aggregation and no request-time key handling. - **Privacy through the back door:** new DB columns, logs, metrics labels, traces, error messages, OpenAPI examples, CSV headers, evidence exports, Grafana panels or issue docs containing note keys/wallet addresses. Add a static scan for forbidden fields and a log-capture test. - **Accessibility/consumer breakage:** a schema/field change that breaks frontend parsing, a 404 that the UI treats as "no history", or a leaderboard that silently includes the pool. Contract tests for the frontend payload parsers. - **Resource abuse:** huge leaf ranges, parallel note scans, repeated 429s, oversized pages, expensive SQL, and cache poisoning. Verify API4 caps, SQL timeouts, in-flight limits and bounded memory. - **Supply chain / config:** a malicious `SHIELDED_POOL_ADDRESSES` update, a pool code-id drift, or an attacker-controlled pool upgrade that changes event names. Fail closed, alert, and do not reclassify old rows. ## Verification criteria - [ ] `make verify-issue-<N>` runs indexer fmt/clippy/build, the new migration up/down, integration tests against disposable Postgres (#1396), OpenAPI/schema checks, doc cross-links and the existing indexer suites (`cargo test --lib`, relevant `--test` bins). - [ ] A fixture with shielded and non-shielded swaps proves: pair volume includes both, trader/leaderboard/positions include only non-shielded, the trade tape marks shielded, DeFiLlama/GT/CG/CMC totals are exact, and the evidence response has no actor/note fields. - [ ] A request-capture test proves shielded endpoints receive no wallet, note key or owner filter; a log-capture test proves no note/key/wallet redaction failure. - [ ] `docs/qa/issue-<N>/README.md` records executed checks, explicit skips (e.g. deployed-indexer verification) and the agent checklist. Executed failures remain FAIL; unavailable checks may be explicit SKIP with PASS WITH SKIPS, without claiming deployed acceptance. - [ ] No conversation, personal data, reporter attribution, wallet-owner identity or private key appears in issue text, docs, fixtures, logs or receipts. ## Out of scope / follow-ups - Pool contract and note layer (#1583); private swap execution (#1584). - dApp vault, quote and UX (#1586); threat model/abuse/rollout (#1587). - Encrypted note payloads or ZK proofs (phase 2); per-key note queries (not planned); hiding public chain linkage (not possible).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
code/cl8y-dex-terraclassic#1585
No description provided.