Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Validate if gas limit is not zero (#8307)
Browse files Browse the repository at this point in the history
  • Loading branch information
ordian authored and debris committed Apr 4, 2018
1 parent d57944f commit 811d165
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ethcore/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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())
Expand Down
3 changes: 2 additions & 1 deletion json/src/spec/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

//! Spec genesis deserialization.
use uint::Uint;
use uint::{Uint, self};
use hash::{Address, H256};
use bytes::Bytes;
use spec::Seal;
Expand All @@ -37,6 +37,7 @@ pub struct Genesis {
pub parent_hash: Option<H256>,
/// Gas limit.
#[serde(rename="gasLimit")]
#[serde(deserialize_with="uint::validate_non_zero")]
pub gas_limit: Uint,
/// Transactions root.
#[serde(rename="transactionsRoot")]
Expand Down

0 comments on commit 811d165

Please sign in to comment.