mirror of
https://github.com/btcsuite/btcd.git
synced 2025-03-13 11:35:52 +01:00
Merge a155d466fc
into 6afce8d608
This commit is contained in:
commit
657d1271bd
2 changed files with 23 additions and 9 deletions
|
@ -353,7 +353,10 @@ func VerifyTaprootLeafCommitment(controlBlock *ControlBlock,
|
||||||
expectedWitnessProgram := schnorr.SerializePubKey(taprootKey)
|
expectedWitnessProgram := schnorr.SerializePubKey(taprootKey)
|
||||||
if !bytes.Equal(expectedWitnessProgram, taprootWitnessProgram) {
|
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
|
// Finally, we'll verify that the parity of the y coordinate of the
|
||||||
|
|
|
@ -293,13 +293,15 @@ func TestTapscriptCommitmentVerification(t *testing.T) {
|
||||||
// make from 0 to 1 leaf
|
// make from 0 to 1 leaf
|
||||||
// ensure verifies properly
|
// ensure verifies properly
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
|
treeMutateFunc func(*IndexedTapScriptTree)
|
||||||
|
|
||||||
|
ctrlBlockMutateFunc func(*ControlBlock)
|
||||||
|
|
||||||
numLeaves int
|
numLeaves int
|
||||||
|
|
||||||
valid bool
|
valid bool
|
||||||
|
|
||||||
treeMutateFunc func(*IndexedTapScriptTree)
|
expectedErr ErrorCode
|
||||||
|
|
||||||
ctrlBlockMutateFunc func(*ControlBlock)
|
|
||||||
}{
|
}{
|
||||||
// A valid merkle proof of a single leaf.
|
// A valid merkle proof of a single leaf.
|
||||||
{
|
{
|
||||||
|
@ -322,11 +324,13 @@ func TestTapscriptCommitmentVerification(t *testing.T) {
|
||||||
// An invalid merkle proof, we modify the last byte of one of
|
// An invalid merkle proof, we modify the last byte of one of
|
||||||
// the leaves.
|
// the leaves.
|
||||||
{
|
{
|
||||||
numLeaves: 4,
|
numLeaves: 4,
|
||||||
valid: false,
|
valid: false,
|
||||||
|
expectedErr: ErrTaprootMerkleProofInvalid,
|
||||||
treeMutateFunc: func(t *IndexedTapScriptTree) {
|
treeMutateFunc: func(t *IndexedTapScriptTree) {
|
||||||
for _, leafProof := range t.LeafMerkleProofs {
|
for _, leafProof := range t.LeafMerkleProofs {
|
||||||
leafProof.InclusionProof[0] ^= 1
|
proofLen := len(leafProof.InclusionProof)
|
||||||
|
leafProof.InclusionProof[proofLen-1] ^= 1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -335,8 +339,9 @@ func TestTapscriptCommitmentVerification(t *testing.T) {
|
||||||
// An invalid series of proofs, we modify the control
|
// An invalid series of proofs, we modify the control
|
||||||
// block to not match the parity of the final output
|
// block to not match the parity of the final output
|
||||||
// key commitment.
|
// key commitment.
|
||||||
numLeaves: 2,
|
numLeaves: 2,
|
||||||
valid: false,
|
valid: false,
|
||||||
|
expectedErr: ErrTaprootOutputKeyParityMismatch,
|
||||||
ctrlBlockMutateFunc: func(c *ControlBlock) {
|
ctrlBlockMutateFunc: func(c *ControlBlock) {
|
||||||
c.OutputKeyYIsOdd = !c.OutputKeyYIsOdd
|
c.OutputKeyYIsOdd = !c.OutputKeyYIsOdd
|
||||||
},
|
},
|
||||||
|
@ -391,6 +396,12 @@ func TestTapscriptCommitmentVerification(t *testing.T) {
|
||||||
"valid=%v, got valid=%v", testCase.valid,
|
"valid=%v, got valid=%v", testCase.valid,
|
||||||
valid)
|
valid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !valid {
|
||||||
|
if !IsErrorCode(err, testCase.expectedErr) {
|
||||||
|
t.Fatalf("expected error code %v, got %v", testCase.expectedErr, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(roasbeef): index correctness
|
// TODO(roasbeef): index correctness
|
||||||
|
|
Loading…
Add table
Reference in a new issue