Skip to content

feat(contracts,core)!: carry each byte slot as one Bytes<32> with one flag - #320

Draft
nicolasLuduena wants to merge 7 commits into
feat/312-nullifier-keyed-vaultfrom
feat/313-whole-byte-slots
Draft

nicolasLuduena wants to merge 7 commits into
feat/312-nullifier-keyed-vaultfrom
feat/313-whole-byte-slots

Conversation

@nicolasLuduena

Copy link
Copy Markdown
Member

Closes #313
Part of #309

PR 5 of 6, stacked on #319.

Summary

A byte slot now travels as one Bytes<32> with one presence flag. It is no longer two Bytes<16> halves with two flags. A predicate compares the slot directly.

-module attestation<#V, #B, #N, #M>          // #B = 2W byte halves
+module attestation<#V, #W, #N, #M>          // #W = byte-slot count
 struct Claim / Observation {
-  bytePresent: Vector<B, Boolean>;          // one flag per half
-  byteHalves:  Vector<B, Bytes<16>>;
+  bytePresent: Vector<W, Boolean>;          // one flag per slot
+  byteValues:  Vector<W, Bytes<32>>;
 }
-message[2] = B                              // half count
+message[2] = W                              // byte-slot count
-nullifier preimage: 136 + 9V + 17B bytes
+nullifier preimage: 136 + 9V + 33W bytes
 absent byte slot must be all zero ("Absent slot has nonzero value")

 // MockAttestationBytes.openAndReadBytes
-assert(Bytes[...c.byteHalves[0], ...c.byteHalves[1]] == expected, ...);
+assert(c.byteValues[0] == expected, ...);

What else changes:

  • @txpipe/thoth-core: ContractClaim and toContractClaim drop the halves, nullifierOf hashes each value whole, and claimToMessage signs W.
  • Kinds: zkFetch and Cardano build claims through core. Their byteSlots docs now say #W.
  • Mocks: the numeric mock is <3, 0, 2, 3>, the bytes mock <3, 1, 2, 3> and the example app <3, 1, 2, 3>.
  • Cross-layout test: it now pairs the layout mock (V = 0, W = 3) with a V = 11, W = 0 claim. Both identities are 99 bytes after the common fields.
  • Parity: the properties also run over the layout mock, so slot order across several byte values is checked.
  • Docs:
    • ADR 0009 gets a shape note. ADR 0015's status line points to it.
    • The wire layout is updated in both places, the attestation.compact header and docs/DESIGN.md.
    • Also updated: the glossary's byte slot entry, the contracts and core READMEs, the kind author guide and both kinds' dApp guides.
  • Changesets: contracts, core, and zk-tls with cardano.

Evidence

npm run bench (Ryzen 7 5700G, proof server 9.0.0, 3 warm runs). The proof server verified every proof against its verifier key and refused a proof under the wrong verifier key.

Mock Circuit k before Rows before k after Rows after Key after (MB) Warm after (s) Peak mem after (MB)
mock_attestation verifyAttestation 14 13,646 14 13,646 24.7 1.46 430
mock_attestation openAndRead 13 6,657 13 6,657 12.3 0.65 251
mock_attestation openAndReadPresence 13 6,627 13 6,627 12.3 0.66 237
mock_attestation openAndRequireMetric0 13 6,617 13 6,617 12.3 0.66 249
mock_attestation openAndBindHost 14 12,680 14 12,680 24.6 1.22 448
mock_attestation_bytes verifyAttestation 14 15,599 14 15,593 24.7 1.53 465
mock_attestation_bytes openAndReadBytes 15 17,236 14 8,626 24.6 (was 49.3) 1.15 (was 2.19) 454 (was 757)

Both row budgets are met: openAndReadBytes is at most 16,384 rows, and verifyAttestation is at most 16,384 on both mocks. The bytes mock's verifyAttestation still has only about 790 rows to spare, and #314 is what widens it.

New simulator checks in bytes.test.ts:

absent byte slot whose only non-zero byte is 0 / 19 / 31   → rejects "Absent slot has nonzero value"
openAndReadBytes with the matching value                    → accepts
openAndReadBytes with byte 0 / 19 / 31 flipped, or reversed → rejects "byteValue[0] mismatch"
byte 0 / 19 / 31 changed after signing                      → rejects "Insufficient valid signatures"
npm test       Test Files 34 passed | 2 skipped (36)   Tests 828 passed | 4 skipped (832)
npm run types  ok
npm run check  ok

Both acceptance tests pass, for zkFetch and for Cardano. Two pins are regenerated: the core nullifierOf literal, taken from the compiled bytes mock, and the two Cardano message strings.

No verification skill in this repo.

Merge Danger

Door: two-way

The repo has no deployed layout, so version stays 1. Revert by reverting the PR.

Blast Radius: wire-format

Every message and nullifier for a claim with a byte slot changes. Contracts embedding attestation<V, B, …> must change to <V, W, …>, and a predicate that reassembled halves must compare byteValues[i] instead. Kinds and the contract have to move together, which the changesets say.

… flag

The attestation module takes <#V, #W, #N, #M>: #W is the byte-slot count, and
Claim and Observation carry byteValues: Vector<W, Bytes<32>> with one
bytePresent flag per slot. The message signs W, the nullifier hashes each
value whole (136 + 9V + 33W bytes), and an absent byte slot must be all zero.
A predicate compares o.byteValues[i] to a Bytes<32> directly, so
openAndReadBytes no longer reassembles halves.

Core's ContractClaim, toContractClaim, nullifierOf and claimToMessage follow.
The cross-layout mock moves to V=0, W=3 against V=11, W=0, and the parity
properties also run over it.
… cost

The README embeds attestation<#V, #W, #N, #M>, compares byteValues[i] directly and drops the unpaired-flags limit. The proving-cost table is regenerated from npm run bench: openAndReadBytes proves at k = 14 (8,626 rows, was 17,236 at k = 15).
ADR 0009's shape note records why a byte slot is one Bytes<32> with one flag, and ADR 0015's status line points to it. The wire layout in DESIGN.md, the glossary's byte slot entry, the kind author guide and the kinds' dApp guides use #W and byteValues; the cross-layout pair is V = 11, W = 0 against V = 0, W = 3.
@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

Name the message's third field W in the numeric mock's layout test.
…e-slots

# Conflicts:
#	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