mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-20 22:04:31 +02:00
multi: fix inclusion proof size
The inclusion proof field in the TapscriptPartialReveal function was incorrect. An inclusion proof can be zero or more elements of 32-byte slices. So an empty inclusion proof can be valid too for a tree that only consists of a single leaf.
This commit is contained in:
parent
f7275c7fc4
commit
e31aab5af6
@ -75,12 +75,12 @@ func TapscriptFullTree(internalKey *btcec.PublicKey,
|
|||||||
// key and revealed script.
|
// key and revealed script.
|
||||||
func TapscriptPartialReveal(internalKey *btcec.PublicKey,
|
func TapscriptPartialReveal(internalKey *btcec.PublicKey,
|
||||||
revealedLeaf txscript.TapLeaf,
|
revealedLeaf txscript.TapLeaf,
|
||||||
inclusionProof [32]byte) *waddrmgr.Tapscript {
|
inclusionProof []byte) *waddrmgr.Tapscript {
|
||||||
|
|
||||||
controlBlock := &txscript.ControlBlock{
|
controlBlock := &txscript.ControlBlock{
|
||||||
InternalKey: internalKey,
|
InternalKey: internalKey,
|
||||||
LeafVersion: txscript.BaseLeafVersion,
|
LeafVersion: txscript.BaseLeafVersion,
|
||||||
InclusionProof: inclusionProof[:],
|
InclusionProof: inclusionProof,
|
||||||
}
|
}
|
||||||
rootHash := controlBlock.RootHash(revealedLeaf.Script)
|
rootHash := controlBlock.RootHash(revealedLeaf.Script)
|
||||||
tapKey := txscript.ComputeTaprootOutputKey(internalKey, rootHash)
|
tapKey := txscript.ComputeTaprootOutputKey(internalKey, rootHash)
|
||||||
|
@ -131,8 +131,9 @@ func testTaprootSignOutputRawScriptSpend(ctxt context.Context, t *harnessTest,
|
|||||||
// Let's add a second script output as well to test the partial reveal.
|
// Let's add a second script output as well to test the partial reveal.
|
||||||
leaf2 := testScriptSchnorrSig(t.t, leafSigningKey)
|
leaf2 := testScriptSchnorrSig(t.t, leafSigningKey)
|
||||||
|
|
||||||
|
inclusionProof := leaf1.TapHash()
|
||||||
tapscript := input.TapscriptPartialReveal(
|
tapscript := input.TapscriptPartialReveal(
|
||||||
dummyInternalKey, leaf2, leaf1.TapHash(),
|
dummyInternalKey, leaf2, inclusionProof[:],
|
||||||
)
|
)
|
||||||
taprootKey, err := tapscript.TaprootKey()
|
taprootKey, err := tapscript.TaprootKey()
|
||||||
require.NoError(t.t, err)
|
require.NoError(t.t, err)
|
||||||
|
@ -273,8 +273,9 @@ func TestScriptImport(t *testing.T) {
|
|||||||
// Now, as a last test, make sure that when we try adding an address
|
// Now, as a last test, make sure that when we try adding an address
|
||||||
// with partial script reveal, we get an error that the address already
|
// with partial script reveal, we get an error that the address already
|
||||||
// exists.
|
// exists.
|
||||||
|
inclusionProof := leaf2.TapHash()
|
||||||
tapscript2 := input.TapscriptPartialReveal(
|
tapscript2 := input.TapscriptPartialReveal(
|
||||||
testPubKey, leaf1, leaf2.TapHash(),
|
testPubKey, leaf1, inclusionProof[:],
|
||||||
)
|
)
|
||||||
_, err = w.ImportTaprootScript(scope, tapscript2)
|
_, err = w.ImportTaprootScript(scope, tapscript2)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user