From 41fbb87c86f47e705610c03537f4e0615fae2176 Mon Sep 17 00:00:00 2001 From: David Hill Date: Thu, 14 Aug 2014 10:44:26 -0400 Subject: [PATCH] Reject transactions with too many signature operations. This matches recent changes in bitcoin core. --- mempool.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/mempool.go b/mempool.go index 380b1a544..335f217f0 100644 --- a/mempool.go +++ b/mempool.go @@ -36,6 +36,11 @@ const ( // of big orphans. maxOrphanTxSize = 5000 + // maxSigOpsPerTx is the maximum number of signature operations + // in a single transaction we will relay or mine. It is a fraction + // of the max signature operations for a block. + maxSigOpsPerTx = btcchain.MaxSigOpsPerBlock / 5 + // maxStandardTxSize is the maximum size allowed for transactions that // are considered standard and will therefore be relayed and considered // for mining. @@ -876,6 +881,25 @@ func (mp *txMemPool) maybeAcceptTransaction(tx *btcutil.Tx, isOrphan *bool, isNe // you should add code here to check that the transaction does a // reasonable number of ECDSA signature verifications. + // Don't allow transactions with an excessive number of signature + // operations which would result in making it impossible to mine. Since + // the coinbase address itself can contain signature operations, the + // maximum allowed signature operations per transaction is less than + // the maximum allowed signature operations per block. + numSigOps, err := btcchain.CountP2SHSigOps(tx, false, txStore) + if err != nil { + if cerr, ok := err.(btcchain.RuleError); ok { + return chainRuleError(cerr) + } + return err + } + numSigOps += btcchain.CountSigOps(tx) + if numSigOps > maxSigOpsPerTx { + str := fmt.Sprintf("transaction %v has too many sigops: %d > %d", + txHash, numSigOps, maxSigOpsPerTx) + return txRuleError(btcwire.RejectNonstandard, str) + } + // Don't allow transactions with fees too low to get into a mined block. // // Most miners allow a free transaction area in blocks they mine to go