From 18cf06ddd1968b949a3319bb13fc69c1d5b758d4 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Tue, 10 May 2022 18:13:00 +0200 Subject: [PATCH] chanfunding: fix sighash type for p2tr inputs This commit fixes the default sighash type for p2tr channel funding transaction inputs. --- lnwallet/chanfunding/wallet_assembler.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lnwallet/chanfunding/wallet_assembler.go b/lnwallet/chanfunding/wallet_assembler.go index cc14dcac0..376360901 100644 --- a/lnwallet/chanfunding/wallet_assembler.go +++ b/lnwallet/chanfunding/wallet_assembler.go @@ -111,7 +111,6 @@ func (f *FullIntent) CompileFundingTx(extraInputs []*wire.TxIn, f.coinSource, extraInputs, ) signDesc := input.SignDescriptor{ - HashType: txscript.SigHashAll, SigHashes: txscript.NewTxSigHashes( fundingTx, prevOutFetcher, ), @@ -136,6 +135,13 @@ func (f *FullIntent) CompileFundingTx(extraInputs []*wire.TxIn, } signDesc.InputIndex = i + // We support spending a p2tr input ourselves. But not as part + // of their inputs. + signDesc.HashType = txscript.SigHashAll + if txscript.IsPayToTaproot(info.PkScript) { + signDesc.HashType = txscript.SigHashDefault + } + // Finally, we'll sign the input as is, and populate the input // with the witness and sigScript (if needed). inputScript, err := f.signer.ComputeInputScript( @@ -398,7 +404,9 @@ var _ txscript.PrevOutputFetcher = (*SegWitV0DualFundingPrevOutputFetcher)(nil) // // NOTE: Since the actual pkScript and amounts aren't passed in, this will just // make sure that nothing will panic when creating a SegWit v0 sighash. But this -// code will NOT WORK for transactions that spend any Taproot inputs! +// code will NOT WORK for transactions that spend any _remote_ Taproot inputs! +// So basically dual-funding won't work with Taproot inputs unless the UTXO info +// is exchanged between the peers. func NewSegWitV0DualFundingPrevOutputFetcher(localSource CoinSource, remoteInputs []*wire.TxIn) txscript.PrevOutputFetcher {