From 389e9966758125f4e20d059a02396e1577b6367c Mon Sep 17 00:00:00 2001 From: Bitflash Date: Tue, 28 Jul 2026 15:27:57 -0300 Subject: main: cap signature operations per block (#20) MAX_SIZE bounds a block's bytes, not what it costs to check. Every OP_CHECKSIG is an elliptic-curve verification, and blocks may be 32 MB here, so one packed with signature operations takes every node minutes of CPU to reject -- while at this chain's difficulty it stays cheap to mine. There was no counter at all. CheckBlock now sums signature operations across the block and rejects past 20000, the figure Bitcoin settled on. OP_CHECKMULTISIG counts as 20 since it may verify that many. Consensus change. Real blocks here carry one or two operations each -- coinbase pay-to-pubkey and standard pay-to-pubkey-hash spends -- so the ceiling is four orders of magnitude above anything in the chain, but it still needs verifying against the full history before merge. --- src/main.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 17e446e..a75bf54 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1261,6 +1261,16 @@ bool CBlock::CheckBlock() const if (!tx.CheckTransaction()) return error("CheckBlock() : CheckTransaction failed"); + // Cap the work a block can demand. MAX_SIZE bounds the bytes, not the cost: + // every signature operation is an elliptic-curve verification, and at this + // chain's difficulty a block packed with them is affordable to mine and + // expensive for everyone else to reject. + unsigned int nSigOps = 0; + foreach(const CTransaction& tx, vtx) + nSigOps += tx.GetSigOpCount(); + if (nSigOps > MAX_BLOCK_SIGOPS) + return error("CheckBlock() : out-of-bounds signature operation count"); + // Reject blocks carrying the same transaction twice (CVE-2012-2459). // // BuildMerkleTree duplicates the last hash when a level has an odd width, -- cgit v1.2.3