Skip to content

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 27 commits January 30, 2026 11:22
New bench_bitcoin tests:
  - evalscript: similar to bench_varops
  - micro: low-level memcmp/memset/memcpy benchmark variants
  - val64: Val64 class benchmarks to try to tweak out worst case.
…d gsr_tests to execute the test vectors, add valtype_stack_tests
* 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:

  • #102 (OP_CHECKCONTRACTVERIFY by bigspider)
  • #100 (OP_TEMPLATEHASH 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.

This was referenced Feb 1, 2026
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.

3 participants