Skip to content

feat(u4): add adjacent equality mask - #201

Merged
RobinLinus merged 4 commits into
solving-bitcoin:mainfrom
brenorb:feat/u4-adjacent-eq-next
Sep 28, 2026
Merged

RobinLinus merged 4 commits into
solving-bitcoin:mainfrom
brenorb:feat/u4-adjacent-eq-next

Conversation

@brenorb

@brenorb brenorb commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

This adds a range-checked u4 adjacent-equality mask: n numeric inputs produce n-1 equality bits in input order. Numeric equality treats alternative ScriptNum encodings of the same value equally; canonical byte encoding is not required by this contract.

The representative 32-input fragment has 558 policy-produced script bytes, 65 serialized data-witness bytes across 32 items and zero hints, a 64-item combined-stack peak, and 361 static non-push opcodes. Evidence is locally-reproduced and deployment remains unclassified; no Bitcoin Core or relay-policy validation is claimed.

Integration preserves current main's catalog records, module exports, documentation, and active metrics. Regression coverage checks raw numeric aliases and output order with complete terminal assertions. A deliberate byte-comparison mutant must fail the same success assertion.

Validation: five focused adjacent-equality library tests, the named metric check, KB validation, formatting, and whitespace checks. No broad or field-arithmetic suite and no metric refresh were run.

Copy link
Copy Markdown
Contributor

Review: changes required before merge.

For the two witness items [0x01] and [0x01, 0x00], both numeric values are 1 and both pass the range checks, but the adjacent-equality result is 0. The copied values are checked numerically and then the original encodings are compared with OP_EQUAL, which compares bytes. Use numeric equality after validating the numeric domain, or reject noncanonical encodings before comparison. Add a regression with these mixed encodings; the strict helper's global minimal-number flag hides this case.

Evidence: locally-reproduced with the repository's explicit TapscriptProfile::Consensus local interpreter, using the PR source and a complete terminal check for the incorrect output. Deployment remains unclassified; this is not a Bitcoin Core result.

Reviewed commit: 5887aff284f4c3be2acb4adf52caae73eb18ea6e.

@brenorb

brenorb commented Sep 19, 2026

Copy link
Copy Markdown
Contributor Author

Updated in commit d8fd99b (branch feat/u4-adjacent-eq).

The adjacent comparison now uses OP_NUMEQUAL, preserving the numeric range-checked contract while treating canonical and nonminimal encodings of the same value as equal. Tests run under require_minimal: false with stack enforcement cover [1]/[1,0] in both orders, zero aliases, asymmetric mixed outputs, invalid values at both positions with explicit errors, and preserved main/alt-stack state.

Metrics/docs remain synchronized: 558 script bytes, 361 static non-push opcodes, 64-item peak, 65-byte canonical fixture witness.

Validation passed:

  • cargo test --locked --lib arithmetic::u4::adjacent_eq::tests (4 passed)
  • cargo test --locked --test primitive_metrics (34 passed, 1 ignored)
  • cargo fmt --all -- --check
  • python3 tools/kb.py validate
  • git diff --cached --check

@brenorb
brenorb force-pushed the feat/u4-adjacent-eq-next branch from 5887aff to d8fd99b Compare September 19, 2026 02:40

Copy link
Copy Markdown
Contributor

Review of d8fd99b3653cd6d305e78e32b21bcfb661a842d5:

The numeric equality change addresses the earlier raw-encoding mismatch. Preserve the alias and asymmetric output-order tests while rebasing; rerun the adjacent-equality library tests, the named metric check, and KB validation against current main.

Current integration conflicts: knowledge/catalog.json, knowledge/comparisons/arithmetic.md, knowledge/primitives/index.md, src/arithmetic/u4/README.md, src/arithmetic/u4/mod.rs, tests/primitive_metrics.rs. These must be resolved and the integrated result validated before merging.

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 5e33b15bb21e46c63ef4f874a85c45755e125f17, integrating current main while retaining its catalog records, module exports, README additions, and active metric tests.

  • Preserved the existing numeric comparator and asymmetric output-order regression. Raw-witness alias/output tests now use the explicit local Consensus profile and a shared assertion requiring executed success, no error, stack-limit enforcement, and exactly one true terminal item.
  • Inspected the retained pre-fix source at a5f2b7224390c0c8e24eec4e0ee6cb0c17aea764, which used OP_EQUAL. A test-only byte-comparison mutation recreates that behavior on [01] / [01,00]; it fails with Verify and is caught by the same expected-success assertion. Mutant construction and execution occur outside the panic-catching assertion, so setup failures cannot count as evidence.
  • Added raw mixed-encoding coverage for the asymmetric mask [1,0,1,0,0], checking every result in order. Malformed-input checks cover -1, 16, and five-byte numeric overflow at both positions of the two-input configuration, with exact typed errors and a valid control using the same complete leaf.
  • Kept the supported batch limit at 499 and described it as conservative rather than claiming a proven maximal frontier. Removed the unsupported 65-byte maximum-witness claim; 65 bytes remains the measured canonical fixture, while permitted numeric aliases can be longer.
  • Representative metrics remain 558 policy-produced fragment bytes, 65 serialized data-witness bytes (32 data items, zero hints), 64 combined stack items, and 361 static non-push opcodes. Evidence remains locally-reproduced / unclassified; no Bitcoin Core or relay-policy result is claimed.

Validation on the integrated tree: all 5 adjacent-equality library tests, u4_adjacent_equal_metrics_are_current, KB validation (102 records / 257 configurations), formatting, and whitespace checks passed. No broad or field-arithmetic test run and no metric refresh were performed.

@RobinLinus
RobinLinus merged commit 0d24437 into solving-bitcoin:main Sep 28, 2026
3 checks passed
@brenorb
brenorb deleted the feat/u4-adjacent-eq-next 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