Skip to content

feat(u32): add embedded constant XNOR - #147

Merged
RobinLinus merged 7 commits into
solving-bitcoin:mainfrom
brenorb:feat/u32-xnor-constant
Sep 28, 2026
Merged

RobinLinus merged 7 commits into
solving-bitcoin:mainfrom
brenorb:feat/u32-xnor-constant

Conversation

@brenorb

@brenorb brenorb commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Adds checked XNOR between a four-byte runtime u32 word and a public embedded mask. The fragment validates every original limb for byte range and canonical ScriptNum encoding, uses and removes the shared Boolean table, and returns four result limbs in their original order.

The mask 0x89abcdef configuration measures 686 policy-produced script bytes, 13 serialized data-witness bytes across four items, zero hints, a 272-item combined-stack peak, and 502 static non-push opcodes. This is a fragment-with-memory boundary; data witness bytes exclude Taproot transaction framing. Evidence is locally-reproduced and deployment remains unclassified.

Current main is integrated while retaining its catalog entries, APIs, exports, and metric tests. Coverage includes runtime result/order checks, malformed raw encodings at every position under a permissive numeric-encoding profile, valid controls, a faithful historical mutant, and surrounding-state preservation.

Validation: three focused library tests, the named metric test, KB validation (102 records / 257 configurations), formatting, and whitespace checks passed. No Bitcoin Core or relay-policy validation is claimed.

Copy link
Copy Markdown
Contributor

Review: changes required before merge.

The checked byte boundary misses three original input limbs. With four witness items encoding numeric 1, replacing any bottom-based position 0, 1, or 2 by the nonminimal encoding [0x01, 0x00] still succeeds under the local Tapscript Consensus profile after consuming the four outputs and appending OP_TRUE. Position 3 is rejected. Validate each original byte before arithmetic normalizes it; move or stage the validated limb before repeating the check. Add malformed-encoding regressions at every position under a profile that permits nonminimal numeric encodings globally.

Evidence: locally-reproduced against the proposed implementation; local fragment execution only, deployment unclassified. This is not Bitcoin Core or complete-spend validation. Run the affected module tests and focused metric check after the fix.

Reviewed commit: 47c1a7141ad91e54ec6b8494b10e2e1b6f8f6d2d.

@brenorb
brenorb force-pushed the feat/u32-xnor-constant branch from 47c1a71 to 3a9a077 Compare September 19, 2026 01:34
@brenorb

brenorb commented Sep 19, 2026

Copy link
Copy Markdown
Contributor Author

Updated in commit 3a9a077 (branch feat/u32-xnor-constant).

The fix validates each original hostile limb before normalization by rotating the next limb into the checker with 3 OP_ROLL. Tests now run with require_minimal: false and stack-limit enforcement, reject malformed/nonminimal encodings at every position, and accept canonical boundary values 128 and 255 at every position.

Refreshed metrics/docs: 686 script bytes, 502 static non-push opcodes, 272 peak stack items, 13-byte witness.

Validation passed:

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

Copy link
Copy Markdown
Contributor

Review of 3a9a077231a06f09da54261af00ffde4933c60ac:

The validator now rotates through all four original limbs, addressing the earlier top-limb-only check. Preserve malformed/nonminimal inputs at every position and the XNOR result/order regressions. Rebase and rerun the focused XNOR and named metric checks plus KB validation.

Current integration conflicts: knowledge/catalog.json, knowledge/comparisons/arithmetic.md, knowledge/primitives/index.md, src/arithmetic/u32/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 1c0e0a2b60349f74a862d6764d43bc265e7b7af9, integrating current main while preserving its existing XNOR APIs, catalog records, module exports, and active metric tests.

  • Reproduced the historical issue at 47c1a7141ad91e54ec6b8494b10e2e1b6f8f6d2d: with four runtime inputs encoding numeric 1, nonminimal [0x01,0x00] inputs at positions 0–2 passed, while position 3 failed. The complete leaf consumes all four outputs before its terminal true item. The local Consensus profile permits nonminimal numeric encodings globally and enforces the stack limit.

  • The current PR already advances through all four original limbs. That production fix is preserved.

  • Reworked the raw-input tests around one policy-compiled complete-leaf wrapper and explicit local Consensus profile. Valid controls now require successful execution; every position tests -1/256 (Verify), negative zero/nonminimal one (EqualVerify), and five-byte numeric overflow (ScriptIntNumericOverflow). Canonical 128/255 controls remain covered.

  • The same all-position rejection predicate catches a faithful test-only unrotated validator. Its canonical control must succeed; malformed positions 0–2 must succeed and position 3 must produce EqualVerify, matching the historical defect.

  • Runtime result/order checks use the existing shared strict witness harness, six boundary/pattern pairs, and 100 deterministically seeded pairs. Preserved main/alt-stack checks remain in place.

  • All 101 existing main catalog records are unchanged; existing module exports and metric tests are retained. Corrected measurement/provenance wording without changing the metric fixture.

Validation: 3 focused library tests passed, the named metric test passed, KB validation passed (102 records / 257 configurations), and formatting/whitespace checks passed. Current execution uses interpreter a09e87af444034698697f0a2267e755cf72f9aed and compiler 124b561ed75ac3ec4c6ad99207d8dcdd3bc67180. The measured configuration remains 686 policy-produced fragment bytes, 13 serialized data-witness bytes, four data items, zero hints, a 272-item combined-stack peak, and 502 static non-push opcodes. The metric leaf discards its outputs; correctness is checked separately by the runtime result assertions.

Historical execution used compiler 124b561ed75ac3ec4c6ad99207d8dcdd3bc67180 and interpreter 702544c9a045ac4fc14846da6da6559e2b7cd9d1. These are local interpreter results, not Bitcoin Core or relay-policy validation.

@RobinLinus
RobinLinus merged commit b5fb5a1 into solving-bitcoin:main Sep 28, 2026
3 checks passed
@brenorb
brenorb deleted the feat/u32-xnor-constant 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