Skip to content

test(u32): strengthen checked zero predicate coverage - #235

Merged
RobinLinus merged 4 commits into
solving-bitcoin:mainfrom
brenorb:fix/u32-zero-boundaries
Sep 28, 2026
Merged

RobinLinus merged 4 commits into
solving-bitcoin:mainfrom
brenorb:fix/u32-zero-boundaries

Conversation

@brenorb

@brenorb brenorb commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Keep the checked u32 zero predicate's existing generator and 53-byte policy-produced fragment. Add runtime-witness contract coverage for nonzero limbs at every position, malformed and oversized limbs, preserved stack state, and the combined stack frontier. Clarify the checked versus unchecked helper contract and restore the 37 static non-push opcode metric.

Validation

  • cargo test --locked --lib arithmetic::u32::zero
  • cargo test --locked --test primitive_metrics u32_zero_metrics_are_current -- --exact
  • python3 tools/kb.py validate
  • rustfmt --edition 2021 --check src/arithmetic/u32/zero.rs
  • git diff --check

The new raw-witness contract and stack-frontier checks use the strict local tapscript executor with its combined stack limit enforced. Existing vector tests that use the stack-limit-disabled helper remain local research evidence. These checks do not establish Bitcoin Core consensus or relay-policy validity.

Copy link
Copy Markdown
Contributor

Review of ef8c06dc059fe49653ad0e0521c0b7e60e5871a0:

The new boundary tests are useful, but the claimed implementation defect is not reproduced. OP_NOT OP_TOALTSTACK already consumes the current limb. I locally executed the original and proposed fragments with a nonzero runtime witness at each of the four positions; both correctly return false. The added OP_DUP/OP_DROP grows the policy-produced fragment from 53 to 61 bytes without changing that behavior. Please retain the tests and contract clarification, remove the redundant generator change and metric inflation, or supply a counterexample that fails with the original code. Also synchronize the knowledge page's 37-opcode claim with the README if the implementation does change.

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 changed the title fix(u32): consume every checked zero limb test(u32): strengthen checked zero predicate coverage Sep 26, 2026
@brenorb

brenorb commented Sep 26, 2026

Copy link
Copy Markdown
Contributor Author

Addressed in 0b825a7, integrated with main at e9d5a66.

You were right: runtime witnesses with a nonzero limb at each of the four positions return false under both the original and proposed generators. Removed the redundant OP_DUP/OP_DROP change; the policy-produced fragment is again 53 bytes with 37 static non-push opcodes. The PR title/description now reflect test and contract coverage, not an implementation bug fix.

Retained the boundary, preserved-state, and stack-frontier tests. Added a reusable runtime-witness contract check with a valid-input control using the same OP_DROP OP_TRUE cleanup as the negative cases. It checks -1 and 256 at every position for Verify, and five-byte numeric limbs for ScriptIntNumericOverflow. A validation-bypass mutation is caught by that same contract check at the malformed-input assertion. Also corrected the catalog label to distinguish the four-byte unchecked stack helper from the checked predicate.

Validation on the integrated tree: 8 focused library tests, the named u32_zero_metrics_are_current fixture, KB validation, rustfmt, and git diff --check passed. The raw-witness contract and frontier checks use local tapscript execution with the combined stack limit enabled; the retained non-strict helper tests remain research-unlimited. No Bitcoin Core consensus or relay-policy claim is added. No broad repository or field-arithmetic suite was run.

@RobinLinus
RobinLinus merged commit 31b461d into solving-bitcoin:main Sep 28, 2026
3 checks passed
@brenorb
brenorb deleted the fix/u32-zero-boundaries 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