From eb56d408070f700348be8f66e442ddc9ae6c1e0b Mon Sep 17 00:00:00 2001 From: Ignotus Peverell Date: Wed, 7 Dec 2016 18:54:28 -0800 Subject: [PATCH] Removed limit on number of inputs or outputs in blocks and transactions. For DoS protection only a total message size needs to be enforced by the p2p layer. --- core/src/consensus.rs | 5 ++--- core/src/core/block.rs | 7 +------ core/src/core/transaction.rs | 6 ------ 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/core/src/consensus.rs b/core/src/consensus.rs index 6d0a9f07..e5304916 100644 --- a/core/src/consensus.rs +++ b/core/src/consensus.rs @@ -107,9 +107,8 @@ pub const SOFT_MIN_TARGET: Target = Target([0, 0, 0xf, 0xff, 0xff, 0xff, 0, 0, 0 /// easier to reason about. pub const CUT_THROUGH_HORIZON: u32 = 48 * 3600 / (BLOCK_TIME_SEC as u32); -/// The maximum number of inputs or outputs a transaction may have -/// and be deserializable. Only for DoS protection. -pub const MAX_IN_OUT_LEN: u64 = 50000; +/// The maximum size we're willing to accept for any message. Enforced by the peer-to-peer networking layer only for DoS protection. +pub const MAX_MSG_LEN: u64 = 20_000_000; #[cfg(test)] mod test { diff --git a/core/src/core/block.rs b/core/src/core/block.rs index 65604fab..fcab672c 100644 --- a/core/src/core/block.rs +++ b/core/src/core/block.rs @@ -23,7 +23,7 @@ use std::collections::HashSet; use core::Committed; use core::{Input, Output, Proof, TxProof, Transaction}; use core::transaction::merkle_inputs_outputs; -use consensus::{PROOFSIZE, REWARD, DEFAULT_SIZESHIFT, MAX_IN_OUT_LEN, MAX_TARGET}; +use consensus::{PROOFSIZE, REWARD, DEFAULT_SIZESHIFT, MAX_TARGET}; use core::hash::{Hash, Hashed, ZERO_HASH}; use core::target::Target; use ser::{self, Readable, Reader, Writeable, Writer}; @@ -162,11 +162,6 @@ impl Readable for Block { let (input_len, output_len, proof_len) = ser_multiread!(reader, read_u64, read_u64, read_u64); - if input_len > MAX_IN_OUT_LEN || output_len > MAX_IN_OUT_LEN || proof_len > MAX_IN_OUT_LEN { - return Err(ser::Error::TooLargeReadErr("Too many inputs, outputs or proofs." - .to_string())); - } - let inputs = try!((0..input_len).map(|_| Input::read(reader)).collect()); let outputs = try!((0..output_len).map(|_| Output::read(reader)).collect()); let proofs = try!((0..proof_len).map(|_| TxProof::read(reader)).collect()); diff --git a/core/src/core/transaction.rs b/core/src/core/transaction.rs index 368d7a5d..d05ebfb0 100644 --- a/core/src/core/transaction.rs +++ b/core/src/core/transaction.rs @@ -19,7 +19,6 @@ use secp::{self, Secp256k1, Message, Signature}; use secp::key::SecretKey; use secp::pedersen::{RangeProof, Commitment}; -use consensus::MAX_IN_OUT_LEN; use core::Committed; use core::MerkleRow; use core::hash::{Hash, Hashed}; @@ -109,11 +108,6 @@ impl Readable for Transaction { let (fee, zerosig, input_len, output_len) = ser_multiread!(reader, read_u64, read_vec, read_u64, read_u64); - // in case a facetious miner sends us more than what we can allocate - if input_len > MAX_IN_OUT_LEN || output_len > MAX_IN_OUT_LEN { - return Err(ser::Error::TooLargeReadErr("Too many inputs or outputs.".to_string())); - } - let inputs = try!((0..input_len).map(|_| Input::read(reader)).collect()); let outputs = try!((0..output_len).map(|_| Output::read(reader)).collect());