diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 97f6c329..554f4b9d 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -21,9 +21,10 @@ jobs: - name: Clippy run: cargo clippy --workspace --all-targets -- -D clippy::all -D clippy::nursery - - name: Clippy no_std run: cargo clippy --no-default-features -- -D clippy::all -D clippy::nursery + - name: Clippy with features + run: cargo clippy --features tracing,create-fixed -- -D clippy::all -D clippy::nursery build: runs-on: ubuntu-latest diff --git a/Cargo.toml b/Cargo.toml index b9732300..3321e721 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,10 +9,10 @@ keywords.workspace = true edition.workspace = true [workspace.dependencies] -evm = { version = "0.46.0", path = "." } -evm-core = { version = "0.46.0", path = "core", default-features = false } -evm-gasometer = { version = "0.46.0", path = "gasometer", default-features = false } -evm-runtime = { version = "0.46.0", path = "runtime", default-features = false } +evm = { version = "0.46.1", path = "." } +evm-core = { version = "0.46.1", path = "core", default-features = false } +evm-gasometer = { version = "0.46.1", path = "gasometer", default-features = false } +evm-runtime = { version = "0.46.1", path = "runtime", default-features = false } primitive-types = { version = "0.12", default-features = false } auto_impl = "1.0" sha3 = { version = "0.10", default-features = false } @@ -88,7 +88,7 @@ create-fixed = [] print-debug = ["evm-gasometer/print-debug"] [workspace.package] -version = "0.46.0" +version = "0.46.1" license = "Apache-2.0" authors = ["Aurora Labs ", "Wei Tang ", "Parity Technologies "] description = "Portable Ethereum Virtual Machine implementation written in pure Rust." diff --git a/gasometer/src/tracing.rs b/gasometer/src/tracing.rs index 214375b2..eead9982 100644 --- a/gasometer/src/tracing.rs +++ b/gasometer/src/tracing.rs @@ -9,7 +9,8 @@ pub trait EventListener { } impl Snapshot { - pub fn gas(&self) -> u64 { + #[must_use] + pub const fn gas(&self) -> u64 { self.gas_limit - self.used_gas - self.memory_gas } } diff --git a/src/executor/stack/executor.rs b/src/executor/stack/executor.rs index 8bbdd0ba..8d884886 100644 --- a/src/executor/stack/executor.rs +++ b/src/executor/stack/executor.rs @@ -519,18 +519,12 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> gas_limit: u64, access_list: Vec<(H160, Vec)>, // See EIP-2930 ) -> (ExitReason, Vec) { - if self.nonce(caller) >= U64_MAX { - return (ExitError::MaxNonce.into(), Vec::new()); - } - - let address = self.create_address(CreateScheme::Legacy { caller }); - event!(TransactCreate { caller, value, init_code: &init_code, gas_limit, - address, + address: self.create_address(CreateScheme::Legacy { caller }), }); if let Some(limit) = self.config.max_initcode_size { @@ -545,7 +539,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> } // Initialize initial addresses for EIP-2929 - self.initialize_addresses(caller, address, access_list); + self.initialize_addresses(&[caller], access_list); match self.create_inner( caller, @@ -576,14 +570,12 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> gas_limit: u64, access_list: Vec<(H160, Vec)>, // See EIP-2930 ) -> (ExitReason, Vec) { - let address = self.create_address(CreateScheme::Fixed(address)); - event!(TransactCreate { caller, value, init_code: &init_code, gas_limit, - address + address: self.create_address(CreateScheme::Fixed(address)), }); if let Err(e) = self.record_create_transaction_cost(&init_code, &access_list) { @@ -591,7 +583,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> } // Initialize initial addresses for EIP-2929 - self.initialize_addresses(caller, address, access_list); + self.initialize_addresses(&[caller], access_list); match self.create_inner( caller, @@ -601,7 +593,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> Some(gas_limit), false, ) { - Capture::Exit((s, _, v)) => emit_exit!(s, v), + Capture::Exit((s, v)) => emit_exit!(s, v), Capture::Trap(rt) => { let mut cs: SmallVec<[TaggedRuntime<'_>; DEFAULT_CALL_STACK_CAPACITY]> = smallvec!(rt.0); @@ -621,34 +613,33 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> gas_limit: u64, access_list: Vec<(H160, Vec)>, // See EIP-2930 ) -> (ExitReason, Vec) { - if let Some(limit) = self.config.max_initcode_size { - if init_code.len() > limit { - self.state.metadata_mut().gasometer.fail(); - return emit_exit!(ExitError::CreateContractLimit.into(), Vec::new()); - } - } - let code_hash = H256::from_slice(Keccak256::digest(&init_code).as_slice()); - let address = self.create_address(CreateScheme::Create2 { - caller, - code_hash, - salt, - }); event!(TransactCreate2 { caller, value, init_code: &init_code, salt, gas_limit, - address, + address: self.create_address(CreateScheme::Create2 { + caller, + code_hash, + salt, + }), }); + if let Some(limit) = self.config.max_initcode_size { + if init_code.len() > limit { + self.state.metadata_mut().gasometer.fail(); + return emit_exit!(ExitError::CreateContractLimit.into(), Vec::new()); + } + } + if let Err(e) = self.record_create_transaction_cost(&init_code, &access_list) { return emit_exit!(e.into(), Vec::new()); } // Initialize initial addresses for EIP-2929 - self.initialize_addresses(caller, address, access_list); + self.initialize_addresses(&[caller], access_list); match self.create_inner( caller, @@ -707,7 +698,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> } // Initialize initial addresses for EIP-2929 - self.initialize_addresses(caller, address, access_list); + self.initialize_addresses(&[caller, address], access_list); if let Err(e) = self.state.inc_nonce(caller) { return (e.into(), Vec::new()); @@ -811,23 +802,18 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> self.state.metadata_mut().access_storages(storage_keys); } - fn initialize_addresses( - &mut self, - caller: H160, - address: H160, - access_list: Vec<(H160, Vec)>, - ) { + fn initialize_addresses(&mut self, addresses: &[H160], access_list: Vec<(H160, Vec)>) { if self.config.increase_state_access_gas { if self.config.warm_coinbase_address { // Warm coinbase address for EIP-3651 let coinbase = self.block_coinbase(); self.state .metadata_mut() - .access_addresses([caller, address, coinbase].iter().copied()); + .access_addresses(addresses.iter().copied().chain(Some(coinbase))); } else { self.state .metadata_mut() - .access_addresses([caller, address].iter().copied()); + .access_addresses(addresses.iter().copied()); }; self.initialize_with_access_list(access_list); @@ -1191,6 +1177,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> Interprete #[cfg(feature = "tracing")] { use evm_runtime::tracing::Event::Step; + #[allow(clippy::used_underscore_binding)] evm_runtime::tracing::with(|listener| { listener.event(Step { address: *address, @@ -1198,7 +1185,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> Interprete position: &Ok(_pc), stack: machine.stack(), memory: machine.memory(), - }) + }); }); } @@ -1246,11 +1233,12 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> Interprete #[cfg(feature = "tracing")] { use evm_runtime::tracing::Event::StepResult; + #[allow(clippy::used_underscore_binding)] evm_runtime::tracing::with(|listener| { listener.event(StepResult { result: _result, return_value: _machine.return_value().as_slice(), - }) + }); }); } }