zorch.grind¶
Proof-of-work grind search: the lowest counter whose candidate passes.
One engine for every transcript's grind. Each lax.while_loop step tests a
window-wide counter batch IN PARALLEL through the caller-supplied predicate
and keeps the lowest-index hit; the loop tiles windows only because the full
space cannot be tested at once, and it early-exits at the first window that
hits — for a typical difficulty the hit is in the first window, so the loop
runs once. What "candidate" means is the caller's: the algebraic duplex checks
the challenge its observe+sample induces, a byte-framed transcript checks the
digest of a pre-image built from state_digest and the counter. On exhaustion
the trailing fallback 0 is returned unchecked — the caller's verify/check-witness
is the soundness gate, so which counter the search returns is soundness-neutral
(the DuplexTranscript.grind contract).
leading_zero_bits_ok ¶
leading_zero_bits_ok(digests: Array, bits: int) -> Array
Whether each digest (uint8 [B, digest_size]) has >= bits leading zero
bits, big-endian (digest[..., 0] most significant). Lives here for the same
reason the search does: it is the predicate every byte-framed transcript's
check_batch ends in, whatever hash built the digest. Traceable, so it
composes into the search's one device program; byte-identical to
byte_transcript._leading_zero_bits_ok, its host twin.
Source code in zorch/grind.py
28 29 30 31 32 33 34 35 36 37 38 39 40 | |
grind_search ¶
grind_search(
check_batch: Callable[[Array], Array],
bound: int,
window: int = GRIND_WINDOW,
) -> Array
Lowest uint32 counter in [0, bound) for which check_batch reports a
hit. check_batch: uint32 [window] counters -> bool [window], pure and
traceable — the search is jit-composable and runs as one device program.
bound caps base so base + window cannot wrap uint32.
Source code in zorch/grind.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |