Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to OpenEthereum 2.6.8 (Istanbul support) #3558

Merged
merged 7 commits into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions runtime/near-evm-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ keccak-hash = "0.2.0"
ripemd160 = "0.9.0"
libsecp256k1 = "0.3.5"

evm = { git = "https://github.com/openethereum/openethereum", rev = "v2.6.2" }
vm = { git = "https://github.com/openethereum/openethereum", rev = "v2.6.2" }
evm = { git = "https://github.com/openethereum/openethereum", rev = "v2.6.8" }
vm = { git = "https://github.com/openethereum/openethereum", rev = "v2.6.8" }
bn = { git = "https://github.com/paritytech/bn", default-features = false }
parity-bytes = "0.1.0"
ethereum-types = "0.6.0"
Expand Down
14 changes: 14 additions & 0 deletions runtime/near-evm-runner/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub fn deploy_code<T: EvmState>(
code: &[u8],
gas: &U256,
evm_gas_config: &EvmCostConfig,
chain_id: u128,
) -> Result<ContractCreateResult> {
let mut nonce = U256::zero();
if address_type == CreateContractAddress::FromSenderAndNonce {
Expand All @@ -49,6 +50,7 @@ pub fn deploy_code<T: EvmState>(
code,
gas,
evm_gas_config,
chain_id,
)?;

// Apply known gas amount changes (all reverts are NeedsReturn)
Expand Down Expand Up @@ -82,6 +84,7 @@ pub fn _create<T: EvmState>(
code: &[u8],
gas: &U256,
evm_gas_config: &EvmCostConfig,
chain_id: u128,
) -> Result<(ExecTrapResult<GasLeft>, Option<StateStore>)> {
let mut store = StateStore::default();
let mut sub_state = SubState::new(sender, &mut store, state);
Expand Down Expand Up @@ -110,6 +113,7 @@ pub fn _create<T: EvmState>(
call_stack_depth + 1,
false,
evm_gas_config,
chain_id,
);
ext.info.gas_limit = U256::from(gas);
ext.schedule = Schedule::new_constantinople();
Expand All @@ -133,6 +137,7 @@ pub fn call<T: EvmState>(
should_commit: bool,
gas: &U256,
evm_gas_config: &EvmCostConfig,
chain_id: u128,
) -> Result<MessageCallResult> {
run_and_commit_if_success(
state,
Expand All @@ -148,6 +153,7 @@ pub fn call<T: EvmState>(
should_commit,
gas,
evm_gas_config,
chain_id,
)
}

Expand All @@ -161,6 +167,7 @@ pub fn delegate_call<T: EvmState>(
input: &[u8],
gas: &U256,
evm_gas_config: &EvmCostConfig,
chain_id: u128,
) -> Result<MessageCallResult> {
run_and_commit_if_success(
state,
Expand All @@ -176,6 +183,7 @@ pub fn delegate_call<T: EvmState>(
true,
gas,
evm_gas_config,
chain_id,
)
}

Expand All @@ -188,6 +196,7 @@ pub fn static_call<T: EvmState>(
input: &[u8],
gas: &U256,
evm_gas_config: &EvmCostConfig,
chain_id: u128,
) -> Result<MessageCallResult> {
run_and_commit_if_success(
state,
Expand All @@ -203,6 +212,7 @@ pub fn static_call<T: EvmState>(
false,
gas,
evm_gas_config,
chain_id,
)
}

Expand All @@ -221,6 +231,7 @@ fn run_and_commit_if_success<T: EvmState>(
should_commit: bool,
gas: &U256,
evm_gas_config: &EvmCostConfig,
chain_id: u128,
) -> Result<MessageCallResult> {
// run the interpreter and
let (result, state_updates) = run_against_state(
Expand All @@ -236,6 +247,7 @@ fn run_and_commit_if_success<T: EvmState>(
is_static,
gas,
evm_gas_config,
chain_id,
)?;

// Apply known gas amount changes (all reverts are NeedsReturn)
Expand Down Expand Up @@ -279,6 +291,7 @@ fn run_against_state<T: EvmState>(
is_static: bool,
gas: &U256,
evm_gas_config: &EvmCostConfig,
chain_id: u128,
) -> Result<(ExecTrapResult<GasLeft>, Option<StateStore>)> {
let code = state.code_at(code_address)?.unwrap_or_else(Vec::new);

Expand Down Expand Up @@ -319,6 +332,7 @@ fn run_against_state<T: EvmState>(
call_stack_depth + 1,
is_static,
evm_gas_config,
chain_id,
);
// Gas limit is evm block gas limit, should at least prepaid gas.
ext.info.gas_limit = *gas;
Expand Down
6 changes: 6 additions & 0 deletions runtime/near-evm-runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub struct EvmContext<'a> {
gas_counter: GasCounter,
pub evm_gas_counter: EvmGasCounter,
fees_config: &'a RuntimeFeesConfig,
chain_id: u128,
domain_separator: RawU256,
}

Expand Down Expand Up @@ -181,6 +182,7 @@ impl<'a> EvmContext<'a> {
),
evm_gas_counter: EvmGasCounter::new(0.into(), evm_gas),
fees_config,
chain_id,
domain_separator,
}
}
Expand All @@ -203,6 +205,7 @@ impl<'a> EvmContext<'a> {
&bytecode,
&self.evm_gas_counter.gas_left(),
&self.fees_config.evm_config,
self.chain_id,
)? {
ContractCreateResult::Created(address, gas_left) => {
self.evm_gas_counter.set_gas_left(gas_left);
Expand Down Expand Up @@ -241,6 +244,7 @@ impl<'a> EvmContext<'a> {
true,
&self.evm_gas_counter.gas_left(),
&self.fees_config.evm_config,
self.chain_id,
)?;
match result {
MessageCallResult::Success(gas_left, data) => {
Expand Down Expand Up @@ -277,6 +281,7 @@ impl<'a> EvmContext<'a> {
true,
&self.evm_gas_counter.gas_left(),
&self.fees_config.evm_config,
self.chain_id,
)?;
match result {
MessageCallResult::Success(gas_left, data) => {
Expand Down Expand Up @@ -313,6 +318,7 @@ impl<'a> EvmContext<'a> {
false,
&self.evm_gas_counter.gas_left(),
&self.fees_config.evm_config,
self.chain_id,
)?;
let result = match result {
MessageCallResult::Success(gas_left, data) => {
Expand Down
15 changes: 15 additions & 0 deletions runtime/near-evm-runner/src/near_ext.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::convert::TryInto;
use std::sync::Arc;

use ethereum_types::{Address, H256, U256};
Expand Down Expand Up @@ -26,6 +27,7 @@ pub struct NearExt<'a> {
pub static_flag: bool,
pub depth: usize,
pub evm_gas_config: &'a EvmCostConfig,
pub chain_id: u128,
}

impl std::fmt::Debug for NearExt<'_> {
Expand All @@ -36,6 +38,7 @@ impl std::fmt::Debug for NearExt<'_> {
write!(f, "\n\tcontext_addr: {:?}", self.context_addr)?;
write!(f, "\n\tstatic_flag: {:?}", self.static_flag)?;
write!(f, "\n\tdepth: {:?}", self.depth)?;
write!(f, "\n\tchain_id: {:?}", self.chain_id)?;
write!(f, "\n}}")
}
}
Expand All @@ -48,6 +51,7 @@ impl<'a> NearExt<'a> {
depth: usize,
static_flag: bool,
evm_gas_config: &'a EvmCostConfig,
chain_id: u128,
) -> Self {
Self {
info: Default::default(),
Expand All @@ -59,11 +63,18 @@ impl<'a> NearExt<'a> {
static_flag,
depth,
evm_gas_config,
chain_id,
}
}
}

impl<'a> vm::Ext for NearExt<'a> {
/// EIP-1344: Returns the current chain's EIP-155 unique identifier.
/// See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1344.md
fn chain_id(&self) -> u64 {
self.chain_id.try_into().unwrap()
}

/// Returns the storage value for a given key if reversion happens on the current transaction.
fn initial_storage_at(&self, key: &H256) -> EvmResult<H256> {
let raw_val = self
Expand Down Expand Up @@ -150,6 +161,7 @@ impl<'a> vm::Ext for NearExt<'a> {
&code.to_vec(),
gas,
&self.evm_gas_config,
self.chain_id,
)
.map_err(|_| TrapKind::Call(ActionParams::default()))
}
Expand Down Expand Up @@ -200,6 +212,7 @@ impl<'a> vm::Ext for NearExt<'a> {
true, // should_commit
gas,
&self.evm_gas_config,
self.chain_id,
),
CallType::StaticCall => interpreter::static_call(
self.sub_state,
Expand All @@ -210,6 +223,7 @@ impl<'a> vm::Ext for NearExt<'a> {
&data.to_vec(),
gas,
&self.evm_gas_config,
self.chain_id,
),
CallType::CallCode => {
// Call another contract using storage of the current contract. No longer used.
Expand All @@ -225,6 +239,7 @@ impl<'a> vm::Ext for NearExt<'a> {
&data.to_vec(),
gas,
&self.evm_gas_config,
self.chain_id,
),
};
result.map_err(|_| TrapKind::Call(ActionParams::default()))
Expand Down