Skip to content

feat(sha256): add 80-byte midstate continuation - #67

Merged
RobinLinus merged 3 commits into
solving-bitcoin:mainfrom
brenorb:feat/sha256-midstate-boundary
Sep 25, 2026
Merged

RobinLinus merged 3 commits into
solving-bitcoin:mainfrom
brenorb:feat/sha256-midstate-boundary

Conversation

@brenorb

@brenorb brenorb commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add a u32 SHA-256 continuation for a fixed 64-byte prefix midstate and 16-byte suffix
  • validate padding, byte ordering, and the full digest against sha2 compression
  • record script, witness, and stack metrics in the knowledge base

Validation

  • cargo test --locked --lib hashes::sha256::sha2_u32::tests
  • cargo test --locked --test primitive_metrics
  • python3 tools/kb.py validate
  • cargo fmt --check
  • git diff --check

The full repository test suite was not run; field-arithmetic tests and unrelated broad targets are outside this scoped primitive change.

Copy link
Copy Markdown
Contributor

Review: hold pending the changes below.

Combine this with #82 into a consistent SHA256 midstate contract, and align the broader continuation family with #71/#73. Share padding and byte-order vectors and add active focused metric checks before integration.

Historical local validation (September 11, at this unchanged PR head): python3 tools/kb.py validate passed; 3 selected library tests passed. These are targeted local checks, not a full-suite or complete-spend validation. Results using a stack-limit-disabled execution helper remain research-unlimited.

Rebase on current main, address the specific gaps above, and run the affected correctness and active metric checks. Broad/full-repository runs are not requested.

Reviewed commit: 4a03397f2e28683526ecf4cdc98166e9a9ab76bc.

@brenorb
brenorb force-pushed the feat/sha256-midstate-boundary branch from 4a03397 to 67a1ea5 Compare September 18, 2026 22:25
@brenorb

brenorb commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

Consolidated and updated in commit 67a1ea5 (force-pushed to this branch).\n\n- Absorbs #82 into this PR with one SHA-256 midstate contract for both u32 and u4: a real midstate from 64 bytes of 0x42, exactly a 16-byte suffix, and the 640-bit final length.\n- Adds rejection tests for short and excess suffixes plus SHA-256 boundary vectors at 55, 56, 63, 64, 65, and 80 bytes.\n- Adds an active focused metric test covering both backends, updates the knowledge pages/catalog/comparison, and records representative versus canonical-maximum witness sizes: u32 33/49 bytes and u4 48/65 bytes.\n- Documents that the fragments consume the complete input stack and do not authenticate the supplied midstate against the prefix.\n- Validation: cargo fmt --all -- --check; python3 tools/kb.py validate; cargo test --locked --test primitive_metrics (106 passed, 1 ignored); git diff --cached --check.

@RobinLinus
RobinLinus merged commit 9a2a65c into solving-bitcoin:main Sep 25, 2026
3 checks passed
brenorb added a commit to brenorb/bitcoin-scripts that referenced this pull request Sep 28, 2026
…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 solving-bitcoin#67/solving-bitcoin#68
(and the further 27-PR integration in solving-bitcoin#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>
@brenorb
brenorb deleted the feat/sha256-midstate-boundary branch October 28, 2026 02:57
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