Repository navigation
feat(avm): BLAKE3COMPRESSION opcode for pq1-fr hashes in public code - #25923
zac-williamson wants to merge 7 commits into
Conversation
…(PLAN H4a) New AVM opcode BLAKE3COMPRESSION, wire byte 68 (appended; no opcode moves), operands [Indirect8, output U16, cv U16, block U16, params U16], all inputs u32-tagged: cv [u32; 8], block [u32; 16], params [counter_lo, counter_hi, block_len, flags]; writes the 8-word chaining value v[i] ^ v[i + 8]. Range and tag failures halt exceptionally in the same order as SHA256COMPRESSION. Gas AVM_BLAKE3COMPRESSION_BASE_L2_GAS = 5440 (SHA256COMPRESSION's 12288 times the measured cost ratio 1800 / 4067 x86 instructions per compression). - avm-transpiler: ForeignCall aztec_blake3Compression -> BLAKE3COMPRESSION, with input/output shape asserts and unit tests. - aztec-rs: aztec_crypto::blake3_compression (ZisK BLAKE3F precompile in zisk guests), the simulator opcode, tests against the official blake3 crate, negatives (tags, out-of-range, gas), and an end-to-end test that runs transpiled Noir (aztec-nr's pq1-fr hint) on the simulator and matches vectors.json's NOTE_HASH_NODE. - barretenberg vm2 (C++ fast simulator): opcode enum, wire format, spec, gas and Execution::blake3_compression over bb's BLAKE3 rounds; compression unit test. The full bb build was not run here. - constants.nr: AVM_BLAKE3COMPRESSION_BASE_L2_GAS; generated.rs regenerated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…f 3,130 AVM instructions per one-block pq1-fr hash)
- Execution::blake3_compression on a real memory: the pq1-fr NOTE_HASH_NODE vector, output overlapping the chaining value, wrong-tag negatives for cv, block and params, out-of-range negatives for each operand range (memory is not touched), and the highest in-range output address. - The transpiled pq1-fr NOTE_HASH_NODE contract (the same bytes as aztec-rs's testdata/h4_pq1fr_note_hash_node.avm) through PublicTxSimulationTester: both modes succeed with the expected hash, a wrong expectation reverts, hint collection agrees with fast simulation, and instruction counts and public L2 gas (430 / 16,750 with the opcode, 18,341 / 422,628 in pure Noir) equal the Rust simulator's. - BLAKE3COMPRESSION entry in the opcode spam benchmark.
|
The
This PR's own checks pass locally:
I couldn't read the CI log itself (ci.aztec-labs.com needs credentials), so a later failure can't be ruled out. I did not port the fixes into this PR. They belong in the Turbo crates ( Generated by Claude Code |
|
Merge desk: left open. The review is APPROVE with conditions. An independent reviewer looked at head b1d104f against base
Tests run:
Not verified: the C++ vm2 test suite (no bb build), a ZisK guest run, and regenerating the Conditions before merge:
🤖 Generated with Claude Code |
AVM_BLAKE3COMPRESSION_BASE_L2_GAS is now SHA256COMPRESSION's 12288 times the ZisK step ratio of the two opcodes, 1268 / 1103.25 = 1.149, in place of the x86 instruction ratio 0.443. Steps are ziskemu (ZisK 1.4.0-alpha) marginal steps per opcode when aztec-rs's avm-simulator executes it in a ZisK guest, each compression on its precompile (BLAKE3F, SHA256F); the per-cell tagged memory traffic of the opcode, not the compression, dominates both. ZisK's cost model (ziskemu -X) gives a similar ratio, 1.081. Reference, in the same guest (steps per opcode in the simulator): BLAKE3COMPRESSION 1268 on BLAKE3F / 2437 portable; SHA256COMPRESSION 1103 on SHA256F / 4469 portable (aztec_crypto::sha256_compression has no precompile path today, so 4469 is what Turbo runs); KECCAKF1600 1499 / 5702; POSEIDON2PERM 11284 (ARITH256_MOD). The other opcodes' gas is not ZisK-calibrated (POSEIDON2PERM 360 gas for 10x SHA's steps); only this opcode is set here. The H4 fixture (pq1-fr NOTE_HASH_NODE, one compression) now costs 25,433 public L2 gas with the opcode (was 16,750); pure Noir is unchanged at 422,628. The Rust fixture test now asserts both, as the C++ test does. The C++ test's expectation is updated by arithmetic; bb was not built.
|
Both conditions from the review above are addressed in a47f168. 1. The fixture in a ZisK guest (
Results:
2. Gas recalibrated on ZisK steps per opcode through the simulator:
Notes for follow-up (not in this PR):
Generated by Claude Code |
… rustfmt cargo fmt --check in aztec-rs/bootstrap.sh failed on the base branch (zkvm/hash-pq1fr-rs @ 92fcd83) on the two generated files; ported here so this PR's CI can run past it.
…K guests 4,469 -> 1,103 ZisK steps per opcode (h4c measurement, output equal to native over 11 chained compressions). The BLAKE3COMPRESSION gas (14123) is calibrated against this precompiled cost.
|
C++ build of the BLAKE3COMPRESSION opcode: green.
This covers simulation only: the opcode has no vm2 circuit (tracegen or constraints) yet. Generated by Claude Code |
|
CI: I ran every PR-relevant step from the build scripts locally on this branch's head (04b503d), and all of them pass:
No commit on the Turbo base ( Generated by Claude Code |
… from fc/aztec-turbo aztec-rs/bootstrap.sh builds with RUSTFLAGS=-Dwarnings, and on fc/aztec-turbo (f629ac5) `cargo build --release --locked` stops at 9 errors in zisk-stark-verifier, so ci-fast fails before any of this branch's code is checked: - unexpected `cfg` condition value `std` (log.rs: v_debug!/v_error! sit behind a `std` feature the manifest does not define), and with it the loop variables they would log (stir.rs:940, verifier.rs:142) are unused; - unused imports (verifier.rs: DotAcc, cubic_mul_acc; fields/advice.rs: PrimeField64); - layout::Tree::leaf_bits is never read. Once it builds, `cargo clippy --locked --all-targets` stops at needless_range_loop and manual_memcpy in the same crate, then let_and_return in zisk-pilfflonk-verifier's pairing test and needless_update / redundant_locals in aztec-epoch's state tests. zisk-stark-verifier's code is left unchanged: its manifest declares the `std` cfg and allows those lints. The two test files take clippy's suggested rewrites. All five aztec-rs build steps pass afterwards, and so does `cargo test --locked`.
|
The CI fast-job failure is in code this PR doesn't touch, so I ported a lint-only fix into this PR (4dd6552). The failure.
Not this PR's. The same 9 errors reproduce at The fix:
The build failed before the fix. After it, these all pass on zac-box:
The full Generated by Claude Code |
|
This is an experimental zkVM branch, validated by local checks on a dev box rather than org CI. It isn't meant to merge into the master track for now, so I've converted it to a draft. The work stays on These local checks pass at 4dd6552:
These were not run locally: a full bb build and link, the full aztec-rs workspace build and clippy, the noir-protocol-circuits compile, and the test suites. 🤖 Generated with Claude Code |
Requested by Zac · project thread
Stacked on
zkvm/hash-pq1fr-rs(pq1-fr BLAKE3 protocol hashes in aztec-rs).What
A
BLAKE3COMPRESSIONAVM opcode, so public code computes aztec-nr's pq1-fr hashes (keyed BLAKE3 truncated to 253 bits) at one instruction per 64-byte block. Private code (leanVM) and public code must agree on map slots and note hashes (partial notes, nullifiers checked in public).[Indirect8, out, cv, block, params], all u32-tagged;params = [counter_lo, counter_hi, block_len, flags]; output = the 8-word chaining value. Failure order and halts are the same as SHA256COMPRESSION.AVM_BLAKE3COMPRESSION_BASE_L2_GAS = 5440(SHA256COMPRESSION × 0.443, from callgrind: 1,800 vs 4,067 x86 instructions per compression). Added toconstants.nrand regenerated.aztec_blake3Compression(cv: [u32; 8], block: [u32; 16], params: [u32; 4]) -> [u32; 8]becomes the opcode.aztec-rs/crates/avm-simulator): the handler;aztec_crypto::blake3_compressionuses ZisK's BLAKE3F precompile in guests.Why
Measured with nargo 1.0.0-rc.5 → avm-transpiler → Rust simulator, for one pq1-fr hash of two Fields:
field_wordsin aztec-nrWithout the opcode a public
transfer_in_publiccosts 55–65× more ZisK steps (about 20M vs 0.37M today), and a 64-input hash exceeds the 6M AVM gas limit.Tests
cargo test -p avm-simulator: 66 passed, both with and without--features pq1fr. New tests:blake3crate (random keyed chunks);vectors.json;vectors.json;cargo test: 6 passed, 4 of them new.vm2_sim_tests(clang20-assert preset): 420 tests, 419 passed, 1 skipped (the opcode-spam benchmark, which runs only when an environment variable is set). The C++ needed no fixes. b1d104f adds:Companion changes (outside this repo)
pq1.nr: the oracle,compresscalling it, and a u128field_words.acir_callback.ts.Patches are kept with the project's integration notes.
https://claude.ai/code/session_01Q1AhUehv3mVEnJr82ZeNes
Generated by Claude Code