Repository navigation
feat(u32): add reusable reverse byte adapter - #40
Conversation
|
Review recommendation: fix before merging. The shared reverse-byte adapter is useful, but the compatibility re-export September 11 local validation (unchanged PR head): Integration: rebase on current main, resolve any catalog/NR/OP ID collisions, and run the affected correctness tests and focused metric checks. Reviewed commit: |
abb7767 to
62e0a03
Compare
|
Updated in place and rebased onto current main. Removed the legacy Checks: focused U32 and hash tests passed; active adapter, HASH160, SHAKE256, and bitwise/hash metric tests passed; |
|
Review of The shared adapter and removal of the legacy alias address the earlier feedback. However, this diff also removes Current integration conflicts: Validation scope: source/diff and existing CI review; no new full-repository or field-arithmetic test run was requested. |
Integrate PR solving-bitcoin#40 with current main at e9d5a66, preserving the main additions and resolving the shared u32 catalog, docs, and metric rows.
|
Addressed in f1c3ba7, integrating main at e9d5a66 while retaining the shared adapter and its consumers. Reproduced the test-harness defect before the fix: even a valid compression input left the compressed result plus OP_TRUE and reported failure without an interpreter error. Restored OP_DROP OP_TRUE. The malformed-limb test now uses strict local runtime witnesses, requires MinimalData for the tested nonminimal aliases and Verify for the tested out-of-range values at each position, and includes a valid-input control with identical cleanup. A deliberately unchecked compressor succeeds on an out-of-range limb, and the same shared rejection assertion demonstrably catches that bypass. Resolved the catalog, knowledge-page, and metric conflicts while preserving main's byte-plane additions. Updated the remaining integrated SHA-256 suffix call site to the shared adapter; no legacy alias was restored. The production compression implementation is unchanged. Validation on the integrated tree: all 24 u32 stack tests and 38 affected hash-consumer tests passed (SHA-256/u32, SHA-1, RIPEMD-160, HASH160, SHAKE256), as did the adapter and canonical-compression named metrics, KB validation, formatting, and whitespace checks. The corrected malformed-limb regression enforces the combined stack limit in local tapscript; other retained non-strict test paths remain research-unlimited. No new Bitcoin Core consensus or relay-policy claim is made. No broad repository or field-arithmetic suite was run. |
Merges origin/main (3d1001f, which has since integrated solving-bitcoin#84 signed less-than, solving-bitcoin#45 fixed rotations/equality, solving-bitcoin#40 reverse-byte adapter, and 27 other PRs) into feat/u32-compressed-boundary, addressing Robin Linus's 2026-09-25 review. Conflicts resolved: - knowledge/catalog.json: kept the u32 record's "tests" entries from both sides (u32_compression_metrics_are_current and u32_reverse_byte_adapter_metrics_are_current), and merged the "security"/"stack_contract" prose so both sides' sentences survive. main ⊆ merged and PR ⊆ merged verified by record-id and (record, configuration)-id set comparison: 117 records / 285 configurations after merge, no duplicates, no ids outside the union of both sides. - knowledge/primitives/u32.md: concatenated both sides' bullets (signed compression boundary / unchecked decoder from the PR; reusable routing / byte-plane transpose / fixed-byte rotations / SHA-256 rotation from main). All 43 main bullets and 40 PR bullets verified present in the merged 45. - src/arithmetic/u4/mod.rs: union of both sides' `pub mod` lines, alphabetically sorted (main added several u4 modules the PR predates; no semantic content lost). - tests/primitive_metrics.rs: kept every #[test] fn from both sides (u32_compression_metrics_are_current from the PR; u32_reverse_byte_adapter_metrics_are_current, u32_equality_metrics_are_current, u32_fixed_rotation_metrics_are_current, u32_byte_planes_metrics_are_current from main). 207 fns after merge = union of main's 206 and the PR's 169 (168 shared). src/arithmetic/u32/README.md and src/arithmetic/u32/stack.rs merged without conflict. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
u8_reverse_toaltstack(num_bytes)byte-order adapter to the u32 stack moduleResearch framing
Question: can the repeated hash input-routing fragment be made a single measured u32 primitive without changing its stack contract?
Result: yes. The adapter moves raw byte items from the main stack to the alt stack and restores top-first order. The representative four-byte fragment is 8 script bytes, 9 serialized witness bytes, and a strict five-item combined peak.
The execution evidence is locally reproduced and unclassified. Inputs remain raw Script numbers; callers must enforce byte range and canonical encoding when the trust boundary requires it. The fragment excludes input pushes and output checks.
Validation
cargo fmt --all -- --checkcargo test --locked arithmetic::u32::stack::tests::reverse_byte_batch_to_altstack_preserves_order_and_statecargo test --locked --test primitive_metrics u32_reverse_byte_adapter_metrics_are_currentpython3 tools/kb.py validategit diff --checkThe full repository test suite was intentionally not run; field-arithmetic tests remain skipped by default.