diff --git a/lib/net/bip152.js b/lib/net/bip152.js index 2b0cbd84..a1a2fe96 100644 --- a/lib/net/bip152.js +++ b/lib/net/bip152.js @@ -417,6 +417,13 @@ CompactBlock.prototype.init = function init() { if (this.totalTX > consensus.MAX_BLOCK_SIZE / 10) throw new Error('Compact block too big.'); + // Custom limit to avoid hashdos: + // Min valid tx size: (4 + 1 + 41 + 1 + 9 + 4) = 60 + // Min block header size: 81 + // Max number of transactions: (1000000 - 81) / 60 = 16665 + if (this.totalTX > (consensus.MAX_BLOCK_SIZE - 81) / 60) + throw new Error('Compact block too big.'); + // No sparse arrays here, v8. for (let i = 0; i < this.totalTX; i++) this.available.push(null);