upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/script.h
diff options
context:
space:
mode:
authorBitflash <btf01@proton.me>2026-07-28 15:27:57 -0300
committerGitHub <noreply@github.com>2026-07-28 15:27:57 -0300
commit389e9966758125f4e20d059a02396e1577b6367c (patch)
tree6a32feac1c5549eeab1e4b3557f50929e7244d6c /src/script.h
parent63764708903cf93476b0fa43580e23ff75ffceba (diff)
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.
Diffstat (limited to 'src/script.h')
-rw-r--r--src/script.h23
1 files changed, 23 insertions, 0 deletions
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:
536 } 536 }
537 537
538 538
539 // Signature operations in this script. Each one costs every validating
540 // node an elliptic-curve verification, so blocks are capped on this count
541 // and not only on their size -- a byte of OP_CHECKSIG is far more
542 // expensive to check than a byte of anything else.
543 unsigned int GetSigOpCount() const
544 {
545 unsigned int n = 0;
546 const_iterator pc = begin();
547 opcodetype opcode;
548 vector<unsigned char> vchPushValue;
549 while (pc < end())
550 {
551 if (!GetOp(pc, opcode, vchPushValue))
552 break;
553 if (opcode == OP_CHECKSIG || opcode == OP_CHECKSIGVERIFY)
554 n++;
555 else if (opcode == OP_CHECKMULTISIG || opcode == OP_CHECKMULTISIGVERIFY)
556 n += 20;
557 }
558 return n;
559 }
560
561
539 void FindAndDelete(const CScript& b) 562 void FindAndDelete(const CScript& b)
540 { 563 {
541 iterator pc = begin(); 564 iterator pc = begin();