From 811d165458f8e068120a19ca79337b369ef8bbae Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Wed, 4 Apr 2018 18:14:59 +0300 Subject: [PATCH] Validate if gas limit is not zero (#8307) --- ethcore/src/machine.rs | 4 ++-- json/src/spec/genesis.rs | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ethcore/src/machine.rs b/ethcore/src/machine.rs index ad36aa69d..fa6a62454 100644 --- a/ethcore/src/machine.rs +++ b/ethcore/src/machine.rs @@ -203,10 +203,11 @@ impl EthereumMachine { /// The gas floor target must not be lower than the engine's minimum gas limit. pub fn populate_from_parent(&self, header: &mut Header, parent: &Header, gas_floor_target: U256, gas_ceil_target: U256) { header.set_difficulty(parent.difficulty().clone()); + let gas_limit = parent.gas_limit().clone(); + assert!(!gas_limit.is_zero(), "Gas limit should be > 0"); if let Some(ref ethash_params) = self.ethash_extensions { let gas_limit = { - let gas_limit = parent.gas_limit().clone(); let bound_divisor = self.params().gas_limit_bound_divisor; let lower_limit = gas_limit - gas_limit / bound_divisor + 1.into(); let upper_limit = gas_limit + gas_limit / bound_divisor - 1.into(); @@ -238,7 +239,6 @@ impl EthereumMachine { } header.set_gas_limit({ - let gas_limit = parent.gas_limit().clone(); let bound_divisor = self.params().gas_limit_bound_divisor; if gas_limit < gas_floor_target { cmp::min(gas_floor_target, gas_limit + gas_limit / bound_divisor - 1.into()) diff --git a/json/src/spec/genesis.rs b/json/src/spec/genesis.rs index 984053e77..f595e7750 100644 --- a/json/src/spec/genesis.rs +++ b/json/src/spec/genesis.rs @@ -16,7 +16,7 @@ //! Spec genesis deserialization. -use uint::Uint; +use uint::{Uint, self}; use hash::{Address, H256}; use bytes::Bytes; use spec::Seal; @@ -37,6 +37,7 @@ pub struct Genesis { pub parent_hash: Option, /// Gas limit. #[serde(rename="gasLimit")] + #[serde(deserialize_with="uint::validate_non_zero")] pub gas_limit: Uint, /// Transactions root. #[serde(rename="transactionsRoot")]