Portable garbled-circuit function benchmark

This dedicated canister measures the reusable garbled-circuit function core, using the canonical wasm64 typed-root SDK startup and the existing factory PocketIC helpers. It has no game, application, secret-storage contract or two-party network protocol. Fixtures are transient and disappear on restoration.

Run from the newstack root after integrating the explicit benchmark package in benches/crypto/Cargo.toml and resolving its lockfile. The caller must own its Cargo target exclusively; the script never chooses a shared target for the caller.

source tools/env.sh
npm ci --ignore-scripts --prefix tests/pocketic
cargo fetch --manifest-path benches/crypto/Cargo.toml --locked
cargo fetch --manifest-path cdk-rsx/crates/crypto/vendor/blake3/Cargo.toml --locked
GC_PRG_VARIANTS='control selected' CARGO_TARGET_DIR=/absolute/exclusive/gc-target \
  bash benches/crypto/garbled-circuit/run.sh \
  /absolute/fresh/gc-run \
  /absolute/qualified/pocket-ic

The default server is the frozen normal13 binary with SHA-256 6a9a75ad9b4551d2b0f4a0d954ffb8bd5bbd0ebc44ac00290679b06ad0b2f8e6. The runner validates that identity through the factory session helper, starts its own server and instance, and shuts down only that owned session. It stores the exact computation catalog and server settings in the result receipts.

run.sh runs the core's ordinary, instrumented and optimized native tests, the three compact-prefix vendor tests with the pinned upstream Rust reference, the benchmark Wire-bound test and host matrix tests. It builds the native reference with --cfg aes_force_soft, uses the shared native receipt tool to record its binary/source/lockfile/compiler hashes, checks all 65,536 native equality pairs with distinct public query domains, then builds and measures a fresh primary artifact with no instrumentation. Finally it builds a separate instrumented image and checks actual Wasm structure counts without emitting primary performance rows. The default primary run takes two independently staged samples per body and per empty harness. --samples 3 is available on the host runner. All artifact/result directories must be fresh.

The canonical builder supplies the startup transform, bounded Wire interface, source archive, optimized Wasm, DWARF and origin sidecars. The host verifies every canonical output and archived source with the existing factory artifact helper. Its result-local .generated/ contains this artifact's exact generated codec, the unchanged factory Wire adapter, and the factory artifact helper with only that adapter's import path remapped. The host records the original and copied hashes. Shared host .generated/ directories are never changed or required.

The matrix contains 91 actual populations: 49 GC/BLAKE3 rows, 24 separately named stream-PRG rows, nine general-key AES32 rows and nine independent-secret batch rows. Original case identities and labels remain stable.

Function Actual batch/fill sizes
XOR, GF doubling, public-zero-key AES context construction, cached AES block, gate hash, AND garbling, AND evaluation 1, 100, 1000 operations
BLAKE3 PRG stream fill 16, 128, 1024, 65536, 1048576 bytes; one fill
Cold PRG construction, cached seed/session owner construction, cached owner per-query stream construction 1, 100, 1000 constructors
Derive one 32-byte secret from one shared prepared seed/session prefix 1, 100, 1000 distinct query IDs
One frozen-BLAKE3 PrgSession::fill_secrets call 1, 100, 1000 independent 32-byte outputs
Eight-bit equality garbling and evaluation, each reported separately 1, 10, 100, 1000 distinct queries
Each independent ChaCha8/ChaCha12/ChaCha20-control profile, shared-session stream plus actual fill32 1, 100, 1000 distinct query IDs
Each independent ChaCha8/ChaCha12/ChaCha20-control profile, prepared-stream fill 16, 128, 1024, 65536, 1048576 bytes
General-key fixslice32 AES, one/two/four actual blocks per invocation 1, 100, 1000 invocations

The recommended command measures the scalar reference, a fresh SIMD-AES/PRG control and the matching selected image with aes-narrow, then checks a separate selected instrumented image. All 91 populations execute at their actual sizes. Both matched images enable prg-query-batch, including its measured cutoff. An empty GC_PRG_VARIANTS value runs only the scalar reference. Optional prg-simd and prg-xof4 variants inspect BLAKE3 expansion independently. See the generated comparison. The feature lists in run.sh were updated after the recorded round5 measurements to match their actual paired images. The component native, canonical-build and runner commands were qualified; this updated packaging script has not been rerun as a complete command.

Each control and each sample starts with a separate setup update using the recorded public fixture seed, then executes exactly one run update. No smaller batch is extrapolated. Primitive operands, query seeds/identities, Alice/Bob inputs, cached hashers, evaluator garblings and PRG state are staged outside the body interval. Inputs change with the query/operation index and pass through runtime black_box; complete outputs remain observable. Primitive vectors use compact typed storage: XOR/GF/AES/hash input pairs occupy 32 bytes per operation and outputs occupy 16 bytes, without strides across unrelated secret owners. AND and equality use their own typed input and output vectors.

Counter 0 includes the synchronous typed kernel, runtime input barriers, output writes and faults between probes. It excludes output-vector allocation/zeroing, checksumming and verification. AES context construction measures construction and retention of the fixed public all-zero-key schedule; this is not generic runtime-secret key expansion. The constructor's encryption/check/drop occurs after the body counter. Cached AES block/hash/AND rows exclude construction. PRG fill excludes PRG construction. Equality garbling includes fresh per-query PRG construction and the entire garbling operation using a cached AES context. Borrowed equality evaluation excludes BobQueryState construction/drop and OT.

The default core feature set remains scalar. Canister feature prg-simd explicitly enables core wasm-simd and the vendored BLAKE3 SIMD compression; prg-xof4 additionally enables the separately gated four-lane XOF output kernel. Every row records the artifact's actual feature list and named variant. These variants must produce the exact same bytes as the scalar native reference. --cases prg-fill selects only the five stream-fill sizes for matched builds. The script can build both PRG variants and their constructor/secret cases, plus the complete control and selected matrices. Each uses two fresh samples. Set GC_PRG_VARIANTS='' to run only the fixed scalar default baseline.

prg-init measures cold Prg::new, retaining each resulting stream until its 16-byte post-counter verification. prg-session-init separately measures PrgSession::new(seed, session), which caches the derive-key seed/session prefix. prg-session-stream stages those private owners, then measures only each per-query .stream(query, purpose) construction. All constructor outputs are filled and checked against ordinary cold Prg::new after the counter stops; this verification, subsequent filling and owner cleanup remain in the complete message total. The existing prg-fill fixture and its stream bytes are unchanged. The constructor-only prg-session-stream cohort uses one distinct staged private prefix per operation, measuring isolated prepared-prefix derivation. prg-secret32 instead prepares one shared private prefix, then constructs a stream, fills a packed 32-byte output and drops the stream for each distinct query inside the body interval. It verifies every byte after timing. This includes the deferred hashing work that a constructor-only result does not measure.

prg-batch-secret32 uses the identical frozen-BLAKE3 seed/session, query IDs, purpose and packed output shape. Its body makes one PrgSession::fill_secrets call for all actual outputs, including batch scratch cleanup. Cold Prg::new references and checks remain outside the counter and inside whole updates. Canister prg-query-batch enables core wasm-query-batch and the vendor's prepared_query_batch; feature-off controls use single-query readers through the same API. This batches independent queries, while prg-xof4 expands one stream. Both preserve the frozen GC byte contract. The SIMD build now retains single-query readers for lengths one through six; seven is the crossover selected from actual small-batch measurements. Fresh target N=1/100/1000 measurements qualify that dispatch without extrapolation.

Every run, including instrumented correctness-only images, first executes a separate bytewise XOF qualification endpoint. The scalar native reference freezes 64 full expected outputs covering ordinary, keyed and derive-key BLAKE3 modes; messages of 0/1/63/64/65/73/1023/1024/1025 bytes; outputs of 0/1/63/64/65/255/256/257/272/511/512/513/1024/4097 bytes; offsets 0 through 31; single fills and chunks of 1/16/63/64/65/257 bytes; unaligned positions, low 32-bit block-counter carry and positions ending at u64::MAX. Native checks also compare each chunked result with one full fill. The host splits these into updates with at most 64 cases and 24 KiB output, checks all output bytes, both canary regions and final positions, and retains each complete trace. Native JSON encodes positions as decimal strings and the host converts them to BigInt before Wire encoding. This probe does not alter the production PRG position API.

PRG transcript checksums now use order-sensitive FNV-1a after the body counter; a regression check swaps two 64-byte blocks. These checksums remain diagnostics: the independent scalar full-byte XOF corpus qualifies the SIMD/XOF4 transport paths. Earlier frozen scalar result files retain their original checksums; new cost comparisons require fresh matched scalar and optional-feature artifacts.

The new cdk-rsx-crypto-prg profiles are independent application PRGs. game-prg-chacha8-v1, game-prg-chacha12-v1 and control-prg-chacha20-v1 each derive one session key with its own explicit BLAKE3 context, then use LE64(query) || purpose || [0;3] as the IETF nonce. Their .secret32 cases include stream construction, actual overwrite of all 32 output bytes and stream cleanup inside the body. Their .fill cases stage the stream and output capacity separately. Session-key derivation stays in setup. These rows report their own profile_id and key_context, suite_id: null and gc_suite_compatible: false; their bytes do not implement the frozen BLAKE3 GC randomness contract. ChaCha8/12 are explicitly reduced-round profiles whose security margin needs a separate application decision. This fixture creates no game, application protocol, entropy source or TEE boundary.

Every application-PRG performance checksum is checked natively against maintained RustCrypto ChaCha core blocks with independent key/nonce framing. An actual-Wasm 50-case bytewise probe covers every profile, varying query/purpose, offsets 0 through 31, nonzero destination bytes, chunking, random-access positions, the last complete/partial block and the exhausted 2^38-byte IETF window. An over-limit fill must reject atomically with the original bytes and position intact. Native JSON preserves query/position values as decimal strings; the host compares every returned byte, canary, verdict and final position before cost capture.

The cdk-rsx-crypto-aes direct cases use profile rustcrypto-aes128-fixslice32-v1 with a separately staged general key. aes32-block uses one real block and the backend's one zero dummy lane; aes32-pair processes two real blocks in one pair; aes32-four processes four real blocks in two pairs. Rows report actual block width and logical_block_count = batch * width, with both per-invocation and per-block costs. No dummy lane is counted as a real block. All native outputs are checked with the separate RustCrypto AES software64 backend, and a 32-case actual-Wasm full-byte probe includes FIPS197 and varying general keys for every real width. These generic primitive rows also have their own profile identity; GC rows retain the GC construction identity when selecting an equivalent AES backend. The old GC AES32 selector was discarded after measurement. The aes-simd feature selects eight-lane Boolean AES; batched-aes alone is the AES64 control. The generic AES32 primitive and its nine cost rows remain a separate reference. aes-narrow selects byte-vector one/two/four-block methods and keeps Boolean eight-block batches. Its constant-time claim requires supported-engine hardware register-swizzle lowering. The unchanged 32-record target probe checks 1,792 repeated API block results across 256 distinct key/input pairs, including borrowed/in-place narrow methods; these are correctness checks, not generic secret-key performance claims.

The post-counter checks consume every output. AND garbling checks all four Boolean inputs per generated gate; equality compares its decoded answer with cleartext equality. Every primary Wasm sample must match every checksum from the native portable build. A separate 1024-pair actual Wasm probe checks cleartext equality and native label checksums. That shared-Rust target differential does not replace the core's independent fixtures and known-answer tests.

The empty harness separately writes changing index labels into compact output slots. It is a diagnostic loop control, not an exact model of every typed kernel's overhead. raw_cost is the median body counter; harness_cost is the separate control median; adjusted_cost is their signed difference for diagnostic use only. The report preserves all samples and the authoritative complete whole-message instruction total, discarded-attempt accounting and page fees. Whole messages include Wire decoding/replies, root entry, all allocation, verification, checksumming and cleanup. No page fee is subtracted.

results.json, rows.jsonl and results.csv contain the required suite/source/ artifact/runtime, party/stage/population, OT-count, instruction, payload, memory and sample fields. suite_id is BLAKE3 of the core's frozen suite.txt bytes; suite_name is a readable fixture name. Each measured function also has a separate empty-harness row. Raw compressed traces, exact cycle snapshots, setup captures, binary/catalog receipts, native reference and installation hashes remain available. Trace incompleteness stops the run and preserves its bytes. An operation failure produces FAILED/PARTIAL, never a successful smaller row.

The 352-byte Alice garbling consists of 128 bytes of active Alice labels and 224 bytes of half-gate tables; the Bob return label is 16 bytes. These exact logical value sizes are reported separately. No transport executes in this function fixture, so sent/received payload and framing bytes and rounds are null. Peak heap bytes are null: page-authority committed capacity is recorded separately and is not a peak-live-heap measurement. Required wall-time median and p95 are also null; two/three memory-traced IC samples do not satisfy a separate 30-sample runtime-timing measurement. Host actor-call durations remain explicitly named diagnostics, including Wire work, ingress polling and tracing.

This IC fixture executes no base OT or chosen OT. Pinned portable/WASI OT qualification exists separately under ot-reference; IC backend integration and the full IC private protocol remain blocked. Local selection of Bob's labels occurs only in staging or semantic checks and is never called OT. The report emits 52 explicit BLOCKED rows covering both parties, base OT cold/warm, chosen OT of 8/80/800/8000 logical transfers, and corresponding full-protocol equality queries in cold/warm/preprocessed contexts. Unmeasured costs, generated/ check/base-OT counts, communication, rounds and memory remain null, never zero. A passing gate-only run does not qualify a complete private equality protocol.

To inspect the matrix without compiling or starting a server:

node benches/crypto/garbled-circuit/run.mjs --dry-run
node --test benches/crypto/garbled-circuit/matrix.test.mjs

To repeat only structural checks against a separately built counter artifact, pass --correctness-only --instrumented to the host runner. The primary runner rejects instrumented artifacts. Its actual Wasm probe requires 28 Alice hashes, 14 Bob hashes, seven ANDs and eight XORs/NOTs per party per query.

The game-prg-simd canister feature selects actual Wasm SIMD128 for the separately named ChaCha profiles. One-block row SIMD and four-counter bulk SIMD preserve their scalar bytes. Its full-byte checks include the final four counter blocks and terminal rejection. The standard scalar control and optimized GC image remain separate. Session preparation and private entropy acquisition are not included in prepared-stream fills.

For bounded source profiling, use --profile-case ID,ID with selected cases. Only the first actual N1000 body for each named case is profiled; normal controls and other samples remain separate. The runner saves complete IC charge ledgers and symbolizes prepaid block boundaries against the matching canonical source/ DWARF sidecars. Those locations are not instruction charges for individual lines. Profiles cover the entire checked update, including post-counter checks.

Independent-secret batches use Session::fill_secrets once for all outputs, with nine explicit .batch-secret32 populations. Their expected bytes match ordinary per-query streams and an independent native oracle. A separate 68-case target probe retains the first 51 standalone cases and appends 17 frozen-GC BLAKE3 cases. It checks full outputs, partial vector groups, query carries, u64 exhaustion, unchanged-buffer rejection and canaries. General-key SIMD AES constructor/eight-lane target checks run alongside the generic AES reference probe; this is distinct from public-zero-key GC context setup.