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

Commit

Permalink
Merge remote-tracking branch 'origin/master' into dp/chore/update-com…
Browse files Browse the repository at this point in the history
…mon-deps

* origin/master:
  fix (light/provider) : Make `read_only executions` read-only (#9591)
  ethcore: fix detection of major import (#9552)
  return 0 on error (#9705)
  ethcore: delay ropsten hardfork (#9704)
  make instantSeal engine backwards compatible, closes #9696 (#9700)
  Implement CREATE2 gas changes and fix some potential overflowing (#9694)
  Don't hash the init_code of CREATE. (#9688)
  ethcore: minor optimization of modexp by using LR exponentiation (#9697)
  removed redundant clone before each block import (#9683)
  • Loading branch information
dvdplm committed Oct 9, 2018
2 parents cced545 + 5b54442 commit 1dae486
Show file tree
Hide file tree
Showing 21 changed files with 260 additions and 101 deletions.
4 changes: 1 addition & 3 deletions ethcore/benches/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ extern crate ethereum_types;
extern crate parity_bytes as bytes;
extern crate rustc_hex;

use std::collections::BTreeMap;

use bytes::BytesRef;
use ethcore::builtin::Builtin;
use ethcore::machine::EthereumMachine;
use ethereum_types::{Address, U256};
use ethereum_types::U256;
use ethcore::ethereum::new_byzantium_test_machine;
use rustc_hex::FromHex;
use self::test::Bencher;
Expand Down
2 changes: 1 addition & 1 deletion ethcore/evm/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl Finalize for Error {

/// Cost calculation type. For low-gas usage we calculate costs using usize instead of U256
pub trait CostType: Sized + From<usize> + Copy + Send
+ ops::Mul<Output=Self> + ops::Div<Output=Self> + ops::Add<Output=Self> +ops::Sub<Output=Self>
+ ops::Mul<Output=Self> + ops::Div<Output=Self> + ops::Add<Output=Self> + ops::Sub<Output=Self>
+ ops::Shr<usize, Output=Self> + ops::Shl<usize, Output=Self>
+ cmp::Ord + fmt::Debug {
/// Converts this cost into `U256`
Expand Down
40 changes: 32 additions & 8 deletions ethcore/evm/src/interpreter/gasometer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,8 @@ impl<Gas: evm::CostType> Gasometer<Gas> {
Request::GasMem(default_gas, mem_needed(stack.peek(0), stack.peek(1))?)
},
instructions::SHA3 => {
let w = overflowing!(add_gas_usize(Gas::from_u256(*stack.peek(1))?, 31));
let words = w >> 5;
let gas = Gas::from(schedule.sha3_gas) + (Gas::from(schedule.sha3_word_gas) * words);
let words = overflowing!(to_word_size(Gas::from_u256(*stack.peek(1))?));
let gas = overflowing!(Gas::from(schedule.sha3_gas).overflow_add(overflowing!(Gas::from(schedule.sha3_word_gas).overflow_mul(words))));
Request::GasMem(gas, mem_needed(stack.peek(0), stack.peek(1))?)
},
instructions::CALLDATACOPY | instructions::CODECOPY | instructions::RETURNDATACOPY => {
Expand Down Expand Up @@ -231,9 +230,24 @@ impl<Gas: evm::CostType> Gasometer<Gas> {

Request::GasMemProvide(gas, mem, Some(requested))
},
instructions::CREATE | instructions::CREATE2 => {
instructions::CREATE => {
let start = stack.peek(1);
let len = stack.peek(2);

let gas = Gas::from(schedule.create_gas);
let mem = mem_needed(stack.peek(1), stack.peek(2))?;
let mem = mem_needed(start, len)?;

Request::GasMemProvide(gas, mem, None)
},
instructions::CREATE2 => {
let start = stack.peek(1);
let len = stack.peek(2);

let base = Gas::from(schedule.create_gas);
let word = overflowing!(to_word_size(Gas::from_u256(*len)?));
let word_gas = overflowing!(Gas::from(schedule.sha3_word_gas).overflow_mul(word));
let gas = overflowing!(base.overflow_add(word_gas));
let mem = mem_needed(start, len)?;

Request::GasMemProvide(gas, mem, None)
},
Expand Down Expand Up @@ -283,8 +297,8 @@ impl<Gas: evm::CostType> Gasometer<Gas> {
},
Request::GasMemCopy(gas, mem_size, copy) => {
let (mem_gas_cost, new_mem_gas, new_mem_size) = self.mem_gas_cost(schedule, current_mem_size, &mem_size)?;
let copy = overflowing!(add_gas_usize(copy, 31)) >> 5;
let copy_gas = Gas::from(schedule.copy_gas) * copy;
let copy = overflowing!(to_word_size(copy));
let copy_gas = overflowing!(Gas::from(schedule.copy_gas).overflow_mul(copy));
let gas = overflowing!(gas.overflow_add(copy_gas));
let gas = overflowing!(gas.overflow_add(mem_gas_cost));

Expand All @@ -311,7 +325,7 @@ impl<Gas: evm::CostType> Gasometer<Gas> {
};

let current_mem_size = Gas::from(current_mem_size);
let req_mem_size_rounded = (overflowing!(mem_size.overflow_add(Gas::from(31 as usize))) >> 5) << 5;
let req_mem_size_rounded = overflowing!(to_word_size(*mem_size)) << 5;

let (mem_gas_cost, new_mem_gas) = if req_mem_size_rounded > current_mem_size {
let new_mem_gas = gas_for_mem(req_mem_size_rounded)?;
Expand Down Expand Up @@ -343,6 +357,16 @@ fn add_gas_usize<Gas: evm::CostType>(value: Gas, num: usize) -> (Gas, bool) {
value.overflow_add(Gas::from(num))
}

#[inline]
fn to_word_size<Gas: evm::CostType>(value: Gas) -> (Gas, bool) {
let (gas, overflow) = add_gas_usize(value, 31);
if overflow {
return (gas, overflow);
}

(gas >> 5, false)
}

#[inline]
fn calculate_eip1283_sstore_gas<Gas: evm::CostType>(schedule: &Schedule, original: &U256, current: &U256, new: &U256) -> Gas {
Gas::from(
Expand Down
3 changes: 1 addition & 2 deletions ethcore/evm/src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,7 @@ impl<Cost: CostType> Interpreter<Cost> {
match result {
InstructionResult::JumpToPosition(position) => {
if self.valid_jump_destinations.is_none() {
let code_hash = self.params.code_hash.clone().unwrap_or_else(|| keccak(self.reader.code.as_ref()));
self.valid_jump_destinations = Some(self.cache.jump_destinations(&code_hash, &self.reader.code));
self.valid_jump_destinations = Some(self.cache.jump_destinations(&self.params.code_hash, &self.reader.code));
}
let jump_destinations = self.valid_jump_destinations.as_ref().expect("jump_destinations are initialized on first jump; qed");
let pos = self.verify_jump(position, jump_destinations)?;
Expand Down
19 changes: 12 additions & 7 deletions ethcore/evm/src/interpreter/shared_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,22 @@ impl SharedCache {
}

/// Get jump destinations bitmap for a contract.
pub fn jump_destinations(&self, code_hash: &H256, code: &[u8]) -> Arc<BitSet> {
if code_hash == &KECCAK_EMPTY {
return Self::find_jump_destinations(code);
}
pub fn jump_destinations(&self, code_hash: &Option<H256>, code: &[u8]) -> Arc<BitSet> {
if let Some(ref code_hash) = code_hash {
if code_hash == &KECCAK_EMPTY {
return Self::find_jump_destinations(code);
}

if let Some(d) = self.jump_destinations.lock().get_mut(code_hash) {
return d.0.clone();
if let Some(d) = self.jump_destinations.lock().get_mut(code_hash) {
return d.0.clone();
}
}

let d = Self::find_jump_destinations(code);
self.jump_destinations.lock().insert(code_hash.clone(), Bits(d.clone()));

if let Some(ref code_hash) = code_hash {
self.jump_destinations.lock().insert(*code_hash, Bits(d.clone()));
}

d
}
Expand Down
2 changes: 1 addition & 1 deletion ethcore/light/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl<T: ChainDataFetcher> Client<T> {

/// Import a header to the queue for additional verification.
pub fn import_header(&self, header: Header) -> EthcoreResult<H256> {
self.queue.import(header).map_err(Into::into)
self.queue.import(header).map_err(|(_, e)| e)
}

/// Inquire about the status of a given header.
Expand Down
12 changes: 6 additions & 6 deletions ethcore/res/ethereum/ropsten.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
"blockReward": {
"0": "0x4563918244F40000",
"1700000": "0x29A2241AF62C0000",
"4200000": "0x1BC16D674EC80000"
"4230000": "0x1BC16D674EC80000"
},
"homesteadTransition": 0,
"eip100bTransition": 1700000,
"difficultyBombDelays": {
"1700000": 3000000,
"4200000": 2000000
"4230000": 2000000
}
}
}
Expand All @@ -42,10 +42,10 @@
"eip211Transition": 1700000,
"eip214Transition": 1700000,
"eip658Transition": 1700000,
"eip145Transition": 4200000,
"eip1014Transition": 4200000,
"eip1052Transition": 4200000,
"eip1283Transition": 4200000
"eip145Transition": 4230000,
"eip1014Transition": 4230000,
"eip1052Transition": 4230000,
"eip1283Transition": 4230000
},
"genesis": {
"seal": {
Expand Down
98 changes: 98 additions & 0 deletions ethcore/res/ethereum/tests-issues/currents.json
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,104 @@
"chain": "Constantinople (test)"
}
}
},
{
"reference": "9590",
"failing": "stCreate2Test",
"subtests": {
"call_then_create2_successful_then_returndatasize": {
"subnumbers": ["1"],
"chain": "Constantinople (test)"
},
"returndatacopy_afterFailing_create": {
"subnumbers": ["1"],
"chain": "Constantinople (test)"
},
"create2checkFieldsInInitcode": {
"subnumbers": ["1","2","3","5","6","7"],
"chain": "Constantinople (test)"
},
"Create2Recursive": {
"subnumbers": ["*"],
"chain": "Constantinople (test)"
},
"create2collisionBalance": {
"subnumbers": ["2","3"],
"chain": "Constantinople (test)"
},
"create2InitCodes": {
"subnumbers": ["1","5","6","7","8","9"],
"chain": "Constantinople (test)"
},
"Create2OOGafterInitCode": {
"subnumbers": ["2"],
"chain": "Constantinople (test)"
},
"CreateMessageRevertedOOGInInit": {
"subnumbers": ["2"],
"chain": "Constantinople (test)"
},
"returndatacopy_following_revert_in_create": {
"subnumbers": ["*"],
"chain": "Constantinople (test)"
},
"create2collisionSelfdestructed": {
"subnumbers": ["2"],
"chain": "Constantinople (test)"
},
"returndatacopy_0_0_following_successful_create": {
"subnumbers": ["*"],
"chain": "Constantinople (test)"
},
"Create2OnDepth1023": {
"subnumbers": ["*"],
"chain": "Constantinople (test)"
},
"Create2OOGafterInitCodeReturndata2": {
"subnumbers": ["2"],
"chain": "Constantinople (test)"
},
"RevertOpcodeInCreateReturns": {
"subnumbers": ["*"],
"chain": "Constantinople (test)"
},
"CREATE2_ContractSuicideDuringInit_ThenStoreThenReturn": {
"subnumbers": ["*"],
"chain": "Constantinople (test)"
},
"returndatasize_following_successful_create": {
"subnumbers": ["*"],
"chain": "Constantinople (test)"
},
"call_outsize_then_create2_successful_then_returndatasize": {
"subnumbers": ["*"],
"chain": "Constantinople (test)"
},
"CreateMessageReverted": {
"subnumbers": ["2"],
"chain": "Constantinople (test)"
},
"CREATE2_Suicide": {
"subnumbers": ["*"],
"chain": "Constantinople (test)"
},
"Create2OOGafterInitCodeRevert": {
"subnumbers": ["*"],
"chain": "Constantinople (test)"
},
"Create2OnDepth1024": {
"subnumbers": ["*"],
"chain": "Constantinople (test)"
},
"create2collisionStorage": {
"subnumbers": ["2","3"],
"chain": "Constantinople (test)"
},
"create2callPrecompiles": {
"subnumbers": ["*"],
"chain": "Constantinople (test)"
}
}
}
]
}
Loading

0 comments on commit 1dae486

Please sign in to comment.