From 6c901a19faf455a11efb97462c939bd10a2c09ed Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 23 Jul 2017 21:22:32 -0700 Subject: [PATCH] bip152: add extra limit to avoid hashdos. --- lib/net/bip152.js | 7 +++++++ 1 file changed, 7 insertions(+) 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);