8000 txscript: add more detail to invalid tapscript merkle proof error by Roasbeef · Pull Request #2284 · btcsuite/btcd · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

txscript: add more detail to invalid tapscript merkle proof error #2284

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion txscript/taproot.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,10 @@ func VerifyTaprootLeafCommitment(controlBlock *ControlBlock,
expectedWitnessProgram := schnorr.SerializePubKey(taprootKey)
if !bytes.Equal(expectedWitnessProgram, taprootWitnessProgram) {

return scriptError(ErrTaprootMerkleProofInvalid, "")
str := fmt.Sprintf("derived witness program: %x, expected: "+
"%x, using tapscript_root: %x", expectedWitnessProgram,
taprootWitnessProgram, rootHash)
return scriptError(ErrTaprootMerkleProofInvalid, str)
}

// Finally, we'll verify that the parity of the y coordinate of the
Expand Down
27 changes: 19 additions & 8 deletions txscript/taproot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,15 @@ func TestTapscriptCommitmentVerification(t *testing.T) {
// make from 0 to 1 leaf
// ensure verifies properly
testCases := []struct {
treeMutateFunc func(*IndexedTapScriptTree)

ctrlBlockMutateFunc func(*ControlBlock)

numLeaves int

valid bool

treeMutateFunc func(*IndexedTapScriptTree)

ctrlBlockMutateFunc func(*ControlBlock)
expectedErr ErrorCode
}{
// A valid merkle proof of a single leaf.
{
Expand All @@ -322,11 +324,13 @@ func TestTapscriptCommitmentVerification(t *testing.T) {
// An invalid merkle proof, we modify the last byte of one of
// the leaves.
{
numLeaves: 4,
valid: false,
numLeaves: 4,
valid: false,
expectedErr: ErrTaprootMerkleProofInvalid,
treeMutateFunc: func(t *IndexedTapScriptTree) {
for _, leafProof := range t.LeafMerkleProofs {
leafProof.InclusionProof[0] ^= 1
proofLen := len(leafProof.InclusionProof)
leafProof.InclusionProof[proofLen-1] ^= 1
}
},
},
Expand All @@ -335,8 +339,9 @@ func TestTapscriptCommitmentVerification(t *testing.T) {
// An invalid series of proofs, we modify the control
// block to not match the parity of the final output
// key commitment.
numLeaves: 2,
valid: false,
numLeaves: 2,
valid: false,
expectedErr: ErrTaprootOutputKeyParityMismatch,
ctrlBlockMutateFunc: func(c *ControlBlock) {
c.OutputKeyYIsOdd = !c.OutputKeyYIsOdd
},
Expand Down Expand Up @@ -391,6 +396,12 @@ func TestTapscriptCommitmentVerification(t *testing.T) {
"valid=%v, got valid=%v", testCase.valid,
valid)
}

if !valid {
if !IsErrorCode(err, testCase.expectedErr) {
t.Fatalf("expected error code %v, got %v", testCase.expectedErr, err)
}
}
}

// TODO(roasbeef): index correctness
Expand Down
Loading
0