zorch.transcript¶
Fiat-Shamir transcript: the Transcript interface and a real duplex-sponge
implementation.
DuplexTranscript is the device-side duplex sponge (fixed-size buffers + position
scalars) — a JAX pytree whose state threads functionally under @jit, with no
host callback or zkVM FFI.
GrindError ¶
Bases: RuntimeError
Raised when a proof-of-work grind cannot run: the field is too wide for the uint32 search (needs x64).
Source code in zorch/transcript.py
33 34 35 | |
Transcript ¶
Bases: Protocol
Source code in zorch/transcript.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
field
property
¶
field: Any
The field one sample word is drawn from.
A challenge in another field is packed from consecutive words of this one, so how many words a challenge costs is a fact about the pair, not about the challenge field alone -- an extension-native sponge already yields an extension element per word.
DuplexState
dataclass
¶
Duplex-sponge state. Fixed-size buffers + position scalars: the buffers
keep observe's absorb a single lax.scan (compile size independent of input
length), and the constant shape makes the whole state a valid lax.scan carry.
Source code in zorch/transcript.py
139 140 141 142 143 144 145 146 147 148 149 150 | |
DuplexTranscript
dataclass
¶
Overwrite-mode duplex sponge implementing Transcript. A JAX pytree whose
state buffers are the leaves and whose permutation/rate are static, so
the whole transcript threads through @jit (and, later, a lax.scan carry).
No step crosses a zkVM FFI on any backend.
The fs backend (_DeviceFs / _HostFs) chooses where every absorb / squeeze
runs; pick one via new(..., fs_on_host=). Under _DeviceFs (the default)
every step is a device op and nothing calls back to the host. _HostFs is an
eager host primitive -- see the host-FS backend section below for what it
trades and why.
Source code in zorch/transcript.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 | |
fs_on_host
property
¶
fs_on_host: bool
Whether Fiat-Shamir runs on the host CPU — read off the fs backend.
Kept as a bool for callers (the sumcheck.prover gate, the consumer's
.new(fs_on_host=...)).
has_dedicated_fusion
property
¶
has_dedicated_fusion: bool
Whether the Fiat-Shamir permutation lowers to a dedicated fusion marker
a vendor can expand — the LogUp-GKR jagged prover's gate
(zorch.logup_gkr.jagged_prover) reads it to mark its sumcheck scan as one
register-resident kernel (mirrors Sponge/Compression). False for a test
CheapPermutation, so unit tests keep the plain scan.
observe ¶
observe(values: Array) -> DuplexTranscript
Absorb values (any field, flattened to the base field) into the
transcript. The absorb is one lax.scan over the flat input, so the
compiled graph size is independent of len(values).
Source code in zorch/transcript.py
314 315 316 317 318 | |
absorb_on_host ¶
absorb_on_host(*messages: Array) -> DuplexTranscript
Absorb messages in order through the CPU sponge, leaving the state
on the device it came from. Byte-identical to the same sequence of
observe calls -- the same _observe_body, only relocated.
The win is placement, not algorithm. A sponge on an accelerator runs one warp-cooperative permute per rate-block, where ~21 rounds of full-warp shuffle latency dominate a few hundred field ops; a CPU pays none of that. Measured on koalabear16 at rate 8: 5.4 us per permutation on an RTX 5090 against 1.0 us on the host. Two host crossings are not worth a short message, so the caller applies its own length threshold -- the call site is where the message length that justifies relocating is known.
Variadic because the crossing, not the absorb, is the repeated cost: a Fiat-Shamir step is usually several messages in a fixed order (a length prefix, then its payload), and absorbing them one call at a time drags the state back to the device between each. The whole sequence costs one round trip.
Only THIS absorb relocates; fs still decides where the stream runs.
Eager only -- it moves buffers across the host boundary, so it cannot
run inside a traced region; observe is the in-graph form.
Source code in zorch/transcript.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | |
observe_and_sample ¶
observe_and_sample(
values: Array, n: int = 1
) -> tuple[DuplexTranscript, Array]
Absorb values, then squeeze n challenges — the per-round
Fiat-Shamir primitive (commit -> challenge). One method so the absorb and
squeeze fuse into a single kernel under @jit by construction, never by a
per-primitive pattern-match (the repo's fusion contract).
Source code in zorch/transcript.py
393 394 395 396 397 398 399 400 | |
check_witness ¶
check_witness(
witness: Array, *, pow_bits: int
) -> tuple[DuplexTranscript, Array]
Observe witness, squeeze one challenge, and report whether its low
pow_bits canonical bits are zero -- the verifier-side proof-of-work
check, and the predicate grind searches against. witness must be a
scalar element of the transcript's field -- the domain grind
enumerates -- so the verifier accepts exactly the witness space the
prover searched (observe itself would bitcast-flatten any array).
Fully jit-traceable, so a verifier runs it inside its own @jit zone.
Returns the advanced transcript (observe + one sample applied), so prover
and verifier reach the same state from the same witness.
Source code in zorch/transcript.py
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 | |
grind ¶
grind(
pow_bits: int, *, chunk: int = _GRIND_CHUNK
) -> tuple[DuplexTranscript, Array]
Find a proof-of-work witness and return the transcript advanced past
it via check_witness, so a verifier replaying it reaches the same state.
Searches canonical witnesses for the lowest whose squeezed challenge has
pow_bits zero low bits. Jit-traceable and does not raise on an exhausted
search: check_witness is the soundness gate, so which witness the search
returns is soundness-neutral.
Source code in zorch/transcript.py
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 | |
reinterpret_challenge ¶
reinterpret_challenge(raw: Array, dtype: Any) -> Array
Reinterpret consecutive transcript squeezes raw as one dtype challenge:
the identity when dtype is the transcript's own field, else the extension
element whose coefficients are the squeezes. The single definition of the
limbs/dtype packing -- shared by sample_challenge and the sumcheck scan
driver so a prover and its verifier dual cannot drift.
Fails loud on a packing mismatch: the squeezes are already consumed, so silently truncating to the first element would leave the stream advanced past a challenge nobody received. The check runs at trace time (shapes are static), so jitting does not cost the loud failure.
Jitted because these three ops are called eagerly once per FS squeeze, and unjitted each one launches its own kernel -- loose single-op dispatch that dominates a warm prove.
Source code in zorch/transcript.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
sample_challenge ¶
sample_challenge(
transcript: TranscriptT, dtype: Any, limbs: int = 1
) -> tuple[TranscriptT, Array]
Squeeze one challenge of dtype as limbs transcript samples.
A transcript squeezes elements of its own field; a challenge field that
extends it takes limbs consecutive squeezes reinterpreted as the
extension element's coefficients (limbs == 1 with the transcript's own
field is the identity reinterpret, via reinterpret_challenge). Module-level
so a prover, its verifier dual, and any binding glue derive challenges from
one definition -- a drift would desynchronize their Fiat-Shamir streams.
Source code in zorch/transcript.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
observe_and_sample_marked ¶
observe_and_sample_marked(
t: DuplexTranscript, values: Array, n: int
) -> tuple[DuplexTranscript, Array]
observe_and_sample under a zorch.duplex_fs fusion marker so a vendor
fuses the ~9-kernel hop (two permutes + duplex glue) into one register-resident
kernel. Only a dedicated-fusion permutation is marked, so a test
CheapPermutation keeps the plain path.
Source code in zorch/transcript.py
809 810 811 812 813 814 815 816 817 818 | |