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.cpp | |
| 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.cpp')
| -rw-r--r-- | src/main.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
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 | |||
| 1261 | if (!tx.CheckTransaction()) | 1261 | if (!tx.CheckTransaction()) |
| 1262 | return error("CheckBlock() : CheckTransaction failed"); | 1262 | return error("CheckBlock() : CheckTransaction failed"); |
| 1263 | 1263 | ||
| 1264 | // Cap the work a block can demand. MAX_SIZE bounds the bytes, not the cost: | ||
| 1265 | // every signature operation is an elliptic-curve verification, and at this | ||
| 1266 | // chain's difficulty a block packed with them is affordable to mine and | ||
| 1267 | // expensive for everyone else to reject. | ||
| 1268 | unsigned int nSigOps = 0; | ||
| 1269 | foreach(const CTransaction& tx, vtx) | ||
| 1270 | nSigOps += tx.GetSigOpCount(); | ||
| 1271 | if (nSigOps > MAX_BLOCK_SIGOPS) | ||
| 1272 | return error("CheckBlock() : out-of-bounds signature operation count"); | ||
| 1273 | |||
| 1264 | // Reject blocks carrying the same transaction twice (CVE-2012-2459). | 1274 | // Reject blocks carrying the same transaction twice (CVE-2012-2459). |
| 1265 | // | 1275 | // |
| 1266 | // BuildMerkleTree duplicates the last hash when a level has an odd width, | 1276 | // BuildMerkleTree duplicates the last hash when a level has an odd width, |