feat(u32): document compressed boundary - #42
Conversation
|
Review recommendation: fix before merging. The new representation documentation does not match Correct the contract, examples and serialized witness maximum accordingly. Align the decoder's caller obligations with the explicit canonical boundary in #30. Tests passing for the existing implementation do not validate this new prose. Evidence for the mismatch: 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: |
055b0b0 to
d58f309
Compare
|
Updated in place and rebased onto current main. Corrected the contract from unsigned encoding to signed two's-complement ScriptNum encoding: Checks: focused boundary tests and metrics passed; |
|
Review of The signed-compression documentation now correctly explains 0xffffffff -> -1 and the five-byte sentinel, addressing the earlier representation error. Preserve current catalog and metric additions during the rebase, then rerun the signed-encoding/decoder boundary tests and named compression metrics. Current integration conflicts: Validation scope: source/diff and existing CI review; no new full-repository or field-arithmetic test run was requested. |
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>
|
Addressed in
Evidence throughout is local ( |
Summary
u32_compress()/u32_uncompress()ScriptNum boundary0x80000000, andu32::MAXResearch framing
Question: what is the exact executable contract and cost of the existing u32-to-ScriptNum boundary?
Result: four byte items compress to one minimal ScriptNum, using a fifth sign byte when needed; decompression expands an at-most-five-byte ScriptNum back to four byte items. The representative fragments are 76 and 413 script bytes, with 9 and 7 serialized witness bytes and 7-item strict peaks.
Execution is locally reproduced and remains unclassified for deployment. The helpers do not certify canonical byte limbs or the unsigned range; callers must enforce those protocol boundaries. Six-byte inputs fail; the complete catalog entries exclude input pushes and output checks.
Validation
cargo fmt --all -- --checkcargo test --locked compressed_u32cargo test --locked uncompress_rejects_scriptnums_wider_than_five_bytescargo test --locked --test primitive_metrics u32_compression_metrics_are_currentpython3 tools/kb.py validategit diff --checkThe full repository test suite was intentionally not run; field-arithmetic tests remain skipped by default.