Skip to content

TAPSCRIPT_V2 (Great Script Restoration)#104

Open
jmoik wants to merge 70 commits intobitcoin-inquisition:29.xfrom
jmoik:inquisitionGsr
Open

TAPSCRIPT_V2 (Great Script Restoration)#104
jmoik wants to merge 70 commits intobitcoin-inquisition:29.xfrom
jmoik:inquisitionGsr

Conversation

@jmoik
Copy link

@jmoik jmoik commented Jan 30, 2026

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:

  • Added JSON test vectors for varops costs and restored opcodes
  • Added bench_varops benchmarks
  • Added Val64 unit tests and valtype_stack_tests
  • Added functional tests for tapscript v2

rustyrussell and others added 30 commits January 12, 2026 22:58
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.
…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
…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
… 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
…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
jmoik added 21 commits January 30, 2026 11:22
* 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
@DrahtBot
Copy link
Collaborator

DrahtBot commented Feb 1, 2026

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #108 (PoC: tooling for OP_TEMPLATEHASH by darosior)
  • #102 (OP_CHECKCONTRACTVERIFY by bigspider)
  • #100 (BIP446 "OP_TEMPLATEHASH" implementation by darosior)

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.

@ajtowns ajtowns added this to the 29.x milestone 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this policy check matches the consensus limit, no need?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


try:
# NOTE: We can't directly test the 4MB limit because Bitcoin's 100KB
# transaction size limit prevents creating such large witness data.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no such limit in consensus, just make the tx then directly mine them

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.

5 participants