Skip to content

Commit

Permalink
txscript: use DoubleHashRaw for segwit sighash single calc
Browse files Browse the repository at this point in the history
We can write direly into the hash writer vs serializing into a buffer,
then writing that into the hash writer.
  • Loading branch information
Roasbeef committed Dec 19, 2023
1 parent adfb641 commit 046a701
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions txscript/sighash.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,11 @@ func calcWitnessSignatureHashRaw(subScript []byte, sigHashes *TxSigHashes,
} else if hashType&sigHashMask == SigHashSingle &&
idx < len(tx.TxOut) {

var b bytes.Buffer
wire.WriteTxOut(&b, 0, 0, tx.TxOut[idx])
w.Write(chainhash.DoubleHashB(b.Bytes()))
h := chainhash.DoubleHashRaw(func(tw io.Writer) error {
wire.WriteTxOut(tw, 0, 0, tx.TxOut[idx])
return nil
})
w.Write(h[:])
} else {
w.Write(zeroHash[:])
}
Expand Down

0 comments on commit 046a701

Please sign in to comment.