Skip to content

feat(arithmetic): add total-domain u32 right shift - #3

Closed
brenorb wants to merge 1 commit into
solving-bitcoin:mainfrom
brenorb:feat/total-domain-u32-rshift
Closed

brenorb wants to merge 1 commit into
solving-bitcoin:mainfrom
brenorb:feat/total-domain-u32-rshift

Conversation

@brenorb

@brenorb brenorb commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add a compressed ScriptNum u32 logical right shift covering the full 0..=0xffffffff domain
  • certify canonical compressed inputs, including the 0x80000000 negative-zero sentinel
  • add malformed-input tests, boundary vectors, benchmark output, metrics, and knowledge-base records

Measured shift-7 boundary

Construction Locking script Witness Stack peak Static non-push opcodes
Compressed ScriptNum 1143 bytes 6 bytes 272 items 863
Four-byte baseline 637 bytes 12 bytes 272 items 473

The compressed form saves witness width but is not a locking-byte or combined-stack improvement. Dynamic opcode and validation-weight measurements are not available from the local executor.

Focused verification

  • cargo test --locked arithmetic::u32::rshift --lib
  • cargo test --locked --test primitive_metrics total_domain_rshift_metrics_are_current
  • cargo test --locked --test knowledge_base
  • cargo fmt --all -- --check
  • python3 tools/kb.py validate
  • cargo run --locked --release --example u32_total_domain_rshift_benchmark

The full repository test suite was not run, per request; validation was limited to the affected primitive, metrics, knowledge-base validation, formatting, and benchmark.

Copy link
Copy Markdown
Contributor

Review recommendation: close or replace this version.

Prefer the right-shift implementation in #8, integrated together with #9. With the same compressed input 0xa5c319e7 and identical result checks, #8 is smaller for each tested shift (1, 7, 8, 16, 24, 31). For shift 7 the policy-compiled fragments are 1,141 bytes here versus 519 bytes in #8; combined main/alt-stack peaks are 272 versus 5. For shift 31 they are 1,136 versus 58 bytes, with the same respective peaks.

These measurements exclude input pushes and terminal checks from fragment size, include the identical result check in stack peak, and use one entry data item, zero hint items and six serialized data-witness bytes (excluding script/control block). Evidence: locally-reproduced; deployment class of these isolated strict-local probes: unclassified.

Preserve this implementation as a comparison/negative result if useful, rather than maintaining two public right-shift APIs.

September 11 local validation (unchanged PR head): python3 tools/kb.py validate passed; 2 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.

Reviewed commit: e9cbd4788962a727945eb8d8dc618a8696693fdb.

@brenorb

brenorb commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favor of the smaller right-shift implementation in #8, integrated with #9. The reviewed version is dominated on script size and stack peak; its measurements remain useful as comparison evidence.

@brenorb brenorb closed this Sep 18, 2026
brenorb added a commit to brenorb/bitcoin-scripts that referenced this pull request Sep 28, 2026
…-066

Resolve the knowledge/negative-results/index.md conflict by keeping main's
historical PR solving-bitcoin#3 record, NR-064 (complete-witness signature budgets, solving-bitcoin#240)
and NR-065 (CSV operand narrowing) unchanged, and appending this PR's
Merkle branch composition entry after them as NR-066 (renamed in the
preceding commit). NR headings are now unique (66 headings, 66 ids).

tests/primitive_metrics.rs and src/ciphers/aes/mod.rs auto-merged; all
112 main and 106 PR-side #[test] functions survive (113 total, no dups).
The merkle_branch_boundary example and metric still reproduce 1,060,200
unoptimized script bytes, 770,481 static non-push opcodes, and 129/193
serialized witness bytes on the integrated tree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
brenorb added a commit to brenorb/bitcoin-scripts that referenced this pull request Sep 28, 2026
Integrate origin/main (3d1001f) into the signed-window schedule branch.

- knowledge/negative-results/index.md: keep every main entry (NR-001..NR-066,
  NR-071, historical PR solving-bitcoin#3, merged Merkle-branch record) and append this PR's
  two entries under their assigned IDs. The PR's NR-064 and NR-065 collided
  with main's NR-064 (data-only signature budgets) and NR-065 (CSV operand
  narrowing); they are renamed NR-067 (signed-window tables) and NR-068
  (width-5 fixed-base CSFS). No PR-side links referenced the old IDs.
- src/arithmetic/u4/mod.rs: take main's sorted module list, a strict superset
  of the PR's alphabetical reordering (47 vs 37 modules, no PR-only module).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@brenorb
brenorb deleted the feat/total-domain-u32-rshift 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