Skip to content

test(u4): strengthen batch packing coverage - #232

Merged
RobinLinus merged 3 commits into
solving-bitcoin:mainfrom
brenorb:fix/u4-batch-pack-coverage
Sep 28, 2026
Merged

RobinLinus merged 3 commits into
solving-bitcoin:mainfrom
brenorb:fix/u4-batch-pack-coverage

Conversation

@brenorb

@brenorb brenorb commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • consolidate review coverage into the merged u4_nibbles_to_bytes implementation from feat(u4): add batch nibble packing #205
  • cover ScriptNum boundary encodings, every malformed nibble position, and main/alt-stack preservation
  • test the 664-nibble strict stack frontier and reject oversized batches
  • synchronize the arithmetic comparison metric and mark the batch result locally reproduced

Validation

  • cargo test --locked --lib arithmetic::u4::pack
  • cargo test --locked --lib arithmetic::u4::pack::tests::packs_scriptnum_boundary_encodings -- --exact
  • cargo test --locked --test primitive_metrics u4_pack_metrics_are_current -- --exact
  • python3 tools/kb.py validate
  • rustfmt --edition 2021 --check src/arithmetic/u4/pack.rs
  • git diff --check

The repository-wide test suite was not run.

Copy link
Copy Markdown
Contributor

Review of 10c9432f83ddaf5e94b4f5d8c511de6321236296:

rejects_invalid_nibbles_at_every_position still has a false-positive rejection path: the four-input packer leaves two output items, and the test does not consume them. Even a successful unchecked packer therefore fails the final clean-stack condition and satisfies assert!(!result.success). Consume both hypothetical outputs (OP_2DROP OP_TRUE) and assert the intended range-check error. Use runtime witnesses and exercise negative, 16, and oversized numeric encodings at each position. The encoding, preservation, and frontier additions are otherwise useful.

Holding this version for the concrete change above.

Validation scope: source/diff and existing CI review; no new full-repository or field-arithmetic test run was requested.

@brenorb

brenorb commented Sep 26, 2026

Copy link
Copy Markdown
Contributor Author

Addressed in 12ecb39, integrated with main at e9d5a66.

Reproduced the false-positive path before fixing the test: the unchecked four-input batch left two outputs and failed with no interpreter error; adding OP_2DROP OP_TRUE made that same unchecked computation succeed. The production packer is unchanged.

The replacement regression uses raw runtime witnesses for -1, 16, and a five-byte numeric encoding at every one of the four positions. Its success-path cleanup consumes both hypothetical outputs, and it requires Verify for out-of-range values or ScriptIntNumericOverflow for the oversized encoding. A valid-input control uses the identical cleanup, and the same shared error assertion detects a deliberately unchecked mutant that succeeds on malformed input. Updated the catalog test reference and evidence description; retained the encoding, preservation, and frontier coverage.

Validation on the committed integrated tree: all 7 pack-module tests passed, including the stack frontier; u4_pack_metrics_are_current passed; KB validation, formatting, and whitespace checks passed. These new runtime-witness checks use the pinned local tapscript interpreter with stack enforcement. They do not establish Bitcoin Core consensus or relay-policy validity. No broad repository or field-arithmetic suite was run.

@RobinLinus
RobinLinus merged commit 5f74e9f into solving-bitcoin:main Sep 28, 2026
3 checks passed
@brenorb
brenorb deleted the fix/u4-batch-pack-coverage 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