caelum0x 19d6549230 feat: p8 zk receipt proofs (selective disclosure + Merkle anchoring)
ReceiptProofSystem lets an agent prove a receipt is anchored on-chain and
disclose only chosen fields while hiding the rest. Each attribute is a
secret-salted hiding commitment H(key=value|salt); receipt leaves form a
Merkle tree whose root is the on-chain anchor; a DisclosureProof opens the
revealed fields, ships opaque commitments for the rest, and a Merkle path.
verify() needs no prover secret — anyone can check inclusion from the root.

Honest scope: commitment-based selective-disclosure + membership (the
dependency-free, Casper-verifiable Stage-4 primitive), not a full zk-SNARK.

6 new tests, full suite 218 green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-17 17:42:03 +03:00

45 lines
2.5 KiB
Markdown

# p8 — zk receipt proofs (trust-ladder Stage 4)
> **Prove a receipt is valid and anchored without revealing it.** Let a counterparty
> verify "this agent finalized an x402 receipt in category `rwa` for ≥ X" while the
> amount, counterparty, and other fields stay private.
## Why
Today, using a receipt as credit evidence means disclosing it. For sensitive
commercial activity that is a non-starter. The trust ladder's top rung is
**privacy-preserving proof**: an agent proves the *properties* of its revenue
history that matter for credit, without exposing the underlying business data — so
even competitors can underwrite each other.
## Scope
- **Field-wise commitments.** Each receipt attribute is hidden behind a
secret-salted hash `H(key=value|salt)`, so a commitment reveals nothing about the
value (salts are high-entropy, derived from a prover secret).
- **Merkle anchoring.** Receipt leaves (binding all field commitments) form a
Merkle tree; the root is the on-chain anchor.
- **Selective disclosure proofs.** A proof opens only the chosen fields
`(value, salt)`, ships the opaque commitments of the rest, and a Merkle path to
the root. The verifier recomputes the leaf and checks inclusion — learning the
disclosed fields and nothing else. No prover secret needed to verify.
## Deliverables (shipped)
- `lib/services/receipt_proof.ts` — `ReceiptProofSystem`:
- `commit(receiptId, attrs)` → field commitments + Merkle leaf.
- `publishRoot(receipts)` → on-chain anchor root + ordered commitments.
- `prove(receipts, index, disclose[])` → `DisclosureProof` (selective reveal).
- `ReceiptProofSystem.verify(proof, expectedRoot)` → validity + disclosed values.
- Standalone `merkleRoot` / `merklePath` / `rootFromPath` (odd-tail safe).
- `test/receipt_proof.test.ts` — valid proof, tamper detection, wrong-root
rejection, secret-based hiding, path reconstruction, full-reveal special case.
## Honest scope note
This is a **commitment-based** selective-disclosure + Merkle-membership proof —
the dependency-free, cheaply Casper-verifiable Stage-4 primitive. It hides
undisclosed fields and proves membership; a full circuit-based zk-SNARK (hiding the
membership witness itself, proving range/predicate in zero knowledge) is the next
hardening step and can drop in behind the same `verify` interface.
## Success metric
An agent can win credit on the strength of receipts it never has to reveal, and any
party can verify the proof on-chain from the published root alone.