Skip to content

Commit 4fad8e6

Browse files
committed
Reject transactions with excessive numbers of sigops
1 parent 29ef389 commit 4fad8e6

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/main.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,9 +1016,18 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
10161016
if (Params().RequireStandard() && !AreInputsStandard(tx, view))
10171017
return error("AcceptToMemoryPool: : nonstandard transaction input");
10181018

1019-
// Note: if you modify this code to accept non-standard transactions, then
1020-
// you should add code here to check that the transaction does a
1021-
// reasonable number of ECDSA signature verifications.
1019+
// Check that the transaction doesn't have an excessive number of
1020+
// sigops, making it impossible to mine. Since the coinbase transaction
1021+
// itself can contain sigops MAX_TX_SIGOPS is less than
1022+
// MAX_BLOCK_SIGOPS; we still consider this an invalid rather than
1023+
// merely non-standard transaction.
1024+
unsigned int nSigOps = GetLegacySigOpCount(tx);
1025+
nSigOps += GetP2SHSigOpCount(tx, view);
1026+
if (nSigOps > MAX_TX_SIGOPS)
1027+
return state.DoS(0,
1028+
error("AcceptToMemoryPool : too many sigops %s, %d > %d",
1029+
hash.ToString(), nSigOps, MAX_TX_SIGOPS),
1030+
REJECT_NONSTANDARD, "bad-txns-too-many-sigops");
10221031

10231032
int64_t nValueOut = tx.GetValueOut();
10241033
int64_t nFees = nValueIn-nValueOut;

src/main.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ static const unsigned int MAX_STANDARD_TX_SIZE = 100000;
4545
static const unsigned int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;
4646
/** Maxiumum number of signature check operations in an IsStandard() P2SH script */
4747
static const unsigned int MAX_P2SH_SIGOPS = 15;
48+
/** The maximum number of sigops we're willing to relay/mine in a single tx */
49+
static const unsigned int MAX_TX_SIGOPS = MAX_BLOCK_SIGOPS/5;
4850
/** The maximum number of orphan transactions kept in memory */
4951
static const unsigned int MAX_ORPHAN_TRANSACTIONS = MAX_BLOCK_SIZE/100;
5052
/** Default for -maxorphanblocks, maximum number of orphan blocks kept in memory */

0 commit comments

Comments
 (0)