Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OP_TXHASH and OP_CHECKTXHASHVERIFY opcodes #2078

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

sputn1ck
Copy link
Collaborator

@sputn1ck sputn1ck commented Dec 24, 2023

Implementation of OP_TXHASH and OP_CHECKTXHASHVERIFY, as per bitcoin/bips#1500.

I mainly did this to learn about the BIP, maybe others might find this interesting and useful.

The code passes all testvectors specified in the BIP, I also added an example of restricting a transaction to be only spent to specified outputs.

I also added a rudimentary cache with a benchmark.

This commit adds the TxFieldSelector type which is used to generate
TxHash values for the OP_TXHASH and OP_CHECKTXHASHVERIFY opcodes.
@sputn1ck sputn1ck force-pushed the op_txhash branch 2 times, most recently from 55242a4 to 1b6ba7e Compare December 24, 2023 12:41
This commit adds two new opcodes, OP_TXHASH and OP_CHECKTXHASHVERIFY.
These opcodes replace the OP_NOP4 and OP_UNKNOWN189 opcodes that were
previously reserved for future use.
This commit adds a simple example of how to use the new
OP_CHECKTXHASHVERIFY opcode added in the previous commit.
The example shows how to create a transaction that is restricted
to spend to two specific outputs.
This commit removes the NOP4 stuff from the script_tests.json file in
order for the test to succeed. This commit will be changed to reflect
expected OP_TXHASH changes.
@coveralls
Copy link

Pull Request Test Coverage Report for Build 7314655737

  • 450 of 561 (80.21%) changed or added relevant lines in 3 files are covered.
  • 3 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.3%) to 56.785%

Changes Missing Coverage Covered Lines Changed/Added Lines %
txscript/opcode.go 26 68 38.24%
txscript/txhash.go 419 488 85.86%
Files with Coverage Reduction New Missed Lines %
txscript/taproot.go 3 95.76%
Totals Coverage Status
Change from base Build 7299011825: 0.3%
Covered Lines: 29051
Relevant Lines: 51160

💛 - Coveralls

Copy link
Collaborator

@halseth halseth left a comment

Choose a reason for hiding this comment

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

thanks for the implementation :)

// should be hashed into the TxHash.
TXFSControl uint8 = 1 << 7

// TXFSAll is the bit that indicates that all fields should be hashed
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/bit/byte

@ben2077 ben2077 mentioned this pull request Mar 23, 2024
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.

None yet

3 participants