diff options
| author | Bitflash <btf01@proton.me> | 2026-07-28 15:27:57 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-07-28 15:27:57 -0300 |
| commit | 389e9966758125f4e20d059a02396e1577b6367c (patch) | |
| tree | 6a32feac1c5549eeab1e4b3557f50929e7244d6c /src/main.h | |
| parent | 63764708903cf93476b0fa43580e23ff75ffceba (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/main.h')
| -rw-r--r-- | src/main.h | 15 |
1 files changed, 15 insertions, 0 deletions
| @@ -18,6 +18,11 @@ static const unsigned int MAX_SIZE = 0x02000000; | |||
| 18 | // Ceiling on transactions held waiting for a parent that has not arrived. | 18 | // Ceiling on transactions held waiting for a parent that has not arrived. |
| 19 | // They cost a peer nothing to send and are never validated, only stored. | 19 | // They cost a peer nothing to send and are never validated, only stored. |
| 20 | static const unsigned int MAX_ORPHAN_TRANSACTIONS = 100; | 20 | static const unsigned int MAX_ORPHAN_TRANSACTIONS = 100; |
| 21 | // Signature operations allowed in one block. Size alone does not bound what a | ||
| 22 | // block costs to validate: every OP_CHECKSIG is an elliptic-curve verification, | ||
| 23 | // so a block within the size limit could still hold millions of them and take | ||
| 24 | // the network minutes of CPU to reject. Same value Bitcoin settled on. | ||
| 25 | static const unsigned int MAX_BLOCK_SIGOPS = 20000; | ||
| 21 | static const int64 COIN = 100000000; | 26 | static const int64 COIN = 100000000; |
| 22 | // Total Bitflash emission: identical to Bitcoin (21 million). | 27 | // Total Bitflash emission: identical to Bitcoin (21 million). |
| 23 | // MAX_MONEY guards against the value overflow bug (CVE-2010-5139), which in | 28 | // MAX_MONEY guards against the value overflow bug (CVE-2010-5139), which in |
| @@ -503,6 +508,16 @@ public: | |||
| 503 | return (vin.size() == 1 && vin[0].prevout.IsNull()); | 508 | return (vin.size() == 1 && vin[0].prevout.IsNull()); |
| 504 | } | 509 | } |
| 505 | 510 | ||
| 511 | unsigned int GetSigOpCount() const | ||
| 512 | { | ||
| 513 | unsigned int n = 0; | ||
| 514 | foreach(const CTxIn& txin, vin) | ||
| 515 | n += txin.scriptSig.GetSigOpCount(); | ||
| 516 | foreach(const CTxOut& txout, vout) | ||
| 517 | n += txout.scriptPubKey.GetSigOpCount(); | ||
| 518 | return n; | ||
| 519 | } | ||
| 520 | |||
| 506 | bool CheckTransaction() const | 521 | bool CheckTransaction() const |
| 507 | { | 522 | { |
| 508 | // Basic checks that don't depend on any context | 523 | // Basic checks that don't depend on any context |