TAPSCRIPT_V2 (Great Script Restoration)#104
Open
jmoik wants to merge 70 commits intobitcoin-inquisition:29.xfrom
Open
TAPSCRIPT_V2 (Great Script Restoration)#104jmoik wants to merge 70 commits intobitcoin-inquisition:29.xfrom
jmoik wants to merge 70 commits intobitcoin-inquisition:29.xfrom
Conversation
Not a generic 64-bit access wrapper, but a very bitcoin-specific
one.
TODO: This was developed in pieces, and I should deconstruct it into separate
commits, with tests, for easy review.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
…nally tracks element size counts for efficient calculation of total stack size and maximum element size. This avoids the need to iterate through all elements during script execution.
…ine endian fixers, adjust varop costs
…rt, extend enum class SigVersion by TAPSCRIPT_V2 and move it from interpreter.h to script.h
…t() and add tapscript_v2 witness script execution
…teWitnessScript()
…le restored opcodes in tapscript_v2
…stack() pushVal64() and stackPushCosted() helper functions
… this overload is used with SigVersion::TAPSCRIPT_V2 (to verify that the function bodies are identical run ./test/lint/verify-evalscript-copy.sh <commit_hash>)
…pscript_v2 EvalScript to make it compatible with the following GSR changes
…ad, since it always uses tapscript_v2
… const qualifiers to stacktop() values, since ValtypeStack does not support getters for mutable references
…criptNum (non-arithmetic opcodes). The following non-arithmetic opcodes interpret numbers on the stack as CScriptNum: 1. OP_CHECKLOCKTIMEVERIFY. 2. OP_CHECKSEQUENCEVERIFY. 3. OP_VERIFY. 4. OP_ROLL. 5. OP_CHECKSIGADD. In the first two cases, all numbers > 2^32-1 are equivalent, and we can easily represent them as CScriptNum (which is an int64_t internally). OP_VERIFY uses CastToBool which unfortunately treats "negative zero" as false. OP_ROLL is invalid if the value is greater or equal to the stack depth, so we can cap value conversion at that. OP_CHECKSIGADD doesn't really care about the number, it just adds 1 and puts it back.
…TSTACK, OP_FROMALTSTACK, OP_DUP, OP_2DUP, OP_3DUP, OP_2OVER, OP_OVER, OP_TUCK, OP_IFDUP
…riptNum for OP_DEPTH and OP_SIZE
…DD, OP_1SUB, OP_NOT, OP_0NOTEQUAL; OP_NEGATE and OP_ABS are OP_SUCCESS in tapscript v2
…D, OP_SUB, OP_BOOLAND, OP_NUMNOTEQUAL, OP_LESSTHAN, OP_GREATERTHAN, OP_LESSTHANOREQUAL, OP_GREATERTHANOREQUAL, OP_MIN, OP_MAX
* OP_CAT * OP_SUBSTR * OP_LEFT * OP_RIGHT * OP_INVERT * OP_2MUL * OP_2DIV * OP_AND * OP_OR * OP_XOR * OP_MUL * OP_DIV * OP_MOD * OP_LSHIFT * OP_RSHIFT
…Script() to EvalGsrScript()
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 Feb 1, 2026
instagibbs
reviewed
Feb 6, 2026
| static constexpr unsigned int MAX_STANDARD_P2WSH_STACK_ITEM_SIZE{80}; | ||
| /** The maximum size in bytes of each witness stack item in a standard BIP 342 script (Taproot, leaf version 0xc0) */ | ||
| static constexpr unsigned int MAX_STANDARD_TAPSCRIPT_STACK_ITEM_SIZE{80}; | ||
| static constexpr unsigned int MAX_STANDARD_TAPSCRIPT_V2_STACK_ITEM_SIZE{4000000}; // 4MB |
There was a problem hiding this comment.
this policy check matches the consensus limit, no need?
Author
There was a problem hiding this comment.
yes good point, we have not discussed policy changes yet, so this limit is still open to discussion and should be added to the BIP too
instagibbs
reviewed
Feb 6, 2026
|
|
||
| try: | ||
| # NOTE: We can't directly test the 4MB limit because Bitcoin's 100KB | ||
| # transaction size limit prevents creating such large witness data. |
There was a problem hiding this comment.
there's no such limit in consensus, just make the tx then directly mine them
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.
This pull request implements the following two BIPs:
Varops Budget
Great Script Restoration
Summary of Changes:
Added new SigVersion::TAPSCRIPT_V2 with leaf version 0xc2
Restored 15 disabled opcodes: OP_CAT, OP_SUBSTR, OP_LEFT, OP_RIGHT, OP_INVERT, OP_2MUL, OP_2DIV, OP_AND, OP_OR, OP_XOR, OP_MUL, OP_DIV, OP_MOD, OP_LSHIFT, OP_RSHIFT
Generalized the sigops budget by introducing the varops budget system for tracking computational costs
OP_NEGATE, OP_ABS, and OP_1NEGATE became OP_SUCCESS in tapscript v2
Added variabel size unsigned integer class Val64 for arithmetic operations
Added ValtypeStack class for efficient stack size tracking without iteration
Numbers are interpreted as varnums instead of CScriptNum in tapscript v2
Final on-stack value is interpreted as unsigned in tapscript v2
Tests & Benchmarks: