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

Commit

Permalink
BLOCKHASH transition and gas price update
Browse files Browse the repository at this point in the history
  • Loading branch information
arkpar committed Jun 16, 2017
1 parent b85e75b commit 4a1f205
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 51 deletions.
11 changes: 8 additions & 3 deletions ethcore/res/ethereum/metropolis_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@
"maximumExtraDataSize": "0x20",
"minGasLimit": "0x1388",
"networkID" : "0x1",
"eip98Transition": "0x0",
"eip98Transition": "0x7fffffffffffffff",
"eip86Transition": "0x0",
"eip140Transition": "0x0",
"eip210Transition": "0x0"
"eip210Transition": "0x0",
"eip198Transition": "0x0",
"eip100Transition": "0x0",
"eip211Transition": "0x0",
"eip212Transition": "0x0",
"eip213Transition": "0x0",
"eip214Transition": "0x0"
},
"genesis": {
"seal": {
Expand Down
2 changes: 1 addition & 1 deletion ethcore/res/ethereum/tests
Submodule tests updated 3674 files
4 changes: 2 additions & 2 deletions ethcore/src/evm/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl Schedule {
self.have_revert = block_number >= params.eip140_transition;
self.have_static_call = block_number >= params.eip214_transition;
if block_number >= params.eip210_transition {
self.blockhash_gas = 350;
self.blockhash_gas = 800;
}
}

Expand All @@ -194,7 +194,7 @@ impl Schedule {
schedule.have_create2 = true;
schedule.have_revert = true;
schedule.have_static_call = true;
schedule.blockhash_gas = 350;
schedule.blockhash_gas = 800;
schedule
}

Expand Down
83 changes: 40 additions & 43 deletions ethcore/src/externalities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,50 +138,47 @@ impl<'a, T: 'a, V: 'a, B: 'a, E: 'a> Ext for Externalities<'a, T, V, B, E>
}

fn blockhash(&mut self, number: &U256) -> H256 {
if self.env_info.number + 256 >= self.engine.params().eip210_transition {
let blockhash_contract_address = self.engine.params().eip210_contract_address;
let code_res = self.state.code(&blockhash_contract_address)
.and_then(|code| self.state.code_hash(&blockhash_contract_address).map(|hash| (code, hash)));

let (code, code_hash) = match code_res {
Ok((code, hash)) => (code, hash),
Err(_) => return H256::zero(),
};

let params = ActionParams {
sender: self.origin_info.address.clone(),
address: blockhash_contract_address.clone(),
value: ActionValue::Apparent(self.origin_info.value),
code_address: blockhash_contract_address.clone(),
origin: self.origin_info.origin.clone(),
gas: self.engine.params().eip210_contract_gas,
gas_price: 0.into(),
code: code,
code_hash: code_hash,
data: Some(H256::from(number).to_vec()),
call_type: CallType::Call,
};

let mut output = H256::new();
let mut ex = Executive::new(self.state, self.env_info, self.engine);
let r = ex.call(params, self.substate, BytesRef::Fixed(&mut output), self.tracer, self.vm_tracer);
trace!("ext: blockhash contract({}) -> {:?}({}) self.env_info.number={}\n", number, r, output, self.env_info.number);
output
} else {
// TODO: comment out what this function expects from env_info, since it will produce panics if the latter is inconsistent
match *number < U256::from(self.env_info.number) && number.low_u64() >= cmp::max(256, self.env_info.number) - 256 {
true => {
let index = self.env_info.number - number.low_u64() - 1;
assert!(index < self.env_info.last_hashes.len() as u64, format!("Inconsistent env_info, should contain at least {:?} last hashes", index+1));
let r = self.env_info.last_hashes[index as usize].clone();
trace!("ext: blockhash({}) -> {} self.env_info.number={}\n", number, r, self.env_info.number);
r
},
false => {
trace!("ext: blockhash({}) -> null self.env_info.number={}\n", number, self.env_info.number);
H256::zero()
},
// this function only uses number from env_info
if *number < U256::from(self.env_info.number) && number.low_u64() >= cmp::max(256, self.env_info.number) - 256 {
if self.env_info.number >= 256 && self.env_info.number - 256 >= self.engine.params().eip210_transition {
let blockhash_contract_address = self.engine.params().eip210_contract_address;
let code_res = self.state.code(&blockhash_contract_address)
.and_then(|code| self.state.code_hash(&blockhash_contract_address).map(|hash| (code, hash)));

let (code, code_hash) = match code_res {
Ok((code, hash)) => (code, hash),
Err(_) => return H256::zero(),
};

let params = ActionParams {
sender: self.origin_info.address.clone(),
address: blockhash_contract_address.clone(),
value: ActionValue::Apparent(self.origin_info.value),
code_address: blockhash_contract_address.clone(),
origin: self.origin_info.origin.clone(),
gas: self.engine.params().eip210_contract_gas,
gas_price: 0.into(),
code: code,
code_hash: code_hash,
data: Some(H256::from(number).to_vec()),
call_type: CallType::Call,
};

let mut output = H256::new();
let mut ex = Executive::new(self.state, self.env_info, self.engine);
let r = ex.call(params, self.substate, BytesRef::Fixed(&mut output), self.tracer, self.vm_tracer);
trace!("ext: blockhash contract({}) -> {:?}({}) self.env_info.number={}\n", number, r, output, self.env_info.number);
output
} else {
let index = self.env_info.number - number.low_u64() - 1;
assert!(index < self.env_info.last_hashes.len() as u64, format!("Inconsistent env_info, should contain at least {:?} last hashes", index+1));
let r = self.env_info.last_hashes[index as usize].clone();
trace!("ext: blockhash({}) -> {} self.env_info.number={}\n", number, r, self.env_info.number);
r
}
} else {
trace!("ext: blockhash({}) -> null self.env_info.number={}\n", number, self.env_info.number);
H256::zero()
}
}

Expand Down
4 changes: 2 additions & 2 deletions ethcore/src/json_tests/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ lazy_static! {
pub static ref HOMESTEAD: Spec = ethereum::new_homestead_test();
pub static ref EIP150: Spec = ethereum::new_eip150_test();
pub static ref EIP161: Spec = ethereum::new_eip161_test();
pub static ref _METROPOLIS: Spec = ethereum::new_metropolis_test();
pub static ref METROPOLIS: Spec = ethereum::new_metropolis_test();
}

pub fn json_chain_test(json_data: &[u8]) -> Vec<String> {
Expand All @@ -50,7 +50,7 @@ pub fn json_chain_test(json_data: &[u8]) -> Vec<String> {
ForkSpec::Homestead => &HOMESTEAD.engine,
ForkSpec::EIP150 => &EIP150.engine,
ForkSpec::EIP158 => &EIP161.engine,
ForkSpec::Metropolis => continue,
ForkSpec::Metropolis => &METROPOLIS.engine,
};

for (i, state) in states.into_iter().enumerate() {
Expand Down

0 comments on commit 4a1f205

Please sign in to comment.