Skip to content

feat(u32): add embedded constant OR - #146

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

RobinLinus merged 4 commits into
solving-bitcoin:mainfrom
brenorb:feat/u32-or-constant

Conversation

@brenorb

@brenorb brenorb commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Adds checked OR 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 0x89abcdef mask configuration measures 776 policy-produced script bytes, 13 serialized data-witness bytes across four items, zero hints, a 272-item combined-stack peak, and 548 static non-push opcodes. This fragment-with-memory boundary includes table setup and cleanup. Data-witness bytes exclude Taproot transaction framing. Evidence is locally-reproduced and deployment remains unclassified.

The integrated tree preserves current main's catalog records, module exports, existing OR APIs, and active metric tests. Tests exercise runtime result/order correctness, raw malformed inputs at every position, successful controls, the historical no-rotation mutant, and surrounding-state preservation.

Validation passed: three focused library tests, the named metric check, KB validation (102 records / 257 configurations), formatting, and whitespace checks. Historical source inspection is backed by a faithful locally executed mutant; 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: 2ee1cfc7f7211054b8b970d0e109f4fe6cbd36c6.

@brenorb
brenorb force-pushed the feat/u32-or-constant branch from 2ee1cfc to 4f1e704 Compare September 19, 2026 01:27
@brenorb

brenorb commented Sep 19, 2026

Copy link
Copy Markdown
Contributor Author

Updated in commit 4f1e704 (branch feat/u32-or-constant).

The fix validates each original hostile limb before table setup, including nonminimal [1, 0] at every position. Tests also cover malformed zero/negative/overflow encodings and canonical boundary values 128 and 255. Refreshed metrics/docs: 776 script bytes, 548 static non-push opcodes, 272 peak stack items.

Validation passed:

  • cargo test --locked --lib arithmetic::u32::or_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 4f1e704b6df753f9d72b52f8d3ef96c518a23935:

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 OR result/order regressions. Rebase and rerun the focused OR and named metric checks plus KB validation.

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

  • Inspected the exact historical source and lockfile at 2ee1cfc7f7211054b8b970d0e109f4fe6cbd36c6: the validator repeatedly checked the same top limb. The current PR already rotates through all four original limbs, and that production fix is unchanged.
  • The raw-input regression now uses a complete leaf that consumes all four hypothetical outputs before OP_TRUE, under the local Consensus profile with global numeric minimality disabled and the stack limit enabled. Valid controls must actually succeed. Every position checks -1/256 (Verify), negative zero/nonminimal one (EqualVerify), and five-byte overflow (ScriptIntNumericOverflow); canonical 128/255 controls are retained.
  • A faithful test-only no-rotation mutant uses the same wrapper, profile, and all-position rejection predicate. Its valid control must succeed; it accepts aliases at positions 0–2 and rejects position 3 with EqualVerify. This mutant was executed under the current interpreter; the historical checkout was source-inspected, not re-executed under its old interpreter.
  • Result/order checks use runtime witnesses through the existing shared strict success harness, with six boundary/pattern cases and 100 seeded cases. Existing main/alt-stack preservation remains covered.
  • Corrected stale README values and the generic canonical eight-item data-witness maximum (25 bytes). Removed an unsupported script-cost comparison. All 101 existing main catalog records remain unchanged; only this target record is added.

Validation: 3 focused library tests passed, the named metric passed, KB validation passed (102 records / 257 configurations), and formatting and whitespace checks passed. The unchanged metric fixture measures 776 policy-produced fragment bytes, 13 serialized data-witness bytes, four data items, zero hints, a 272-item combined-stack peak, and 548 static non-push opcodes. It discards outputs; separate correctness tests compare the OR result.

Current runs use compiler 124b561ed75ac3ec4c6ad99207d8dcdd3bc67180 and interpreter a09e87af444034698697f0a2267e755cf72f9aed. The inspected historical lockfile pins interpreter 702544c9a045ac4fc14846da6da6559e2b7cd9d1. Evidence remains local and deployment unclassified; no Bitcoin Core or relay-policy validation is claimed.

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