Skip to content

Commit

Permalink
Update evm and switch to shanghai hardfork (#2691)
Browse files Browse the repository at this point in the history
* update PrecompileHandle ref: rust-ethereum/evm#122

* update fee calculation ref: rust-ethereum/evm#132

* add code_size/code_hash fn in StackState trait ref: rust-ethereum/evm#140

* update evm call stack ref: rust-ethereum/evm#136

* update evm call stack ref: rust-ethereum/evm#155

* add shanghai eips 3651, 3855, 3860 ref: rust-ethereum/evm#152

* update is_precompile ref: rust-ethereum/evm#157

* fix eip-3860 ref: rust-ethereum/evm#160

* update runtime config ref: rust-ethereum/evm#161

* add eip-4399 ref: rust-ethereum/evm#162

* fix eip-2618 ref: rust-ethereum/evm#163

* fix nonce back to U256 ref: rust-ethereum/evm#166

* remove exit_substate in create functions ref: rust-ethereum/evm#168

* record external cost ref: rust-ethereum/evm#170

* add record_external_operation ref: rust-ethereum/evm#171

* add storage_growth ref: rust-ethereum/evm#173

* update evm

* switch to shanghai hardfork

* update ecrecover ref: polkadot-evm/frontier#964 (#2696)
  • Loading branch information
zjb0807 committed Jan 29, 2024
1 parent dd482ac commit 97bfc23
Show file tree
Hide file tree
Showing 48 changed files with 1,565 additions and 1,262 deletions.
62 changes: 25 additions & 37 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion evm-bench
Submodule evm-bench updated 1 files
+4 −4 build/benches.json
2 changes: 1 addition & 1 deletion evm-tests
4 changes: 2 additions & 2 deletions modules/asset-registry/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ pub fn deploy_contracts() {
H256::from_slice(&buf).as_bytes().to_vec()
},
}],
used_gas: 1235081,
used_gas: 1235455,
used_storage: 5131,
}));

Expand Down Expand Up @@ -242,7 +242,7 @@ pub fn deploy_contracts_same_prefix() {
H256::from_slice(&buf).as_bytes().to_vec()
},
}],
used_gas: 1235081,
used_gas: 1235455,
used_storage: 5131,
}));

Expand Down
2 changes: 1 addition & 1 deletion modules/currencies/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ pub fn deploy_contracts() {
H256::from_slice(&buf).as_bytes().to_vec()
},
}],
used_gas: 1235081,
used_gas: 1235455,
used_storage: 5131,
}));

Expand Down
6 changes: 3 additions & 3 deletions modules/evm-bridge/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ pub fn deploy_contracts() {
H256::from_slice(&buf).as_bytes().to_vec()
},
}],
used_gas: 1235081,
used_gas: 1235455,
used_storage: 5131,
}));

Expand All @@ -230,7 +230,7 @@ pub fn deploy_liquidation_ok_contracts() {
from: alice_evm_addr(),
contract: erc20_address(),
logs: vec![],
used_gas: 235274,
used_gas: 235330,
used_storage: 844,
}));

Expand All @@ -257,7 +257,7 @@ pub fn deploy_liquidation_err_contracts() {
from: alice_evm_addr(),
contract: erc20_address(),
logs: vec![],
used_gas: 228284,
used_gas: 228338,
used_storage: 818,
}));

Expand Down
8 changes: 4 additions & 4 deletions modules/evm-utility/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ sha3 = { workspace = true }

sp-std = { workspace = true }

evm = { git = "https://github.com/rust-blockchain/evm", rev = "13240a8a551586fdef0b5028ed73af80b248092a", default-features = false, features = ["with-codec"] }
evm-gasometer = { git = "https://github.com/rust-blockchain/evm", rev = "13240a8a551586fdef0b5028ed73af80b248092a", default-features = false }
evm-runtime = { git = "https://github.com/rust-blockchain/evm", rev = "13240a8a551586fdef0b5028ed73af80b248092a", default-features = false }
ethereum = { version = "0.14.0", default-features = false, features = ["with-codec"] }
evm = { version = "0.41.1", default-features = false, features = ["with-codec"] }
evm-gasometer = { version = "0.41.0", default-features = false }
evm-runtime = { version = "0.41.0", default-features = false }
ethereum = { version = "0.15.0", default-features = false, features = ["with-codec"] }

[features]
default = ["std"]
Expand Down
8 changes: 7 additions & 1 deletion modules/evm/src/bench/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ fn whitelist_keys(b: &mut Bencher, from: H160, code: Vec<u8>) -> H160 {
let state = SubstrateStackState::<Runtime>::new(&vicinity, metadata);
let mut executor = StackExecutor::new_with_precompiles(state, config, &());

let mut runtime = EVMRuntime::new(Rc::new(code.clone()), Rc::new(Vec::new()), context, config);
let mut runtime = EVMRuntime::new(
Rc::new(code.clone()),
Rc::new(Vec::new()),
context,
config.stack_limit,
config.memory_limit,
);
let reason = executor.execute(&mut runtime);

assert!(reason.is_succeed(), "{:?}", reason);
Expand Down
23 changes: 16 additions & 7 deletions modules/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

pub use crate::runner::{
stack::SubstrateStackState,
state::{PrecompileSet, StackExecutor, StackSubstateMetadata},
state::{PrecompileResult, StackExecutor, StackSubstateMetadata},
storage_meter::StorageMeter,
Runner,
};
Expand All @@ -46,7 +46,11 @@ use frame_system::{ensure_root, ensure_signed, pallet_prelude::*, EnsureRoot, En
use hex_literal::hex;
pub use module_evm_utility::{
ethereum::{AccessListItem, Log, TransactionAction},
evm::{self, Config as EvmConfig, Context, ExitError, ExitFatal, ExitReason, ExitRevert, ExitSucceed},
evm::{
self,
executor::stack::{IsPrecompileResult, PrecompileFailure, PrecompileHandle, PrecompileOutput, PrecompileSet},
Config as EvmConfig, Context, ExitError, ExitFatal, ExitReason, ExitRevert, ExitSucceed, ExternalOperation,
},
Account,
};
pub use module_support::{
Expand Down Expand Up @@ -100,17 +104,17 @@ pub type NegativeImbalanceOf<T> =
pub const RESERVE_ID_STORAGE_DEPOSIT: ReserveIdentifier = ReserveIdentifier::EvmStorageDeposit;
pub const RESERVE_ID_DEVELOPER_DEPOSIT: ReserveIdentifier = ReserveIdentifier::EvmDeveloperDeposit;

// Initially based on London hard fork configuration.
// Initially based on shanghai hard fork configuration.
static ACALA_CONFIG: EvmConfig = EvmConfig {
refund_sstore_clears: 0, // no gas refund
sstore_gas_metering: false, // no gas refund
sstore_revert_under_stipend: false, // ignored
create_contract_limit: Some(MaxCodeSize::get() as usize),
..module_evm_utility::evm::Config::london()
..module_evm_utility::evm::Config::shanghai()
};

/// Create an empty contract `contract Empty { }`.
pub const BASE_CREATE_GAS: u64 = 67_066;
pub const BASE_CREATE_GAS: u64 = 67_072;
/// Call function that just set a storage `function store(uint256 num) public { number = num; }`.
pub const BASE_CALL_GAS: u64 = 43_702;

Expand Down Expand Up @@ -410,8 +414,13 @@ pub mod module {
let state = SubstrateStackState::<T>::new(&vicinity, metadata);
let mut executor = StackExecutor::new_with_precompiles(state, T::config(), &());

let mut runtime =
evm::Runtime::new(Rc::new(account.code.clone()), Rc::new(Vec::new()), context, T::config());
let mut runtime = evm::Runtime::new(
Rc::new(account.code.clone()),
Rc::new(Vec::new()),
context,
T::config().stack_limit,
T::config().memory_limit,
);
let reason = executor.execute(&mut runtime);

assert!(
Expand Down
Loading

0 comments on commit 97bfc23

Please sign in to comment.