Skip to content

feat(contracts,core)!: attestors sign the nullifier - #317

Draft
nicolasLuduena wants to merge 17 commits into
feat/192-proving-benchmarkfrom
feat/310-sign-nullifier
Draft

nicolasLuduena wants to merge 17 commits into
feat/192-proving-benchmarkfrom
feat/310-sign-nullifier

Conversation

@nicolasLuduena

Copy link
Copy Markdown
Member

Closes #310
Part of #309

PR 2 of 6, stacked on #316.

Summary

Attestors now sign seven fields instead of the flat list of claim fields. version and holder reach the signature directly. Every other claim field reaches it through the nullifier, which verifyAttestation already computes for replay. The circuit no longer cuts five 32-byte fields at byte 16, and that cut was three quarters of verifyAttestation.

 verifyAttestation
-  msg = buildMessage(claim)                 // 14 + 2V + 2B fields, five 32-byte fields split into halves
+  nullifier = nullifierOf(claim)            // SHA-256 of the observation identity, computed once
+  msg = [version, V, B, limbs(nullifier), limbs(holder)]   // 7 fields
   Registry_countValidSignatures(msg, sigs)  // stdlib jubjubSchnorrVerify<7>
   ...
-  nullifier = nullifierOf(claim)
   replay check, vault insert

limbs(b) = [b[31], bytes 0–30 little-endian] is how a circuit already holds 32 bytes, so it needs no byte-by-byte decomposition.

-import "attestation"<K, V, B, N, M>     import "attestor_registry"<M, K>
+import "attestation"<V, B, N, M>        import "attestor_registry"<M>
  • core: claimToMessage returns the same seven fields, and the new keyless nullifierOf mirrors the circuit's nullifier.
  • The message carries V and B. The identity is hashed as a plain concatenation (136 + 9V + 17B bytes), so V = 34, B = 0 and V = 0, B = 18 can give two claims the same nullifier. A new test mock, MockAttestationLayout (V=0, B=18), shows that a signature made for the other layout is rejected.
  • Parity over random claims: a seeded generator (test/helpers/random-claims.ts, replay with THOTH_SEED) draws 200 claims per mock and per property. It holds claimToMessage and nullifierOf equal to the circuits on both mocks. fast-check is not used, because it is not a dependency on this base.
  • Tamper tests: any observation-identity field changed after signing is rejected with Insufficient valid signatures. That covers policyHash, subjectHash, salt, both window bounds, each value and flag, byte halves and byte flags, and appId (tested against a contract sealed to the changed id). A changed holder or version is rejected too.
  • Docs: ADR 0015, the wire layout (message and nullifier preimage) in the attestation.compact header and the DESIGN.md tables, the glossary, the kind author guide, AGENTS.md, and the contracts, core and cardano docs. There are changesets for contracts, core, zk-tls and cardano.

Evidence

npm run bench on a Ryzen 7 5700G (16 threads, 31 GiB), proof server 9.0.0, 3 warm proofs per circuit. The proof server verified every proof against its verifier key and refused a proof under the wrong one.

Before (feat/192-proving-benchmark):

Mock Circuit k Rows Proving key (MB) First (s) Warm (s) CPU/warm (s) Peak mem (MB)
mock_attestation verifyAttestation 17 90,590 197.2 12.20 9.27 74.9 3,162
mock_attestation openAndRead 14 8,610 24.6 1.53 1.15 10.3 422
mock_attestation openAndReadPresence 14 8,580 24.6 1.55 1.15 10.4 437
mock_attestation openAndRequireMetric0 14 8,570 24.6 1.56 1.15 10.5 446
mock_attestation openAndBindHost 14 14,633 24.6 1.61 1.22 10.8 446
mock_attestation_bytes verifyAttestation 17 94,609 197.2 12.43 9.34 75.1 3,166
mock_attestation_bytes openAndReadBytes 15 19,188 49.3 2.94 2.23 19.4 758

After (this branch):

Mock Circuit k Rows Proving key (MB) First (s) Warm (s) CPU/warm (s) Peak mem (MB)
mock_attestation verifyAttestation 15 23,107 49.3 3.26 2.54 20.6 749
mock_attestation openAndRead 14 8,610 24.6 1.58 1.16 10.4 433
mock_attestation openAndReadPresence 14 8,580 24.6 1.54 1.15 10.4 446
mock_attestation openAndRequireMetric0 14 8,570 24.6 1.54 1.16 10.4 434
mock_attestation openAndBindHost 14 14,633 24.6 1.60 1.22 10.8 447
mock_attestation_bytes verifyAttestation 15 26,930 49.3 3.30 2.58 20.9 754
mock_attestation_bytes openAndReadBytes 15 19,188 49.3 2.96 2.25 19.3 756

Both mocks are within the 32,768-row (k = 15) budget. The open circuits are unchanged because this ticket does not touch openClaim.

Tests:

layout binding
  ✓ builds two layouts whose claims share a nullifier
  ✓ signs a message that differs only in the layout fields
  ✓ accepts signatures over its own layout
  ✓ rejects signatures made for the other layout   // fails if the circuit drops V and B (mutation checked)
off-chain parity over random claims, numeric mock (V = 3, W = 0) / bytes mock (V = 3, W = 1)
  ✓ nullifierOf equals the circuit nullifier
  ✓ claimToMessage equals the circuit message
cross-seam acceptance (zkFetch) ✓   cardano cross-seam acceptance ✓

npm test:   Test Files 34 passed | 2 skipped (36), Tests 818 passed | 4 skipped (822)
npm run types: pass    npm run check: pass

No verification skill in this repo.

Merge Danger

Door: two-way

Nothing is deployed, and version stays 1 before launch, so this can be reverted. After a deploy, any change to the observation identity changes what attestors sign and needs a version bump (ADR 0015).

Blast Radius: breaking

Every signature made over the old message stops verifying. Embedding contracts drop the #K parameter (attestation<V, B, N, M>, attestor_registry<M>). zkFetch and Cardano attestors sign the new message through claimToMessage, so they need the matching contracts release.

Attestors sign seven fields: the version, the layout (V and B), and the
nullifier and the holder as two limbs each. Every other claim field
reaches the signature through the nullifier, which verifyAttestation
already computes, so the circuit no longer splits five 32-byte fields
into halves. The registry verifies seven fields, and the message length
is no longer a module parameter.

Core adds nullifierOf, the off-chain mirror of the circuit's nullifier,
and claimToMessage returns the same seven fields as buildMessage. The
parity tests hold both equal to the circuits over random claims.
@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

# Conflicts:
#	package.json
#	packages/contracts/README.md
#	packages/core/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