From 468f8366cf926c73de154d567a791fefa93599c3 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Fri, 30 May 2014 21:12:46 -0500 Subject: [PATCH] Make multisig txns with non-null dummy nonstandard. This commit helps prevent transaction malleability by enforcing that the extra dummy value on multisig transaction script contains no data for a transaction . This syncs with a recent change in Bitcoin Core to remain compatible. As part of this change a new constant has been introduced which is used to specify the script flags which are used for standard transactions. This constant is then used in both the memory pool and the mining code to ensure they remain in sync with one another. Closes #131. ok @jrick, @dajohi --- mempool.go | 4 ++-- mining.go | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/mempool.go b/mempool.go index d41f9462..ade8f6dc 100644 --- a/mempool.go +++ b/mempool.go @@ -905,8 +905,8 @@ func (mp *txMemPool) maybeAcceptTransaction(tx *btcutil.Tx, isOrphan *bool, isNe // Verify crypto signatures for each input and reject the transaction if // any don't verify. - flags := btcscript.ScriptBip16 | btcscript.ScriptCanonicalSignatures - err = btcchain.ValidateTransactionScripts(tx, txStore, flags) + err = btcchain.ValidateTransactionScripts(tx, txStore, + standardScriptVerifyFlags) if err != nil { return err } diff --git a/mining.go b/mining.go index abeb9525..b6899ea9 100644 --- a/mining.go +++ b/mining.go @@ -37,6 +37,17 @@ const ( // and is used to monitor BIP16 support as well as blocks that are // generated via btcd. coinbaseFlags = "/P2SH/btcd/" + + // standardScriptVerifyFlags are the script flags which are used when + // executing transaction scripts to enforce additional checks which + // are required for the script to be considered standard. These checks + // help reduce issues related to transaction malleability as well as + // allow pay-to-script hash transactions. Note these flags are + // different than what is required for the consensus rules in that they + // are more strict. + standardScriptVerifyFlags = btcscript.ScriptBip16 | + btcscript.ScriptCanonicalSignatures | + btcscript.ScriptStrictMultiSig ) // txPrioItem houses a transaction along with extra information that allows the @@ -669,8 +680,8 @@ mempoolLoop: logSkippedDeps(tx, deps) continue } - flags := btcscript.ScriptBip16 | btcscript.ScriptCanonicalSignatures - err = btcchain.ValidateTransactionScripts(tx, blockTxStore, flags) + err = btcchain.ValidateTransactionScripts(tx, blockTxStore, + standardScriptVerifyFlags) if err != nil { minrLog.Tracef("Skipping tx %s due to error in "+ "ValidateTransactionScripts: %v", tx.Sha(), err)