Skip to content

Add complete-witness tapscript execution and budget accounting - #23

Open
adrienlacombe wants to merge 1 commit into
BitVM:masterfrom
adrienlacombe:codex/tapscript-witness-budget
Open

adrienlacombe wants to merge 1 commit into
BitVM:masterfrom
adrienlacombe:codex/tapscript-witness-budget

Conversation

@adrienlacombe

@adrienlacombe adrienlacombe commented Sep 20, 2026

Copy link
Copy Markdown

A tapscript execution initialized from only its data stack can reject a valid spend at the signature-budget boundary because BIP342 also counts the script, control block, annex and CompactSize prefixes. Add Exec::new_tapscript(options, tx) to derive the execution context and 50 + complete witness size budget from the selected transaction input. Existing explicit-script constructors retain their compatibility behavior.

The constructor rejects malformed or inconsistent context, derives the annex for signature hashing, and requires the complete prevout list. It does not validate the Taproot output commitment, full transaction, relay policy or unsupported OP_SUCCESS behavior. Signature charges are now reflected in statistics even when the opcode fails.

Validation: cargo test --locked --offline --workspace --all-features passes all 21 tests (11 existing unit tests, nine new regression tests and one doctest). The new tests cover all three signature opcodes at exact exhaustion and negative budgets, empty and failed signatures, real annex-bound Schnorr signatures, CompactSize boundaries, control-path sizes, malformed context, constructor compatibility and selection of input 1 from a two-input transaction. Upstream does not track Cargo.lock; an ignored lockfile was generated offline for this run.

The accounting follows BIP342 and Bitcoin Core v30.3. This patch is based directly on upstream master and does not depend on the other pending interpreter repairs.

Independent funded validation is recorded in solving-bitcoin/bitcoin-scripts#240: all 32 complete-witness comparisons match Bitcoin Core v30.3, including rejection categories, and two fresh nodes produce identical reports. These runs use an integration that retains the existing interpreter repairs; the legacy and new constructors are compared at that same revision. Core accepts 15 spends under consensus and 10 under policy, while the legacy constructor disagrees on 16 cases.

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.

1 participant