Skip to content

Varops: Two BIPs for Script Restoration: varops calculations and tapleaf version (0xc2).#2118

Open
rustyrussell wants to merge 12 commits intobitcoin:masterfrom
rustyrussell:varops-bips
Open

Varops: Two BIPs for Script Restoration: varops calculations and tapleaf version (0xc2).#2118
rustyrussell wants to merge 12 commits intobitcoin:masterfrom
rustyrussell:varops-bips

Conversation

@rustyrussell
Copy link
Contributor

The full revision history is available in a separate branch (https://github.com/rustyrussell/bips/tree/guilt/varops): this is a clean one to submit for merge.

…eaf version (0xc2).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
@jmoik
Copy link

jmoik commented Mar 9, 2026

to fix the CI we should add Toom = "Toom" to the [default.extend-words] section in .typos.toml.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Copy link
Member

@murchandamus murchandamus left a comment

Choose a reason for hiding this comment

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

I only made it to the Multiply and Divide Opcodes in this first read. I suspect that I’m missing something about how you are describing the opcodes. Please see my comments for details.

@murchandamus murchandamus added the PR Author action required Needs updates, has unaddressed review comments, or is otherwise waiting for PR author label Mar 14, 2026
@rustyrussell rustyrussell force-pushed the varops-bips branch 2 times, most recently from 1cfb44f to c4572fe Compare March 23, 2026 04:20
Great feedback from Murch:
1. Lots of markdown instead of mediawiki formatting fixed.
2. Input count max fixed (explanatory only, but still a good fix).
3. Justification for detailed by-byte nature of descriptions added to global Rationale.
4. Note on truncation moved earlier, and expanded.
5. OP_OR/OP_XOR clarified to make it clear that A is altered "in-place".
6. Clarification on early termination (and thus cost) of OR and XOR.
7. nee is spelled "née" (Julian suggested replacing it, but let's try to keep some culture alive!).
8. Murch is now thanked in the thanks section.

In particular, Murch's confusion was enlightening.  I had not appreciated that
the reduction in script capability (removing all bitops and limiting operand
size) made endian of stack objects very much an *implementation detail*, thus
these descriptions are battling with people's head-canon of how Bitcoin's Stack
Is Just Numbers.

Mere words can only do so much to address this issue, but I've tried, and at
least I'm now aware of this.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
@rustyrussell
Copy link
Contributor Author

@murchandamus thankyou for your detailed review. Here's the comment on the fixup commit which I hope addresses it:

Great feedback from Murch:
1. Lots of markdown instead of mediawiki formatting fixed.
2. Input count max fixed (explanatory only, but still a good fix).
3. Justification for detailed by-byte nature of descriptions added to global Rationale.
4. Note on truncation moved earlier, and expanded.
5. OP_OR/OP_XOR clarified to make it clear that A is altered "in-place".
6. Clarification on early termination (and thus cost) of OR and XOR.
7. nee is spelled "née" (Julian suggested replacing it, but let's try to keep some culture alive!).
8. Murch is now thanked in the thanks section.

In particular, Murch's confusion was enlightening.  I had not appreciated that
the reduction in script capability (removing all bitops and limiting operand
size) made endian of stack objects very much an *implementation detail*, thus
these descriptions are battling with people's head-canon of how Bitcoin's Stack
Is Just Numbers.

Mere words can only do so much to address this issue, but I've tried, and at
least I'm now aware of this.

Copy link
Member

@murchandamus murchandamus left a comment

Choose a reason for hiding this comment

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

Thanks, the additional explanation and additions to the abstract helped.

My first impression from the document titles was that "Restoration of disabled script functionality (Tapscript v2)" would be focused on explaining the functionality of the restored opcodes (and perhaps only maybe mention costs), whereas "Varops Budget For Script Runtime Constraint" would expound on the budget and how the costs were found. It seemed to me that you were splitting the content for users of script from the content for the implementers.

In hindsight, I should have first read "Varops Budget For Script Runtime Constraint", I think "Restoration of disabled script functionality (Tapscript v2)" would have made more sense to me after that. Either way, the title "Restoration of disabled script functionality (Tapscript v2)" does not set the expectation that the main focus of the document would be to provide Rationale for the costs of the restored opcodes.

@rustyrussell
Copy link
Contributor Author

Thanks, the additional explanation and additions to the abstract helped.

My first impression from the document titles was that "Restoration of disabled script functionality (Tapscript v2)" would be focused on explaining the functionality of the restored opcodes (and perhaps only maybe mention costs), whereas "Varops Budget For Script Runtime Constraint" would expound on the budget and how the costs were found. It seemed to me that you were splitting the content for users of script from the content for the implementers.

Yes, the split is kind of awkward :(

In hindsight, I should have first read "Varops Budget For Script Runtime Constraint", I think "Restoration of disabled script functionality (Tapscript v2)" would have made more sense to me after that. Either way, the title "Restoration of disabled script functionality (Tapscript v2)" does not set the expectation that the main focus of the document would be to provide Rationale for the costs of the restored opcodes.

If we were to put restoration first, that BIP would become trivial. But, also, kinda useless? The varops budget BIP would then have to re-describe the restored opcodes in precise detail, in order to derive their costs.

I guess there are three parts:

  1. The concepts of varops, such as it limits and factors for different kinds of work opcodes can do.
  2. The restoration of script: removing length limits, making numbers unsigned, restoring old opcodes (presumably with a mention that this is deeply unsafe without the new varops).
  3. The reference-style listing and derivation of varops costs for every opcode.

Happy to do this. If so, would number 3 be a separate BIP, or a giant appendix? I think I'm too close to it to see it through fresh eyes, so I'll take your advice here? Help!

@murchandamus
Copy link
Member

I think my confusion was mostly caused by reading the documents in the order they appear in this PR instead of the intended order. When they’re assigned numbers, putting them in the order of recommended reading should mostly resolve that. The "Restoration" BIP should then also have a Requires header along the lines of “Requires: Varops BIP" in the Preamble to clarify.

After that, the split into three documents does not seem necessary.

Perhaps some tweaks to the tables would be able to address both parts of the audience. (This is a spontaneous suggestion, please feel free to reject or amend as makes sense to you.)

I’m thinking the following might help:

  • Required Stack Elements is a bit of a waste of space. Replace it with a column "Inputs", "Operands", or "Input Stack". This could communicate the count of operands and save you the "Pop x off the stack" lines in the Definition.
  • I would refer to the number as the opcode, so maybe rename "Opcode" to "Operation" or "Word" and "value" to "Opcode".
  • Add a column "Description" that gives a very short summary of what the opcode does. Between the Operands column and Description, the functionality should be clear enough to the Script users that read the BIP.
  • Then perhaps move the Varops Cost and Varops Reason to the end, to illustrate that they follow from the Definition.
image

That would make the columns:

| Operation | Opcode | Inputs | Description | Definition | Varops Cost | Varops Reason |

rustyrussell and others added 4 commits March 24, 2026 13:44
minimum signature size fix from Murch.

Co-authored-by: Mark "Murch" Erhardt <murch@murch.one>
More refinement from Murch:
1. v2 is bad, be explicit with 0xC2 Tapleaf.
2. Title was over 50 chars.
3. Footnote for normalization decisions (mainly, legacy)
4. Cleaner quote of bip-0342, for nice line-wrap.
5. OP_RIGHT clarification (esp. if offset > length).
6. OP_2MUL and OP_2DIV clarification (bit moves across bytes) to
   match how detailed we were in OP_ADD.
7. Use explicit language on what ops are cost 0.
8. Be consistent with "64-bit" vs "64 bit".

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
All fixes reported by Murch, who is slowly teaching me mediawiki.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog section added.

Reported-by: Murch
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Murch had more great feedback:
1. Add Requires: line to header.
2. Refer to stack elements by names, not just number for clarity.
3. Add a human-readable opcode description.
4. Reorder and rename fields.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Copy link
Member

@murchandamus murchandamus left a comment

Choose a reason for hiding this comment

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

Looks good, except for one more MediaWiki quirk and a potential issue in OP_RIGHT.

Copy link
Member

@murchandamus murchandamus left a comment

Choose a reason for hiding this comment

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

Noticed a few more minor things when scanning the changes from the last version I reviewed.

More formatting from Murch: [A B] renders as [A], so we need nowiki,
and using ## for the BIP quote doesn't work well, so opencode the number
and italizice.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
More Murch's sharp eyes:
1. Missing - in "128 bit".
2. Bad description of OP_RIGHT.
3. Missing "be" in sentence.
4. Clarify OP_DIV2 takes top bit of next byte as bottom bit.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Use correct values for costs in Rationale (they were updated).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
linewrap at 78 chars (except in tables)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
@rustyrussell
Copy link
Contributor Author

Note: I noticed that we used the marker ARITH on some costs. This is not present in the varops BIP: I'm consulting with @jmoik now to see if this is a simple omission, or requires deeper change :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs number assignment New BIP PR Author action required Needs updates, has unaddressed review comments, or is otherwise waiting for PR author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants