Skip to content

feat(u4): add nibble pair byte adapter - #80

Closed
brenorb wants to merge 1 commit into
solving-bitcoin:mainfrom
brenorb:feat/u4-nibbles-to-byte
Closed

brenorb wants to merge 1 commit into
solving-bitcoin:mainfrom
brenorb:feat/u4-nibbles-to-byte

Conversation

@brenorb

@brenorb brenorb commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add u4_nibbles_to_byte to pack a high/low nibble pair into one byte
  • provide checked and unchecked forms with explicit stack contracts
  • reject negative and 16-valued inputs in checked mode
  • record script, witness, stack, and static-opcode metrics

Validation

  • cargo test --locked arithmetic::u4::bits::tests::exhaustive_nibble_pairs_pack_to_bytes
  • cargo test --locked arithmetic::u4::bits::tests::checked_nibble_pair_rejects_malformed_inputs
  • cargo test --locked --test primitive_metrics
  • python3 tools/kb.py validate
  • cargo fmt --check
  • git diff --check

The full repository test suite was intentionally not run; the focused primitive and metric checks pass. Dynamic opcode counting is unavailable in the local executor, so the documentation reports static non-push counts.

@brenorb
brenorb force-pushed the feat/u4-nibbles-to-byte branch from 3f07fea to 39a6c69 Compare September 11, 2026 14:21

Copy link
Copy Markdown
Contributor

Review recommendation: close or replace this version.

Prefer #33 as the single public pair-to-byte API. Both implementations produce 20 policy-compiled bytes checked and 10 unchecked; their bytecode is not identical, but this PR provides no size advantage. #33 also has an active dedicated metric check. Preserve any additional useful tests there rather than maintaining two overlapping helpers.

September 11 local validation (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.

Reviewed commit: 39a6c6942d4ebaa8b5bc4cf1aabf97f41f4a6360.

@brenorb

brenorb commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded by merged PR #33, which is the canonical u4_pair_to_u8(check_inputs) API. The two implementations have the same measured checked/unchecked sizes and #33 has the active dedicated metric check. The useful additional exhaustive unchecked coverage and corrected malformed-input assertions were preserved in follow-up PR #239.

@brenorb brenorb closed this Sep 18, 2026
@brenorb
brenorb deleted the feat/u4-nibbles-to-byte 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