Skip to content

feat(contracts,client)!: the registry checks the N named signatures - #321

Draft
nicolasLuduena wants to merge 14 commits into
feat/313-whole-byte-slotsfrom
feat/314-n-named-signatures
Draft

nicolasLuduena wants to merge 14 commits into
feat/313-whole-byte-slotsfrom
feat/314-n-named-signatures

Conversation

@nicolasLuduena

@nicolasLuduena nicolasLuduena commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Closes #314
Closes #309

PR 6 of 6 of spec #309, stacked on #320 (feat/313-whole-byte-slots).

Summary

The registry checks only the N signatures the prover names. Before, it checked one signature for each of the M slots. Each signature is still verified with the standard library's jubjubSchnorrVerify. The slots are private inputs.

 verifyAttestation
-  [claim, sigs] = getAttestationWitness()          // sigs: Vector<M, JubjubSchnorrSignature>, dummies in unsigned slots
+  claim = getAttestationWitness()                  // the claim only; openClaim reads just this
   ...
-  assert countValidSignatures(msg, sigs) >= N      // M verifies
+  requireSignatures<N>(msg, getSignatures())       // Vector<N, { registryIndex: Uint<16>, signature }>
+    assert slots strictly increase                 "Registry slots not increasing"
+    assert last slot < M                           "Registry slot out of range"
+    ks = keys                                      // read every key, whichever slots are named
+    for each s: key = keyAt(ks, s.registryIndex)   // fold over all M slots
+      assert key != empty                          "Empty registry slot"
+      assert jubjubSchnorrVerify<7>(msg, s.signature, key)   "Insufficient valid signatures"

What the client hands over:

const { claim, collected } = await client.collect(...);   // exactly `threshold`, sorted by slot
getAttestationWitness → toContractClaim(claim)
getSignatures        → slotSignaturesOf(collected)          // new in @txpipe/thoth-client; RangeError on a repeated slot or one outside [0, 65535]
  • Tests: new named signatures suite in registry.test.ts, the client's slot-signatures.test.ts, and every other suite moved to the named shape (atSlots, signClaim with null for a slot that does not sign). The two acceptance tests use slotSignaturesOf; the benchmark's captures build the same named entries with the test helpers signClaim and atSlots.
  • Docs: ADR 0017, plus a status line on ADR 0016. Also the glossary's registry, threshold, registry slot and attestment entries, the registryIndex invariant and mock descriptions in AGENTS.md, DESIGN.md, the kind author guide, the root, contracts, client and zk-tls READMEs, and both kinds' dApp guides.
  • Changesets: contracts (minor), client (minor) and zk-tls (patch, README only).

Evidence

  • Before: the registry verified all M slots and counted the valid ones, so a dApp had to send a dummy for each slot that did not sign.
    After: exactly N signatures from distinct slots, with no dummy, for 2-of-3:
registry.test.ts > named signatures
  ✓ accepts exactly N signatures from slots 0 and 1 / 0 and 2 / 1 and 2, with no dummy
  ✓ rejects a repeated slot                                  → "Registry slots not increasing"
  ✓ rejects slots out of order                               → "Registry slots not increasing"
  ✓ rejects the highest slot followed by slot 0              → "Registry slots not increasing"
  ✓ rejects an empty slot, even with a signature that verifies for the empty key → "Empty registry slot"
  ✓ rejects the out-of-range slot 3 / 255 / 65535            → "Registry slot out of range"
  ✓ rejects a valid signature presented under another slot  → "Insufficient valid signatures"
  ✓ rejects two valid signatures swapped between their slots → "Insufficient valid signatures"
  ✓ rejects 1 / 3 signatures where the threshold is 2        → witness type error
  ✓ discloses nothing that depends on which slots signed     (slots {0,1} vs {1,2}: same public transcript, input and output)

npm test: 849 passed, 4 skipped (the opt-in live checks), both acceptance tests included. npm run types and npm run check pass, and the pre-push hook ran the whole suite green.

Privacy, checked on the compiled circuit, not only the source. I wrote a taint pass over each circuit's zkir. It marks the getSignatures private inputs (%sigs.*) and follows them through every instruction. In both mocks' verifyAttestation, it finds 6 signature inputs and 64 values that depend on them. None of those values reaches an impact (a ledger operation), a public_input or a guard. The open circuits have no signature inputs at all. As a control, I compiled a throwaway copy that writes a slot to a ledger field, and the pass flagged two impacts there. The generated contract code reads keys once, as a whole vector. In the simulator, two submissions of one claim from slots {0,1} and {1,2} produce identical publicTranscript, input and output (the last test above).

Benchmark (npm run bench under the prove lock; Ryzen 7 5700G, 16 threads, proof server 9.0.0, 3 warm proofs). Every circuit of both mocks proved, and the proof server verified each proof. It refused a proof under the wrong verifier key. No open circuit crashed the prover: they still hold the hashToCurve vault pseudonym.

Before (#320):

Mock Circuit k Rows Proving key (MB) Warm proof (s) CPU per warm proof (s) Peak memory (MB)
mock_attestation verifyAttestation 14 13,646 24.7 1.46 11.4 430
mock_attestation openAndRead 13 6,657 12.3 0.65 6.0 251
mock_attestation openAndReadPresence 13 6,627 12.3 0.66 6.0 237
mock_attestation openAndRequireMetric0 13 6,617 12.3 0.66 6.0 249
mock_attestation openAndBindHost 14 12,680 24.6 1.22 10.8 448
mock_attestation_bytes verifyAttestation 14 15,593 24.7 1.53 11.6 465
mock_attestation_bytes openAndReadBytes 14 8,626 24.6 1.15 10.4 454

After (this PR; also in the contracts README's "Proving cost"):

Mock Circuit k Rows Proving key (MB) Warm proof (s) CPU per warm proof (s) Peak memory (MB)
mock_attestation verifyAttestation 14 12,177 24.7 1.38 11.3 444
mock_attestation openAndRead 13 6,639 12.3 0.65 6.0 229
mock_attestation openAndReadPresence 13 6,609 12.3 0.66 6.0 235
mock_attestation openAndRequireMetric0 13 6,599 12.3 0.66 6.0 235
mock_attestation openAndBindHost 14 12,662 24.6 1.21 10.8 448
mock_attestation_bytes verifyAttestation 14 14,123 24.7 1.43 11.5 462
mock_attestation_bytes openAndReadBytes 14 8,608 24.6 1.16 10.4 426

verifyAttestation drops by 1,469 rows on the numeric mock and 1,470 on the bytes mock. The bytes mock now has 2,261 rows of headroom under 16,384, where it had 791. Each open circuit loses the 18 rows its unused signature inputs cost. Proof size is 5,772 B throughout.

The spec's row targets, with the final numbers:

Circuit Spec's "today" Target Final
verifyAttestation, both mocks 90,610 and 94,629 (k = 17) at most 16,384 (k = 14) 12,177 and 14,123 (k = 14)
openAndRead, openAndReadPresence, openAndRequireMetric0 about 8,600 (k = 14) at most 8,192 (k = 13) 6,639, 6,609, 6,599 (k = 13)
openAndReadBytes 19,188 (k = 15) at most 16,384 (k = 14) 8,608 (k = 14)

No verification skill in this repo.

Not verified: the live zkFetch and Cardano checks (opt-in, need real witnesses or endpoints). I also did not test, at the prover level, a signature whose response is malleated past the Jubjub order. The client and the circuit both use the standard library's verify, and the simulator accepts exactly what jubjubVerifier accepts in the acceptance tests.

Merge Danger

Door: two-way

Nothing is deployed and the claim's version stays 1. Reverting restores the per-slot registry.

Blast Radius: consumers

Every dApp's witnesses change: getAttestationWitness returns only the claim, and a new getSignatures returns exactly N { registryIndex, signature } entries in slot order. A contract compiled from this release rejects the old [claim, Vector<M, sig>] witness at the type check. One invalid signature now fails the proof instead of not being counted, so threshold must equal the contract's N.

The registry verifies exactly N signatures, each with the standard library's jubjubSchnorrVerify against the key of the registry slot it names, instead of one signature per registry slot. Slots must strictly increase, be in range and hold a key; the key is selected by reading every slot, so the proof does not reveal which attestors signed. The signatures move to their own witness, getSignatures, so the open circuits no longer take them.
@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

/// ledger operation depends on which slots are named.
export circuit requireSignatures<#N>(msg: Vector<7, Field>, sigs: Vector<N, SlotSignature>): [] {
// order[1] is one past the last slot seen; a Uint<17> holds 65,536.
const order = fold((acc: [Boolean, Uint<17>], s: SlotSignature) =>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For N = 0 the fold returns [true, ...] allowing an unsigned claim to be vaulted.
Proposed fix: assert(N > 0, "Threshold must be positive"); either here or on initRegistry to fail on deploy.

…ures

# Conflicts:
#	packages/client/README.md
#	packages/contracts/README.md
#	packages/zk-tls/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.

2 participants