Skip to content

feat(contracts)!: key the claims vault by the nullifier - #319

Draft
nicolasLuduena wants to merge 6 commits into
feat/311-holder-one-blockfrom
feat/312-nullifier-keyed-vault
Draft

nicolasLuduena wants to merge 6 commits into
feat/311-holder-one-blockfrom
feat/312-nullifier-keyed-vault

Conversation

@nicolasLuduena

Copy link
Copy Markdown
Member

Closes #312
Part of #309. This is PR 4 of 6, stacked on #318.

Summary

The claims vault is keyed by the nullifier. Vault membership is the replay check. The nullifier set, the claim id (persistentCommit(claim, rand)) and the commitment randomness are gone. openClaim takes the nullifier and returns the observation identity. The vault entry and the vault pseudonym do not change.

 verifyAttestation()
-  [claim, sigs, rand] = getAttestationWitness()
+  [claim, sigs] = getAttestationWitness()
   nullifier = nullifierOf(claim)          # already computed for the signed message
   ...
-  assert !nullifiers.member(nullifier)    "Observation replay"
-  nullifiers.insert(nullifier)
-  claimsVault.insert(persistentCommit(claim, rand), entry)
+  assert !claimsVault.member(nullifier)   "Observation replay"
+  claimsVault.insert(nullifier, entry)

-openClaim(id): Claim
-  [claim,, rand] = getAttestationWitness()
+openClaim(nullifier): Observation         # every claim field except holder and version
+  [claim,] = getAttestationWitness()
   assert member                          "Unknown claim"
   assert entry.holder == pseudonym       "Claim not bound to caller"
-  assert persistentCommit(claim, rand) == id      "Claim does not match id"
-  return claim
+  assert sha256(observationOf(claim)) == nullifier "Claim does not match nullifier"
+  return observationOf(claim)

The holder computes the nullifier off-chain with nullifierOf(claim) from @txpipe/thoth-core/claim. Neither kind keeps vault state now. Each kind's getAttestationWitness returns [claim, signatures], and both acceptance tests open the accepted claim by its off-chain nullifier.

  • Docs: ADR 0016 explains why the vault key hides no more and no less than the nullifier published in the same transaction, including for a chain-event kind whose salt is public. ADR 0006's status line notes the amendment. Also updated: the glossary's nullifier and claims vault entries, the contracts README (guarantees, a new design decision, proving cost), the root README, DESIGN, the kind author guide and the Cardano dApp guide.
  • Changeset: contracts only.

Evidence

Before is feat/311-holder-one-block; after is this branch. Both come from npm run bench: Ryzen 7 5700G, proof server 9.0.0, a fresh container per circuit, 3 warm proofs.

Mock Circuit k before → after Rows before → after Key (MB) Warm proof (s) Peak mem (MB)
mock_attestation verifyAttestation 15 → 14 21,253 → 13,646 49.3 → 24.7 2.50 → 1.48 765 → 454
mock_attestation openAndRead 14 → 13 8,610 → 6,657 24.6 → 12.3 1.15 → 0.67 450 → 255
mock_attestation openAndReadPresence 14 → 13 8,580 → 6,627 24.6 → 12.3 1.17 → 0.70 457 → 244
mock_attestation openAndRequireMetric0 14 → 13 8,570 → 6,617 24.6 → 12.3 1.15 → 0.66 469 → 213
mock_attestation openAndBindHost 14 → 14 14,633 → 12,680 24.6 1.22 → 1.21 458 → 434
mock_attestation_bytes verifyAttestation 15 → 14 25,076 → 15,599 49.3 → 24.7 2.55 → 1.51 759 → 455
mock_attestation_bytes openAndReadBytes 15 → 15 19,188 → 17,236 49.3 2.22 → 2.19 759 → 757
  • Every circuit of both mocks proved on the proof server, and the server verified every proof against its verifier key. It refused a proof under the wrong verifier key.
  • Budgets met: verifyAttestation is at most 16,384 on both mocks (the bytes mock has 785 rows to spare), and the three open circuits are at most 8,192. The open circuits prove with the unchanged hashToCurve pseudonym.
  • openAndReadBytes stays at k = 15. Reassembling the byte halves is what contracts, core: byte slots travel whole #313 removes.

A predicate that reads holder or version from openClaim's result does not compile. I compiled this throwaway mock, then deleted it:

import "../../attestation"<3, 0, 2, 3> prefix A_;

export circuit openAndReadholder(nullifier: Bytes<32>): [] {
  const c = A_openClaim(nullifier);
  assert(c.holder == default<A_Claim>.holder, "unbound field");
}
$ compact compile +0.36.1 --skip-zk test/mocks/ProbeReads_holder.compact ...
Exception: ProbeReads_holder.compact line 9 char 11:
  structure Observation has no field named holder
exit 255
$ compact compile +0.36.1 --skip-zk test/mocks/ProbeReads_version.compact ...
Exception: ProbeReads_version.compact line 9 char 11:
  structure Observation has no field named version
exit 255

The same mock reading c.salt instead compiles (exit 0). The returned type says the same thing, and npm run types checks it:

expectTypeOf<A_Observation>().toEqualTypeOf<Omit<A_Claim, 'holder' | 'version'>>();

I checked that this test fails when 'holder' is dropped from the Omit.

Simulator tests on the numeric mock (attestation.test.ts):

claim vault content › stores holder and window under the nullifier         (red before the change)
observation replay  › rejects a resubmission of the accepted claim and keeps its vault entry
openClaim           › returns every claim field but holder and version     (type test)
openClaim           › rejects an unknown nullifier                         "Unknown claim"
openClaim           › rejects a caller whose secret does not own the entry "Claim not bound to caller"
openClaim           › rejects a claim that does not hash to the nullifier  "Claim does not match nullifier"
openClaim           › rejects the caller's other vaulted claim under this nullifier
openClaim           › opens whatever holder and version the witness claim carries
openClaim           › is repeatable and consumes nothing                   (vault size and entry unchanged)

Both acceptance suites (acceptance.test.ts for zkFetch, acceptance-cardano.test.ts for Cardano) gain lets the holder open the accepted claim by its off-chain nullifier, and both pass. npm test passes (823 passed, 4 live tests skipped), and so do npm run types and npm run check.

No verification skill in this repo.

Merge Danger

Door: two-way

Pre-launch, nothing is deployed. The vault key and the witness shape can still change, and version stays 1.

Blast Radius: contract-wide

Every embedding contract changes:

  • A_nullifiers and computeId are gone.
  • getAttestationWitness returns two elements instead of three.
  • Predicates take the nullifier, and they get an Observation instead of a Claim.

A predicate that read holder or version stops compiling, which is the point of the change.

verifyAttestation stores the claim under its nullifier and rejects a
nullifier already in the vault, so vault membership is the replay check.
The nullifier set, the claim id and the commitment randomness in the
witness are gone.

openClaim takes the nullifier and returns the observation identity, the
fields the nullifier binds, without holder or version.
ADR 0016 records why the vault key hides no more and no less than the
nullifier the same transaction publishes, including for a chain-event
kind whose salt is public. The glossary, the root README, the design and
the kind author guide open a claim by its nullifier.
@coderabbitai

coderabbitai Bot commented Nov 27, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • 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

…tection

List what openClaim rejects apart from what the module leaves to the app,
show where the Cardano guide's nullifier comes from, and drop the bytes
mock's unused Observation export.
…d-vault

# Conflicts:
#	packages/contracts/README.md

This branch has not been deployed

No deployments
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.

1 participant