Skip to content

feat(u32): add canonical compressed decoder - #30

Merged
RobinLinus merged 1 commit into
solving-bitcoin:mainfrom
brenorb:feat/u32-canonical-uncompress
Sep 16, 2026
Merged

RobinLinus merged 1 commit into
solving-bitcoin:mainfrom
brenorb:feat/u32-canonical-uncompress

Conversation

@brenorb

@brenorb brenorb commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add u32_uncompress_canonical() for the exact raw ScriptNum encoding of a compressed u32
  • reject negative zero, redundant sign bytes, nonminimal aliases, and out-of-domain five-byte values
  • reuse the shared boundary in the Ed25519 packed decoder instead of keeping a duplicate validator
  • document the contract and measured cost

Evidence

  • evidence: locally-reproduced
  • execution class: unclassified; local tapscript helper only, with no Bitcoin Core differential validation
  • representative maximum item: canonical five-byte -2^31
  • measured fragment: 431 locking-script bytes, 7-byte serialized witness, 7-item strict combined peak

Validation

  • cargo fmt -- --check
  • python3 tools/kb.py validate
  • cargo test --locked arithmetic::u32::stack
  • cargo test --locked fields::ed25519::u5_packed
  • cargo test --locked --test primitive_metrics u32_uncompress_canonical_metrics_are_current

The full repository test suite was intentionally not run; this contribution is covered by focused tests for the new boundary and its affected packed decoder.

@RobinLinus
RobinLinus merged commit b92e22c into solving-bitcoin:main Sep 16, 2026
@brenorb
brenorb deleted the feat/u32-canonical-uncompress 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