Skip to content

Integrate 18 reviewed arithmetic, hash and maturity PRs - #263

Merged
RobinLinus merged 49 commits into
mainfrom
codex/review-bitcoin-prs-20261016
Oct 16, 2026
Merged

RobinLinus merged 49 commits into
mainfrom
codex/review-bitcoin-prs-20261016

Conversation

@RobinLinus

@RobinLinus RobinLinus commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Integrates the reviewed changes from #4, #26, #62, and #247–#251 and #253–#262 while preserving every source PR head.

The additions cover BIP68 confirmed-input maturity, arithmetic/checksum and witness-representation primitives, BLAKE3 keyed/derive-key/64-byte output, grouped MSB range checks, hash prefixes, and the checked PRINCE M-hat layer. Research-only limitations remain explicit.

Integration fixes:

Validation:

  • All 16 included same-repository source heads have successful CI. Fork PRs Add BLAKE3 keyed, derive-key and 64-byte XOF modes #259/Shrink u4 MSB projection with grouped range checks #260 have no completed source CI (workflow approval required), so their code is included in this integration's local and CI validation.
  • Knowledge validation: 135 records / 428 configurations; 54 Python harness tests passed; Rust formatting passed.
  • All 21 retained metric/regression tests passed after exclusion, without refreshing measurements.
  • All 143 targeted library tests passed. Fresh pinned Bitcoin Core 30.3 BIP68 comparison passed both height/time fixtures at immature and exact-maturity boundaries.
  • All 62 tests across the eight retained contract suites passed. Six independent research-artifact checks passed. All three final integration CI jobs passed at f392f37cfb73a6e7d9bb2b75af8e6f92f08fe8de: knowledge/Python/formatting, the locked non-field Rust suite, and pinned Bitcoin Core comparisons. Run: https://github.com/solving-bitcoin/bitcoin-scripts/actions/runs/38957292613.

PR #252 is excluded from both the tree and merge ancestry. Its artifact test fails when unrelated shared files change; see #252 (comment).

No field-arithmetic or local full-repository test run was requested or started.

brenorb and others added 30 commits September 10, 2026 23:25
…PIs, resolve NR-064 collision

Rebases the RIPEMD-160/SHA-1/SHA-256 output-prefix adapters over the SHA256
midstate-continuation and BIP340 tagged-hash APIs merged into main via #67/#68
(and the further 27-PR integration in #244). Resolves conflicts in
knowledge/catalog.json, knowledge/comparisons/hashes.md,
knowledge/negative-results/index.md, knowledge/primitives/sha256-u32.md,
src/arithmetic/u4/mod.rs, src/hashes/ripemd160/mod.rs, src/hashes/sha1/mod.rs,
src/hashes/sha256/README.md, src/hashes/sha256/sha2_u4.rs, and
tests/primitive_metrics.rs by keeping both API families: main's
sha256_80bytes_from_midstate/sha256_tagged_hash_32bytes plus this PR's
sha256_prefix/ripemd160_prefix/sha1_prefix adapters, with matching catalog
records, README rows, and primitive_metrics entries on both sides.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…/byte-plane overlaps

Integrates main's 27-PR batch (#244, at 3d1001f) with feat/u4-unpack.

Conflicts resolved:
- knowledge/catalog.json: merged the shared "arithmetic/u4" record's
  stack_contract sentence so it documents both the byte unpacker (PR)
  and the per-nibble/total popcount projections (main, #224).
- knowledge/techniques/representations.md: kept both the u4 byte-unpacker
  paragraph and the u32 byte-plane adapter paragraph, moving the latter
  next to the other u32 mask paragraphs; corrected an inaccurate
  "table wins at larger batches" claim that was not backed by any
  measurement.
- src/arithmetic/u4/README.md: kept both the unpack bullet (PR) and the
  threshold/clamp/equality bullets plus the updated lsb caveat (main);
  corrected an arithmetic error in the byte/stack tradeoff prose (the
  table path was described as "smaller by 32 bytes" when it is actually
  102 bytes larger at the only measured batch size).
- src/arithmetic/u4/mod.rs: sorted union of every `pub mod` from both
  sides (48 modules total; verified head and main are each full subsets
  and the union matches exactly).
- tests/primitive_metrics.rs: kept both `u4_unpack_metrics_are_current`
  (PR) and `tapbranch_metrics_are_current` (main), independent tests that
  were inserted at the same line.

Also corrected the same unsupported "table path trades stack occupancy
for a smaller repeated-batch script" claim in
knowledge/primitives/u4.md, and re-grounded all four locations
(README, knowledge page, representations.md) in the only measured
comparison (16 bytes: table 1,168 bytes/546 items vs. scalar 1,066
bytes/34 items), explicitly declining to claim a crossover batch size
that isn't measured in this repository.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s alongside output prefixes

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…on, 32-bit preimage)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ith current PRINCE

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
brenorb and others added 18 commits October 2, 2026 16:07
Expand a fixed number of canonical (symbol, length) pairs into a nibble
vector. The width-16 comparison saves witness items on long runs and loses
on combined script-plus-witness bytes, recorded as NR-073.
Cover both invalid byte bounds at every witness position and add a strict valid-input state-preservation control. Record matched table/scalar measurements at 16, 18, 19, 32, and 243 inputs, preserving existing snapshots and deployment qualifiers.
Add src/arithmetic/factoradic: checked decoding of a width-n Lehmer code
(n u4 digits with the descending staircase bounds 0 <= c_i <= n-1-i) into
one factorial value v = sum c_i * (n-1-i)! < n!, the lexicographic rank of
a permutation.

- Generator accepts 1 <= n <= 12: the digit carrier fits u4 up to n = 16,
  but the single-ScriptNum value must stay inside the 4-byte
  consensus numeric-operand domain, and 13! - 1 exceeds it.
- Per-position OP_WITHIN checks; multiplication by the generation-time
  constant is unrolled repeated addition (OP_MUL is a disabled opcode and
  fails every script that executes it).
- Range-checked and canonical (byte-unique witness) variants; no hints,
  no table, no altstack.
- Knowledge: primitives/factoradic-u4.md, catalog record with two
  configurations (range-checked 185 bytes / canonical 305 bytes, both
  22-item peak, 24-byte witness), comparison rows, index updates.
- Evidence: locally-reproduced under the local tapscript profile with the
  consensus stack limit enabled; deployment unclassified.
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>
The direct-threshold MSB batch range-checked each nibble with two
separate compare-and-VERIFY sequences, then duplicated and dropped the
nibble around the threshold comparison. The pinned optimizer rewrote
neither, leaving the schedule six bytes larger than the lookup table it
replaced, so NR-071's claim that the lookup was dominated did not hold.

One OP_WITHIN range check consuming a copy, followed by a threshold
that consumes the original, cuts the 32-nibble batch from 446 to 286
bytes for one extra peak item. It now dominates the former lookup on
both bytes and stack. The maximum standalone width drops from 998 to
997. Record the stack-minimal 382-byte alternative and the corrected
NR-071 comparison.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A per-nibble OP_WITHIN check costs five bytes and dominates the MSB
projection. Checking three nibbles at once needs only their maximum
below 16 and their minimum non-negative: 3DUP MAX MAX 16 LESSTHAN
VERIFY, then 3DUP MIN MIN and a lower bound. While at least 16 batch
items remain on the main stack, that lower bound is OP_PICK OP_DROP,
since any index in 0..=15 reaches a batch item and a negative one
fails. A small dynamic program picks the group widths.

For 32 nibbles this is 250 bytes against 286, at the same 35-item
peak, with 202 static non-push opcodes against 190. Three-wide groups
peak at n+3, so batches above 995 use two-wide groups and peak at n+2,
which keeps the 998-nibble maximum the OP_WITHIN version had to give
up. The two-wide schedule is 277 bytes at a 34-item peak for 32
nibbles, the smallest found that keeps the n+2 peak.

New tests run both schedules on every batch size up to 40, with and
without items below the batch, checking every value at every position
and rejecting every out-of-range value there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ibility fixes

Exclude Adler-32 PR #252 pending reproducible artifact validation fixes.
@RobinLinus
RobinLinus force-pushed the codex/review-bitcoin-prs-20261016 branch from 6638ec6 to f392f37 Compare October 16, 2026 19:45
@RobinLinus RobinLinus changed the title Integrate 19 reviewed arithmetic, hash and maturity PRs Integrate 18 reviewed arithmetic, hash and maturity PRs Oct 16, 2026
@RobinLinus
RobinLinus merged commit 374d076 into main Oct 16, 2026
6 checks passed
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.

4 participants