Repository navigation
Shrink short BLAKE3 from 59,534 to 43,930 bytes - #264
Merged
Merged
Conversation
Replace the tracked-stack backend of the short direct-u4 BLAKE3 profile with a generator that models the main and alt stacks exactly and emits opcodes directly. Addition outputs are stored biased so that each nibble is directly the OP_PICK depth of its lookup entry, carries are biased so that a nibble sum is directly the depth of its modulo entry, and constant state words are folded into lookup addresses. While generating, every lookup and word operation is checked against host arithmetic on a sample message. The construction comes from an agentic Claude Opus 5.5 run against an older upstream revision. It is generalized here to every message length from 1 to 32 bytes, all three modes and 16-, 32- and 64-byte output, keeping the public API and the witness layout. The 32-byte unkeyed fragment shrinks from 59,534 to 44,305 bytes and from 41,135 to 28,893 static non-push opcodes. Its strict peak including the verifier rises from 527 to 581 items. Remove the digit backend, late tables and keyed-root entry point that only the old short path used. The limb profile and every Ed25519 challenge script stay byte-identical. Add tests for seeded random messages in every mode and output width, malformed witness items at every position, the exact stack model and the table lifecycle, and a focused metric test for the short-profile rows of the ignored repository-wide suite. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Store the 16 XOR rows of the short-profile tables as three pieces of their 171-item shortest common superstring instead of 256 separate entries, fitted around the shift, lut, carry and modulo tables. Those tables keep their positions, so every steady-state shift adjustment still pushes as one data byte. The table shrinks from 384 to 302 items and is now built by a greedy encoder that copies earlier entries where that is shorter than a literal. Use a fixed column and diagonal G-call order per round, found by a coordinate search over the 24 orders of each phase; it is shorter for every length, mode and output width. Try cyclic nibble orders for each XOR, and drop the materialized-state and unbiased-message variants, which never produced the shortest script. The 32-byte unkeyed fragment shrinks from 44,305 to 43,930 bytes and 28,854 static non-push opcodes, and its strict peak including the verifier falls from 581 to 499 items, below the earlier 527. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewrite the short-profile sections of the BLAKE3 README and the blake3-short-u4 knowledge page for the new generator: its biased value representations, packed table layout, generation-time choices, lifecycle byte counts, stack contract, and the tests behind the differential and malformed-witness evidence. Credit the agentic Claude Opus 5.5 run the construction comes from. Record the measured steps and the variants that did not pay as NR-086 with a dedicated page, move the OP-013 frontier to 43,930 bytes and 499 items, and add dated remeasurements to the closed keyed, derive-key and XOF records instead of rewriting their history. Update the hash comparison rows, the catalog record's description and deployment class, and add depth-biased values to the lookup-table techniques. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The short direct-u4 BLAKE3 profile now comes from a new generator,
src/hashes/blake3/short.rs. It models the main and alt stacks exactly and emits opcodes directly. The 32-byte unkeyed fragment shrinks from 59,534 to 43,930 bytes (−26%), and its strict peak falls from 527 to 499 items. Every length from 1 to 32 bytes and every mode and output width improves by a similar margin.Public APIs and the witness layout are unchanged. The limb-profile scripts and every Ed25519 challenge script are byte-identical, checked by hashing an export of
main.Measurements
Hint items are 0 in every row. All 64 inputs are present at entry, and the peak includes the output verifier.
Table setup is 362 B and cleanup is 183 B (199 B for the 128-bit prefix). The scripts are over 32 KiB, so the compile policy applies no optimizer passes. The BLAKE3 peephole pass leaves every configuration unchanged.
How it works
Values are stored with offsets so that most lookups need no index arithmetic:
nis stored asn + MU, which is directly theOP_PICKdepth of a small table pointing at XOR rown. A full XOR isPICK ADD PICK.q + KAPPA, so a nibble sum is directly the depth of its modulo entry.DUP PICK TUCK SUB PICKyields the result nibble and the next carry.OP_DEPTHcount check runs first. Each witness nibble is then range-checked withDUP 0 16 WITHIN VERIFYthe first time it is fetched.Main's packing of the 16 XOR rows into a 171-item shortest common superstring is kept. The rows go in as three pieces, fitted around the shift, lut, carry and modulo tables. Those tables keep their positions, so every shift adjustment still pushes as one data byte. Table memory falls from 384 to 302 items.
The column/diagonal G-call order is fixed per round from a coordinate search. It is at least 168 B shorter in all 288 length/mode/output configurations. Each XOR also tries more nibble orders.
The construction comes from an agentic Claude Opus 5.5 run against an older revision (5860061, where this script was 62,647 B; that run reached 44,401 B). Here it is generalized to lengths 1–32, all three modes and 16/32/64-byte output, and combined with main's table packing.
What did not pay
Recorded as NR-086, with the full table in
knowledge/negative-results/blake3-short-generator.md:About 45% of the remaining bytes are operand fetches (3-byte rolls of deep state nibbles, 4-byte message picks). OP-013 now targets 43,930 B.
Validation
Evidence is
differentially-validatedagainst theblake3crate. The catalog's execution class moves fromresearch-unlimitedtounclassified: every test now runs under the strict stack limit, and no in-repo Bitcoin Core run was added.Independently of this repository's tests, the 32-byte unkeyed script was graded with a separate harness. It runs on the pinned
rust-bitcoin-scriptexecfork and compares against theblake3crate:Every one of those 1,084 cases was then spent through Bitcoin Core's consensus library, as a single-leaf taproot script path with taproot flags. Core agrees on all of them: the 503 correct messages spend, and the 581 malformed cases fail.
Not done
readme_metrics_are_currentsuite. Not run, because it executes bn254 field scripts. The newblake3_short_metrics_are_currentchecks the short-profile rows.[n, 0x00]is accepted as nibblen. A test confirms it yields the same digest, so it cannot select a different message. This behaviour is unchanged frommain.Test plan
cargo test --locked --lib hashes::blake3, including the ignored utils testscargo test --locked --test primitive_metrics(164 passed)cargo test --locked -- --skip fields::(all groups pass)python3 tools/kb.py validate,cargo fmt --check0xffmessages for every length, mode and output width (297 scripts, strict stack)UPDATE_PRIMITIVE_METRICS=1(single-threaded); every changed number is a short-profile row🤖 Generated with Claude Code