Implement BIP 440 & 441 (Script Restoration in new Tapleaf 0xc2) - #119
Draft
jmoik wants to merge 14 commits into
Draft
Implement BIP 440 & 441 (Script Restoration in new Tapleaf 0xc2)#119jmoik wants to merge 14 commits into
jmoik wants to merge 14 commits into
Conversation
added 5 commits
July 29, 2026 10:54
Add the transaction-wide budget carrier and BIP 440 and BIP 441 cost helpers used by tapscript v2 execution. Include focused unit coverage for the budget carrier and cost formulas. Execution plumbing and opcode charging follow in later commits.
Add the Bitcoin-specific arbitrary-length unsigned value type used by tapscript v2 arithmetic and bit operations. Use little-endian logical values and aligned 64-bit words while accounting for operation costs through the varops helpers.
Add conversion vectors and deterministic coverage for Val64 arithmetic, representation invariants, portable wide arithmetic, and edge cases. Use Boost multiprecision as an independent test oracle.
Add ValtypeStack, a const-access stack wrapper that tracks element sizes across every mutation. Wire the stack into the production targets; evaluator integration follows later.
Add the 0xc2 leaf version, TAPSCRIPT_V2 sigversion, resource limits, and script errors used by tapscript v2 execution. Move SigVersion to script.h and add IsTapscript() so shared callers can classify both script-path versions. Make OP_SUCCESS classification sigversion-aware, restoring the BIP 441 opcodes for 0xc2 without changing BIP 342 behavior. Add compile-time proofs that maximum-size varops cost expressions fit in uint64_t.
Collaborator
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
This was referenced Jul 30, 2026
added 4 commits
August 11, 2026 23:19
Add an explicit-budget VerifyScript overload and thread the budget through witness execution and CScriptCheck. Give all checks for one transaction a shared atomic budget derived from its weight. Retain the existing unlimited-budget overload for compatibility. Give each standalone PSBT input check a fresh budget derived from finalized transaction weight.
Copy the existing EvalScript() body into an overload that takes an
explicit varops budget. Keep the function bodies byte-for-byte
identical so this commit remains a mechanical review checkpoint.
Semantic changes follow in a later commit.
Verify the copy with:
./contrib/devtools/verify-evalscript-copy.sh <this-commit>
Register BIN-2026-0441-000 as SCRIPT_RESTORATION with consensus and policy verification gating. This gives signet the 2026 deployment window and keeps the deployment always active on regtest through the generated Inquisition parameters.
Route activated 0xc2 leaves through a dedicated evaluator while leaving legacy script and BIP 342 paths unchanged. Implement the BIP 441 restored opcodes and unsigned numeric semantics, enforce the expanded stack resource limits, and charge BIP 440 varops before costly operations. Apply tapscript v2 signature hashing, OP_SUCCESS handling, and final cleanstack and truthiness rules.
added 5 commits
August 12, 2026 17:13
Propagate the 0xc2 leaf version and TAPSCRIPT_V2 sigversion through Schnorr signing, PSBT, RPC, wallet, and bitcoin-util paths. Verify finalized transactions under one transaction-wide varops budget. Let bitcoin-util evalscript accept an explicit budget and report the remaining amount.
- Add JSON vectors and unit coverage for ValtypeStack, varops, restored opcodes, and edge cases. - Add bitcoin-util fixtures for Tapscript v2 evaluation paths. - Migrate existing tests to the explicit varops-budget API.
- Add SCRIPT_RESTORATION activation coverage and focused Tapscript v2 spend tests. - Replay shared Taproot mechanics under 0xc2 leaves while filtering semantics that intentionally diverge from c0/APO. - Register the focused functional tests with the test runner.
Exercise budget accounting, evaluator invariants, stack programs and resource limits, and signature and timelock behavior against independent expected results. Check Val64 arithmetic, predicates, bitwise shifts, and large multiply, divide, and modulo operations against Boost multiprecision.
Add a standalone bench_varops executable that materializes and preflights a declarative corpus of opcode saturation and budget-boundary cases, then measures it against a raw Schnorr baseline. Use deterministic discovery and stable-measurement rounds, support filtered and validation-only runs, and atomically write summary and sample data to CSV. Add CTest coverage for invalid opcodes and output failures.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implement BIP 440 & BIP 441
Summary
This PR implements BIP 440 — Varops Budget For Script Runtime Constraint
and BIP 441 — Restoration of disabled script (Tapleaf 0xC2)
on Bitcoin Inquisition
29.x.BIP 440 introduces a transaction-wide varops budget. BIP 441 uses that budget
to restore Script functionality in tapleaf version
0xc2.Deployment
The rules are registered as
BIN-2026-0441-000/SCRIPT_RESTORATION.On signet, signalling has been permitted since 2026-01-01. The deployment
times out on 2036-01-01 and uses 432-block periods.
Before activation,
0xc2retains unknown-tapleaf behavior. After activation,it is evaluated as Tapscript v2.
Implementation structure
EvalScriptfor the new script evaluatorSCRIPT_RESTORATIONdeploymentNotes
enabled in Tapscript v2.
OP_CHECKTEMPLATEVERIFYremains an upgradable NOP in0xc2, whileOP_CHECKSIGFROMSTACK,OP_INTERNALKEY, andOP_TEMPLATEHASHretainOP_SUCCESS semantics. ANYPREVOUT-prefixed public keys similarly remain
unknown public-key types.
OP_CATis the exception: it is enabled directlyby BIP 441 with the Tapscript-v2 semantics defined there.
boost-multiprecisionis used only as an independent oracle in Val64 unitand fuzz tests. It is not used by production consensus code.
bench_varopsis included so the cost calibration and worst-case scriptscan be tested on additional hardware. Existing results are collected in
varopsData.
Testing
Coverage includes varops accounting, Val64 arithmetic, restored opcodes,
stack-resource boundaries, activation behavior, transaction-wide budgeting,
signatures and timelocks, policy boundaries, functional tests and fuzz targets.
Frontier LLMs were also used to independently verify the test structure and expected results against the BIP 440 and BIP 441 specifications.