Skip to content

BIP446 "OP_TEMPLATEHASH" implementation#100

Open
darosior wants to merge 5 commits intobitcoin-inquisition:29.xfrom
darosior:2512_inquisition_templatehash
Open

BIP446 "OP_TEMPLATEHASH" implementation#100
darosior wants to merge 5 commits intobitcoin-inquisition:29.xfrom
darosior:2512_inquisition_templatehash

Conversation

@darosior
Copy link

@darosior darosior commented Dec 9, 2025

This implements OP_TEMPLATEHASH, as defined in BIP446, for Inquisition. The corresponding Binana PR is available here.

Unit tests are included, that are used to derive test vectors for the proposal. We also included two fuzz targets and end-to-end checks through the functional tests framework.

The original implementation, which this PR ports to Inquisition, is available here.

@darosior darosior marked this pull request as draft December 9, 2025 16:46
@ajtowns ajtowns added this to the 29.x milestone Dec 9, 2025
@DrahtBot DrahtBot mentioned this pull request Dec 14, 2025
@DrahtBot
Copy link
Collaborator

DrahtBot commented Dec 14, 2025

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #109 (Implement BIP-EC-OPS: Elliptic Curve Operations for Bitcoin Script by ViniciusCestarii)
  • #104 (TAPSCRIPT_V2 (Great Script Restoration) by jmoik)
  • #102 (OP_CHECKCONTRACTVERIFY by bigspider)

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.

@darosior darosior force-pushed the 2512_inquisition_templatehash branch from 2101fe0 to afcf99f Compare February 18, 2026 16:54
@darosior darosior force-pushed the 2512_inquisition_templatehash branch from afcf99f to c6f9c9a Compare February 18, 2026 17:45
@darosior darosior changed the title OP_TEMPLATEHASH BIP446 "OP_TEMPLATEHASH" implementation Feb 18, 2026
@darosior
Copy link
Author

I have now rebased this PR on master, updated the OP_SUCCESS used to resolve the conflict with #102, and used the Binana number proposed here. This is now ready for review.

@darosior darosior marked this pull request as ready for review February 18, 2026 17:51
darosior and others added 5 commits February 18, 2026 14:09
This introduces a new Script operation exclusively available in Tapscript context: OP_TEMPLATEHASH.
This operation pushes the hash of the spending transaction on the stack. See BIP 446 for details.

This operation is introduced as replacing OP_SUCCESS206 (0xce).

Co-Authored-By: Greg Sanders <gsanders87@gmail.com>
Sanity check the template hash by using it to commit to the transaction that must spend an output.
Malleating committed fields must lead to a consensus failure, and changing non-committed fields is
fine.

We also add the option to generate test vectors from this unit test.
We introduce one specialized target focused on exercising the new `GetTemplateHash()` logic
introduced for OP_TEMPLATEHASH, and one broader fuzz target which exercises using OP_TEMPLATEHASH
on a variety of transactions while asserting invariants.
This leverages the extensive feature_taproot.py test framework to generate coverage for the numerous
scenarii and mutations exercised there.

Additionally, a separate feature_templatehash.py functional test is introduced for end-to-end
testing of the commit-to-next-transaction use case, which does not fit nicely into the
feature_taproot.py framework (assumes input independence).
@instagibbs
Copy link

will review this soon

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.

4 participants