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/script.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/script.h') diff --git a/src/script.h b/src/script.h index 27c1b13..26bb65a 100644 --- a/src/script.h +++ b/src/script.h @@ -536,6 +536,29 @@ public: } + // Signature operations in this script. Each one costs every validating + // node an elliptic-curve verification, so blocks are capped on this count + // and not only on their size -- a byte of OP_CHECKSIG is far more + // expensive to check than a byte of anything else. + unsigned int GetSigOpCount() const + { + unsigned int n = 0; + const_iterator pc = begin(); + opcodetype opcode; + vector vchPushValue; + while (pc < end()) + { + if (!GetOp(pc, opcode, vchPushValue)) + break; + if (opcode == OP_CHECKSIG || opcode == OP_CHECKSIGVERIFY) + n++; + else if (opcode == OP_CHECKMULTISIG || opcode == OP_CHECKMULTISIGVERIFY) + n += 20; + } + return n; + } + + void FindAndDelete(const CScript& b) { iterator pc = begin(); -- cgit v1.2.3