From 90a9019387450e4e22285daff3b4f2ccdb42c598 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 27 Jul 2016 00:52:27 -0700 Subject: [PATCH] Fix issue where a coinbase tx should have it's sigscript hashed to avoid duplicate txids, as discussed in BIP34 and BIP30. --- src/primitives/transaction.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index 114aaf372..5d157a5c3 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -234,13 +234,16 @@ void CTransaction::UpdateTxid() const // Create a deep copy of this transaction CMutableTransaction tx(*this); - // Clear sigscript from all transaction inputs. - for (CTxIn & txIn : tx.vin) { - txIn.scriptSig.clear(); - } + // We keep the sigscript for coinbase txs to avoid duplicate txids (BIP34 and BIP30) + if (!IsCoinBase()) { + // Clear sigscript from all transaction inputs. + for (CTxIn & txIn : tx.vin) { + txIn.scriptSig.clear(); + } - // Clear joinSplitSig by filling the buffer with zero - tx.joinSplitSig.assign(0); + // Clear joinSplitSig by filling the buffer with zero + tx.joinSplitSig.assign(0); + } // Return double SHA256 hash *const_cast(&txid) = tx.GetSerializeHash();