Skip to content

Conversation

@jamesob
Copy link
Contributor

@jamesob jamesob commented Mar 4, 2025

This implements BIP-119 (OP_CHECKTEMPLATEVERIFY), but only specifies a regtest deployment. There is no effective policy change, since the SCRIPT_VERIFY_* flags (as used) result in the same NOP-like behavior.

This change can be composed with other opcode specifications (e.g. CSFS, CAT) and bundled into the same deployment (yet to be specified).

I encourage more general, conceptual discussion to happen on Delving Bitcoin and not on this pull request.

Some related discussion on Delving Bitcoin here:

See also:

@DrahtBot
Copy link
Contributor

DrahtBot commented Mar 4, 2025

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

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/31989.

Reviews

See the guideline for information on the review process.

Type Reviewers
Concept NACK BitcoinErrorLog, darosior
Concept ACK jaybny, moonsettler, stevenroose, jonatack, delta1, prasincs, pinheadmz, average-gary, ariard
Stale ACK JeremyRubin

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #32998 (Bump SCRIPT_VERIFY flags to 64 bit by ajtowns)
  • #32729 (test,refactor: extract script template helpers & widen sigop count coverage by l0rinc)
  • #32453 ([Policy] Discourage Unsigned Annexes by JeremyRubin)
  • #29843 (policy: Allow non-standard scripts with -acceptnonstdtxn=1 (test nets only) by ajtowns)
  • #29247 (CAT in Tapscript (BIP-347) by arminsabouri)
  • #26201 (Remove Taproot activation height by Sjors)

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.

@jamesob jamesob changed the title Add BIP-119 (OP_CHECKTEMPLATEVERIFY) (no activation) BIP-119 (OP_CHECKTEMPLATEVERIFY) (no activation) Mar 5, 2025
@BitcoinErrorLog
Copy link

NACK. As Towns just pointed out on the mailing list, this proposal represents an unsolicited modification of Bitcoin’s code and consensus rules. There is no clear user demand, no demonstrated market need, and no compelling application that justifies taking on this risk. The absence of significant business interest or ecosystem momentum further underscores the speculative nature of this change.

Bitcoin’s resilience depends on its conservatism. To safeguard against unnecessary complexity and centralized agenda-setting, we should reject rule changes that lack overwhelming, emergent consensus.

Until we establish clear standards for what constitutes legitimate consensus-driven changes and market-driven necessity, rather than academic or developer curiosity, proposals of this nature should be treated as research, not candidates for inclusion in Core.

@melvincarvalho
Copy link

Echoing what @BitcoinErrorLog said—clear user demand must be shown to justify this. Any proposed change should be weighed against the worst-case scenario: civil war or a chain split, which we’ve seen before. The use case needs to be so compelling that it decisively outweighs these risks and gains overwhelming community support.

@1440000bytes

This comment was marked as abuse.

@willcl-ark
Copy link
Member

@jamesob I'd be happy to help you keep this thread focused by moderating off-topic comments and pointing them to the appropriate forums.

You've suggested and linked to Delving which seems appropriate for general/conceptual discussion, however there is no thread/post over there to actually point folks to.
Would you mind starting a thread over there so that we have somewhere concrete to point these types of discussions to?

@melvincarvalho

This comment was marked as off-topic.

@pinheadmz
Copy link
Member

@melvincarvalho please review the moderation policy: https://github.com/bitcoin-core/meta/blob/main/MODERATION-GUIDELINES.md

Github pull request review comments are restricted exclusively for PULL REQUEST REVIEW COMMENTS

@average-gary
Copy link

@jamesob I'd be happy to help you keep this thread focused by moderating off-topic comments and pointing them to the appropriate forums.

You've suggested and linked to Delving which seems appropriate for general/conceptual discussion, however there is no thread/post over there to actually point folks to. Would you mind starting a thread over there so that we have somewhere concrete to point these types of discussions to?

https://delvingbitcoin.org/t/bip-119-op-checktemplateverify-no-activation/1494

@ariard
Copy link

ariard commented Mar 5, 2025

This change can be composed with other opcode specifications (e.g. CSFS,

@jamesob see my pending email in answer to AJ for the issues with CSFS building on @naumenkogs’s TxWithhold:

Especially if it’s possible to do a TxWithhold on the spend of any coinbase output beyond COINBASE_MATURITY. At least having an impossibility result that you cannot do a TxWithhold by grinding the miner’s scriptpubkey would be welcome from a safe engineering perspective. I’m not able to come with a practical offensive TxWithhold with OP_CTV alone, though as soon as you combine it with another primitive this is plausible.

@pinheadmz
Copy link
Member

@ariard I think your comment is more appropriate on the mailing list or delving. You are even mentioning a specific post from the mailing list. I expect a lot of off-topic comments on this PR and would appreciate your help staying focused. PR comments MUST be entirely focused on THIS PR code.

@ariard

This comment was marked as off-topic.

@darosior
Copy link
Member

darosior commented Mar 6, 2025

The code in this pull request is of good quality and is well tested, but it's not clear to me what's the goal with this pull request nor how it fits in the big picture. As this introduces a new consensus feature, it seems premature to merge this into Bitcoin Core until widespread consensus is reached among Bitcoin users to eventually activate this new feature in a soft fork.

To be clear, i am not saying the details of the activation need to be figured out before the implementation of the feature goes in, but there needs to at least be rough consensus among Bitcoin users to activate this at all.

@michaelfolkson
Copy link

I encourage more general, conceptual discussion to happen on Delving Bitcoin and not on this pull request.

@jamesob I'd be happy to help you keep this thread focused by moderating off-topic comments and pointing them to the appropriate forums.

To state the obvious if you push "conceptual discussion" (a critical part of the Bitcoin Core review process for a PR) to external forums (why not an accompanying issue in this repo?) the consideration of whether to merge this pull request would require monitoring these external forums. Merging this pull request would be a step towards a second declared activation attempt for CTV and a potential chain split if there isn't community consensus. Pushing that conceptual discussion outside of this repo doesn't change that fact.

@moonsettler

This comment was marked as off-topic.

@michaelfolkson

This comment was marked as off-topic.

@1440000bytes

This comment was marked as abuse.

@jaybny
Copy link

jaybny commented Mar 8, 2025

Before proceeding with a full technical review, I’d like to clarify whether this pull request represents a complete rewrite or simply a refactor of the original implementation from three years ago.


Off-topic

Concept ACK

CTV is an objectively well-reviewed, fundamental upgrade to Bitcoin, and it has gained broad consensus among subject matter experts over the past three years. There will only ever be a handful of legitimate, code-complete upgrades to Bitcoin that are truly ready for merge—and this is one of them, an ingenious, well-thought-out enhancement to Bitcoin with no downside.

I disagree with the notion that consensus-breaking code should receive special treatment compared to other changes. Every upgrade to Bitcoin carries some risk of unknowns (after all, the bug that caused the chain split in 2010 wasn’t consensus code). Moreover, not every low-level piece of C++ code needs to be judged solely on market demand. In Bitcoin, the only reason some people focus their complaints on consensus-breaking code is because such changes require a broad social activation method—to ensure miners are informed, upgrade their nodes, and keep the network in sync to avoid a chain split. This process isn’t a social vote; it’s simply a way of signaling to the hardware operators that Bitcoin software must be upgraded and indicating when it is safe to activate.

Frankly, the only reason this ends up on the non-technical timeline is because social consensus is needed to get the word out to miners. Otherwise, like the hundreds of other low-level Bitcoin Core C++ code merges, this wouldn’t attract such uninformed commentary.

While there’s naturally a significant overlap between consensus code and Bitcoin’s core fundamentals, BIP119 provides additional scaling techniques and supports second-layer mechanisms without fundamentally altering Bitcoin itself.

Ultimately, mergeable C++ code that has undergone thorough review and reached technical consensus should be merged in a timely manner to avoid staleness—even if activation debates continue elsewhere.

Given the limited number of humans capable of writing and reviewing low-level C++ Bitcoin upgrades, I hope this is the last time we code and review the same feature in the same codebase.

Unless there are substantive technical issues, I recommend we focus on the code review here and move broader conceptual discussions to the appropriate forums.

@rot13maxi
Copy link

simple implementation, helpful comments, good test coverage, no backwards compatibility issues, passes all CI.

LGTM!

@jamesob
Copy link
Contributor Author

jamesob commented Jun 12, 2025

@ariard thanks - probably the place for that is the meta issue or Delving Bitcoin. I don't see anything about your attack that's specific to CTV; e.g. your test script doesn't use the template hash or OP_NOP4 (OP_CTV). Rather it seems like a limitation of legacy script in general. But let's move this discussion off this PR please.

@ariard
Copy link

ariard commented Jun 13, 2025

I don't see anything about your attack that's specific to CTV; e.g. your test script doesn't use the template hash or OP_NOP4 (OP_CTV). Rather it seems like a limitation of legacy script in general.

@jamesob It’s correct it’s not specific for CTV, though it’s easy for CTV to fix it. The test case doesn’t use the template hash, but the “effect” should be the same when OP_NOP4. Yeah, let’s discuss the fix on your core GH repository better.

@ariard
Copy link

ariard commented Jun 29, 2025

Opened a pull request on Jamesob repository with the suggested changes: due to current block sigs exhaustions exposure:
jamesob#3

Changes motivated by current exposure to block signature overflow attacks and it’s quite simple to fix.

@darosior
Copy link
Member

darosior commented Jul 7, 2025

I believe the ability to commit to the transaction to spend an output, combined with BIP340 signature verification of arbitrary messages, is a reasonable bundle of capabilities to consider for a Bitcoin soft fork. However there is clearly no consensus about this among the Bitcoin development community (see for instance here and here for recent examples). On top of disagreement regarding the capability itself, objections were raised about CTV's approach to implement it.

Bitcoin Core should implement but not dictate Bitcoin's consensus rules. As such, a Bitcoin soft fork should only be implemented in Bitcoin Core after there is (rough) consensus among the Bitcoin developer community, and preferably after there is also demonstrated support from Bitcoin users. Outstanding disagreements to CTV on both conceptual and specifications ground make it absolutely premature to consider it for inclusion into Bitcoin Core.

The repeated attempts by the author of this PR to try to pressure his way to getting this change merged also leads me to believe he's trying to take advantage of Bitcoin Core's position as the dominant Bitcoin full node implementation to circumvent the broader consensus process. I think such an attempt would ultimately fail, but should be opposed rather than facilitated by the Bitcoin Core project on the sole ground that it would set a terrible precedent for how we approach changes to Bitcoin's consensus rules.

For all these reasons, Concept NACK on merging this pull request.

To be clear, i am not arguing this PR needs necessarily be closed. I understand a pull request to Bitcoin Core has uses beyond requesting being pulled into master, for instance to keep an up-to-date implementation of the proposal with already configured CI to point people to. But in my opinion marking it as draft would better indicate its status.

add_witness_commitment(block)
block.hashMerkleRoot = block.calc_merkle_root()
block.solve()
return block.serialize(True).hex(), block.hash
Copy link
Contributor

Choose a reason for hiding this comment

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

                               AttributeError: 'CBlock' object has no attribute 'hash'

@BitcoinErrorLog
Copy link

a Bitcoin soft fork should only be implemented in Bitcoin Core after there is (rough) consensus among the Bitcoin developer community

This is not sufficient for inclusion into the most popular implementation.

Developers are not a governance system for Bitcoin. Higher standards must be defined, required, and culturally acceptable.

SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_PUBKEYTYPE = (1U << 20),

// CHECKTEMPLATEVERIFY validation (BIP-119)
SCRIPT_VERIFY_CHECKTEMPLATEVERIFY = (1U << 21),
Copy link
Contributor

Choose a reason for hiding this comment

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

fyi this is the same bit used for csfs PR #32247

@ariard
Copy link

ariard commented Aug 24, 2025

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Concept ACK.

I'm not going to enter into the polemic about what should be or not the broader consensus process.
During the year of 2022 and 2023, in reaction to the failed CTV activation attempt, I did launch
and maintain for roughly a year the bitcoin contracting WG on IRC open to everyone, as a transparent
forum to discuss consensus changes, in the goal to make real and step-by-step progress among all the
domain experts.

While, I did discontinue this effort to spend more time investigating security bugs (there is only
144 blocks in a day...but an infinite universe of way to break things...sighs), there has been
almost none other initiatives to move the needle forward, apart of still bitcoin-inquisition and
one or two playbooks to describe what "ideally" should be the process, but who have not been applied
by their authors as far as I'm aware off.

I have no opinion if bitcoin core is or not the dominant full node implementaiton in the bitcoin
ecosystem. It might the case at the current block (i.e 911544), it might not be the case anymore
at the next block, 10 min in average. As far as I know there is no trustless cryptograpghic protocol
to prove with near-zero latency the identity of the software you're running to an open set of verifiers
all over the world.

Given the champion of this proposed consensus change, CHECKTEMPLATEVERIFY, have opened the code here
for review against a version of the bitcoin consensus engine code, and that consensus change is ultimately
a process where a group of human beings decide which technical rules will be authoritatively run by
a network of computers nodes, we're stuck on this online forum of discussion, in the lack of a better one.

With all those elements in mind, I'm not the Pythia of Delphi, so in the lack of a more formalized
consensus process, I'll only speak further for myself as I don't know how to interprets the entrails
of the bitcoin community like Greek oracles used to do in the ancient Greece.

On the design of CHECKTEMPLATEVERIFY, of which, describing in my own words allows to build "hash-chain"
of transactions, where a spending transaction must equal a pre-committed hash digest in a coin, I do
think it's a very minimal extension of the bitcoin script capabilities. There are margin of discussions
to discuss what transaction fields should be committed in the template and the hash algorithm performance,
though overall it's making clear technical choices.

Historically, my concern on CTV have been of 2 kind:

    • it didnt do enough to do the what I'm interested in in terms of off-chain protocols design
    • the use-cases presented by CTV have always been a bit of free technical claims with no real review

On the lack of flexible enough capabilities offered for off-chain protocol designers, I'm not
going to make remake here the whole discussion between Jeremy and myself on the trade-off between
"radix-pool" and "coinpool" and the implications on how you design a consensus primitive in consequence.
Suffice to say, for a group of counterparties who which to leave and exit in any order, and with
the maximum of fault-tolerance and on-chain cost, the design goal is not meet.

On the use-cases presented by CTV that have always been a bit of free technical claims (e.g congestion
tree, vaults, LN ball, DLC ctv), in the lack for every use-cases allegued to be enabled by CTV of
transactions + scripts, I do think it has always been hard to evaluate (1) if their works as expected
and (2) how they score on many dimensions (attacks & risks, economic engineering, privacy, implementation
complexity, protocol unknowns, evolvability, ecosystem impacts, etc).

Now, since 2022, we have more "toy" implementations of CTV uses-cases with vaults and the Ark thing
experimenting with CTV, and while I'm not personally excited or interested by CTV use-cases I can
understand from the perspective of a off-chain protocol designer how creating immutable vertices
in your graph of transactions can be very valuable. Immutable in the sense of it's used in BIP112,
that you cannot forge it, in the absence of chain reorgs.

Of course, there are trade-off with CTV-based vault approach versus signature-based vault approaches
design. The hash approach with CTV is more footgunish (you have a fee estimation miscomputation for
the nAmount, and boom! your funds might be forever frozen). The key approach is more flexible, and
while you can do "key delete" in software only, it does not offer the same security guarantees from
the perspective of anyone who has spent enough time with a motherboard and a soldering iron.

In my humble opinion, it's okay to offer different bitcoin scripts ways to design and develop
a use-cases, after all off-chain protocol designers and developers have to sweat a bit too --
as long as the primitive is safe in itself from the network of full nodes and the stability of
bitcoin mining.

About the unknown knowns of CHECKTEMPLATEVERIFY, I can think of 3 of them, 1) is all the denial-of-service
risks of the hashing algorithm for the template risk, 2) is security risk like block signature overflow
attacks due to misinteraction with other mechanism of the consensus engine and 3) all TxWithold attacks
or EHHMEEEE_VEEEEE (phonetic) in layman's terms. About TxWithold attacks, and the accidental enabling
of more powerful off-chain protocol that could leveraged to break base-layer mechanisms (e.g miner bribing
"tx-withold" smart contract to censor lightning txn, it's a serious concern, but so far I have not
found with CTV only how you can do that. Door is opened if someone can outsmart on that.

I'm deliberately not going to prononunce myself on the comparative design of CHECKTEMPLATEVERIFY,
like TEMPLATEHASH (?) and other primitives. We should remind that CTV was deliberately design to
the most restrictive design, after few rounds of interactions (i.e OP_CHECKOUTPUTHASHVERIFY,
OP_SECURETHEBAG, etc).

More flexible designs come with more surface of unforeseen interactions, and sadly I only realize
last year that Block Signature Overflow Attack were a thing that can affect time-sensitive off-chain
protocols. So being conservative in the design is a very good thing to be mindful of.

I would support a change of CTV to be Taproot only, but I also understand the concern of the champions
with the realities of the bitcoin ecosystem, where most of the coins spents are Segwit V0.

That's all -- I think I forgot nothing, but if so I'll correct myself.

I do make mine all the concerns of the usual Bitcoin core hackers, that's it's better to very
very very very conservative with consensus code changes and more unit, functional, manual testing
and fuzzing is welcome for this code branch.


Disclaimer: I'm not paid and I'm not interested to receive any compensation for the time spent on
reviewing consensus changes, be it startup equity, open source grant, ETF paper bitcoin, bitcoin
treasury equity, NFT, shitcoin or anything else. This is including any kind of promise being made
to me of a compensation in any kind of "forward-looking" statement.

All my professional commitments are under bulletproofs legal provisions to let me be free of whatever
I wish to say about bitcoin consensus changes and stay free of potential conflict of interests, with
only my own consciousness and sense of ethics to speak on such a technical subject.

In Q4 2021, around the Thursday 2 December to be more exact, we were approached with Gleb Naumenko
by Jeremy Rubin for a security review of CTV for a sum around $20k to $30k and we immediately, politely
and gently decline his proposal for ethical reasons.

I'm an investor in bitcoin, the self-custodied asset.
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEpaaGjXqpHdAKwaZ/gX/6Ao72HJQFAmirlRgACgkQgX/6Ao72
HJTxOg/7BRSd4sRrDijpardDWjRDT8tfVNoTLmcgnS73IiPwg2W8qzeov1ylsKjA
BUZggzvxb5bxZosMHyXksYtL2/YN2xHEuhLI+A41B4zQ2ouRv2fLh8ZZP9sA08Vv
KniGAKb8+hT6LhG2xR2J+R+Y/Ee/QteGmcnDDK69ukEHnJZOpRKusV7y0AwM4K8W
PAY9PJ/c4Vpr3Pqp20xmSO37WSZUAuiRYRkmvv1vIYedfWKcP3/is42X41jfu3Vg
NFqVySpewc7rdfsbvQwfspVKR8h1jnOBcFP3FeRNtjxEq7scfB+Njw0WXBcS0kpL
CZ4xyitxykigCjuLeRy2Aa+YExykHT7JCD8yqjYB5hO9umjXkpBKJcyX8SgCfuJ6
pmtg451aALW167AtaBPN/a3BQ/ZSm2jfc4VtxPdvcI525d+KcCWgcAzBJeBz57In
9HsYeYyeDOCgODVUstMQF/Eduxa8uOHotOPHbyWHRGUCNTRPr0MclU69kEyYrq6j
lVL2h1n65wPShp3m18IQrh0I64RsYzY5bC4cHoSR5O8vqFjGagOqsTdWGUGaq8o0
wi/9UESSi+G8dsAC5yE2QpeX4y3mSWA98FOSTghIRdcN/SwS7zyYZYOmzJcFHVx8
773QMDN9ladDUM/t2dc1N3fMQSVxrPbEGp1/tRFosZSTPIXf8Eg=
=W15h
-----END PGP SIGNATURE-----

@maflcko maflcko removed the CI failed label Sep 26, 2025
achow101 added a commit that referenced this pull request Oct 7, 2025
652424a test: additional test coverage for script_verify_flags (Anthony Towns)
417437e script/verify_flags: extend script_verify_flags to 64 bits (Anthony Towns)
3cbbcb6 script/interpreter: make script_verify_flag_name an ordinary enum (Anthony Towns)
bddcade script/verify_flags: make script_verify_flags type safe (Anthony Towns)
a5ead12 script/interpreter: introduce script_verify_flags typename (Anthony Towns)
4577fb2 rpc: have getdeploymentinfo report script verify flags (Anthony Towns)
a398693 validation: export GetBlockScriptFlags() (Anthony Towns)
5db8cd2 Move mapFlagNames and FormatScriptFlags logic to script/interpreter.h (Anthony Towns)

Pull request description:

  We currently use 21 of 32 possible bits for `SCRIPT_VERIFY_*` flags, with open PRs that may use 8 more (#29247, #31989, #32247, #32453). The mutinynet fork that has included many experimental soft fork features is [already reusing bits here](https://github.com/benthecarman/bitcoin/blob/d4a86277ed8a0712e03fbbce290e9209165e049c/src/script/interpreter.h#L175-L195). Therefore, bump this to 64 bits.

  In order to make it easier to update this logic in future, this PR also introduces a dedicated type for the script flags, and disables implicit conversion between that type and the underlying integer type. To make verifying that this change doesn't cause flags to disappear, this PR also resurrects the changes from #28806 so that the script flags that are consensus enforced on each block can be queried via getdeploymentinfo.

ACKs for top commit:
  instagibbs:
    reACK 652424a
  achow101:
    ACK 652424a
  darosior:
    ACK 652424a
  theStack:
    Code-review ACK 652424a 🎏

Tree-SHA512: 7b30152196cdfdef8b9700b571b7d7d4e94d28fbc5c26ea7532788037efc02e4b1d8de392b0b20507badfdc26f5c125f8356a479604a9149b8aae23a7cf5549f
@DrahtBot
Copy link
Contributor

DrahtBot commented Oct 8, 2025

🐙 This pull request conflicts with the target branch and needs rebase.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.