bip152: add extra limit to avoid hashdos.

This commit is contained in:
Christopher Jeffrey 2017-07-23 21:22:32 -07:00
parent 69b862df42
commit 6c901a19fa
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -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);