Skip to content

Add BLAKE3 keyed, derive-key and 64-byte XOF modes - #259

Merged
RobinLinus merged 2 commits into
solving-bitcoin:mainfrom
benthecarman:blake3-modes-xof64
Oct 16, 2026
Merged

RobinLinus merged 2 commits into
solving-bitcoin:mainfrom
benthecarman:blake3-modes-xof64

Conversation

@benthecarman

Copy link
Copy Markdown
Contributor

Summary

Several negative results in knowledge/negative-results/ claimed things were impossible or costly when they are not. This PR implements three of them and corrects the records.

  • 64-byte XOF (NR-060, OP-024): the first 64 XOF bytes are the complete root compression output. The second half, v[i+8] ^ cv[i], was already computed and dropped. Returning it needs no extra compression.
  • Keyed mode (NR-069, OP-028): with a key fixed when the script is generated, only the starting chaining value and one flag change. Witness shape and routing stay the same.
  • Derive-key (NR-061, OP-025): BLAKE3 requires a hardcoded context, so the context phase runs on the host. Only the material phase is in Script.
  • NR-071: the u4 MSB lookup was called "dominated", but it is 6 bytes smaller (440 vs 446). It is a bytes-for-stack tradeoff (50 vs 34 items).
  • Removes a duplicated merge remnant in NR-042.

New API: blake3_short_mode_compute_script(len, Blake3Mode, output_len) for messages up to 32 bytes, with 16-, 32- or 64-byte output.

Measurements (32-byte message 00 01 ... 1f)

All rows use 64 checked u4 data items and zero hint items. The peak is the strict combined stack peak, including the output verifier.

Mode Script bytes Static non-push opcodes Peak
Unkeyed digest (unchanged) 59,534 41,135 527
Keyed, official key 59,532 41,135 527
Derive-key, official context 59,521 41,131 527
64-byte XOF 60,131 41,442 527
Keyed 64-byte XOF 60,133 41,443 527

Script size varies slightly with the key; an all-0x42 key gives 59,557. Evidence is differentially-validated; deployment is unclassified.

Still not implemented

  • XOF output beyond 64 bytes, which needs a counter-1 root compression.
  • 64-byte XOF in the multi-block limb API, which needs the previous chaining value kept.
  • A key supplied in the witness.

A fixed key is visible in the revealed leaf.

Test plan

  • cargo test --locked -- --skip fields:: (all pass; existing BLAKE3 metric snapshots unchanged)
  • python3 tools/kb.py validate
  • All 27 official keyed/derive-key/extended-output vectors (lengths 0–8) under strict-stack execution
  • Every length 0–32 × three modes × 16/32/64-byte output against the blake3 crate
  • Derive-key with empty, short, and 150-byte contexts
  • Rejection of malformed nibbles, extra and missing items, and another mode's digest
  • New metrics added through blake3_short_mode_metrics_are_current

🤖 Generated with Claude Code

benthecarman and others added 2 commits October 11, 2026 11:14
The short direct-u4 BLAKE3 profile only produced the unkeyed digest.
Keyed and derive-key modes differ from unkeyed hashing only in the root
compression's input chaining value and one flag, so with a key or
context fixed when the script is generated they cost the same as
unkeyed hashing. Derive-key contexts must be hardcoded, so the context
phase runs on the host and only the material phase is in Script.

The first 64 bytes of the XOF stream are the complete root compression
output. Its second half, state[i+8] ^ cv[i], was already computed and
then dropped; returning it needs no extra compression.

blake3_short_mode_compute_script exposes all three modes with 16-, 32-
or 64-byte output. Unkeyed scripts are unchanged. Tests check the
official extended vectors and every length up to 32 against the blake3
crate under the strict stack limit, plus malformed inputs.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Several negative results overstated what was impossible or costly:

- NR-060 and the XOF record claimed a 64-byte output needs an extra
  compression; it is the complete root output.
- NR-069 and the keyed record claimed keyed mode changes witness shape
  and routing; with a fixed key it only changes constants.
- NR-061 claimed derive-key must duplicate the compression schedule;
  the hardcoded context phase can run on the host.
- NR-071 called the u4 MSB lookup dominated, but it is six bytes
  smaller; it is a bytes-for-stack tradeoff.

Record the new measurements, close OP-024, OP-025 and OP-028, add the
catalog configurations, and remove a duplicated merge remnant in NR-042.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@RobinLinus
RobinLinus merged commit f392f37 into solving-bitcoin:main Oct 16, 2026
@benthecarman
benthecarman deleted the blake3-modes-xof64 branch October 17, 2026 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants