diff --git a/bins/revme/src/cmd/statetest/merkle_trie.rs b/bins/revme/src/cmd/statetest/merkle_trie.rs index c869938bf0..b7a97cd7c7 100644 --- a/bins/revme/src/cmd/statetest/merkle_trie.rs +++ b/bins/revme/src/cmd/statetest/merkle_trie.rs @@ -40,7 +40,7 @@ impl TrieAccount { root_hash: sec_trie_root::( acc.storage .iter() - .filter(|(_k, &v)| v != U256::ZERO) + .filter(|(_k, &v)| !v.is_zero()) .map(|(k, v)| (k.to_be_bytes::<32>(), alloy_rlp::encode_fixed_size(v))), ), code_hash: acc.info.code_hash, diff --git a/crates/interpreter/src/gas/calc.rs b/crates/interpreter/src/gas/calc.rs index 4f6d867e60..5e33c43fbf 100644 --- a/crates/interpreter/src/gas/calc.rs +++ b/crates/interpreter/src/gas/calc.rs @@ -29,15 +29,15 @@ pub fn sstore_refund(spec_id: SpecId, original: U256, current: U256, new: U256) if current == new { 0 } else { - if original == current && new == U256::ZERO { + if original == current && new.is_zero() { sstore_clears_schedule } else { let mut refund = 0; - if original != U256::ZERO { - if current == U256::ZERO { + if !original.is_zero() { + if current.is_zero() { refund -= sstore_clears_schedule; - } else if new == U256::ZERO { + } else if new.is_zero() { refund += sstore_clears_schedule; } } @@ -48,7 +48,7 @@ pub fn sstore_refund(spec_id: SpecId, original: U256, current: U256, new: U256) } else { (SSTORE_RESET, sload_cost(spec_id, false)) }; - if original == U256::ZERO { + if original.is_zero() { refund += (SSTORE_SET - gas_sload) as i64; } else { refund += (gas_sstore_reset - gas_sload) as i64; @@ -59,7 +59,7 @@ pub fn sstore_refund(spec_id: SpecId, original: U256, current: U256, new: U256) } } } else { - if current != U256::ZERO && new == U256::ZERO { + if !current.is_zero() && new.is_zero() { REFUND_SSTORE_CLEARS } else { 0 @@ -99,7 +99,7 @@ const fn log2floor(value: U256) -> u64 { /// `EXP` opcode cost calculation. #[inline] pub fn exp_cost(spec_id: SpecId, power: U256) -> Option { - if power == U256::ZERO { + if power.is_zero() { Some(EXP) } else { // EIP-160: EXP cost increase @@ -230,7 +230,7 @@ fn istanbul_sstore_cost( ) -> u64 { if new == current { SLOAD_GAS - } else if original == current && original == U256::ZERO { + } else if original == current && original.is_zero() { SSTORE_SET } else if original == current { SSTORE_RESET_GAS @@ -242,7 +242,7 @@ fn istanbul_sstore_cost( /// Frontier sstore cost just had two cases set and reset values. #[inline] fn frontier_sstore_cost(current: U256, new: U256) -> u64 { - if current == U256::ZERO && new != U256::ZERO { + if current.is_zero() && !new.is_zero() { SSTORE_SET } else { SSTORE_RESET diff --git a/crates/interpreter/src/instructions/arithmetic.rs b/crates/interpreter/src/instructions/arithmetic.rs index 34c98a348b..9b34aa14f9 100644 --- a/crates/interpreter/src/instructions/arithmetic.rs +++ b/crates/interpreter/src/instructions/arithmetic.rs @@ -26,7 +26,7 @@ pub fn sub(interpreter: &mut Interpreter, _host: &mut H) { pub fn div(interpreter: &mut Interpreter, _host: &mut H) { gas!(interpreter, gas::LOW); pop_top!(interpreter, op1, op2); - if *op2 != U256::ZERO { + if !op2.is_zero() { *op2 = op1.wrapping_div(*op2); } } @@ -40,7 +40,7 @@ pub fn sdiv(interpreter: &mut Interpreter, _host: &mut H) { pub fn rem(interpreter: &mut Interpreter, _host: &mut H) { gas!(interpreter, gas::LOW); pop_top!(interpreter, op1, op2); - if *op2 != U256::ZERO { + if !op2.is_zero() { *op2 = op1.wrapping_rem(*op2); } } diff --git a/crates/interpreter/src/instructions/bitwise.rs b/crates/interpreter/src/instructions/bitwise.rs index a02058419f..8a87ee5ae0 100644 --- a/crates/interpreter/src/instructions/bitwise.rs +++ b/crates/interpreter/src/instructions/bitwise.rs @@ -39,7 +39,7 @@ pub fn eq(interpreter: &mut Interpreter, _host: &mut H) { pub fn iszero(interpreter: &mut Interpreter, _host: &mut H) { gas!(interpreter, gas::VERYLOW); pop_top!(interpreter, op1); - *op1 = U256::from(*op1 == U256::ZERO); + *op1 = U256::from(op1.is_zero()); } pub fn bitand(interpreter: &mut Interpreter, _host: &mut H) { diff --git a/crates/interpreter/src/instructions/contract.rs b/crates/interpreter/src/instructions/contract.rs index d10cb05b34..7128c7a03f 100644 --- a/crates/interpreter/src/instructions/contract.rs +++ b/crates/interpreter/src/instructions/contract.rs @@ -231,7 +231,7 @@ pub fn extcall(interpreter: &mut Interpreter, host }; pop!(interpreter, value); - let has_transfer = value != U256::ZERO; + let has_transfer = !value.is_zero(); if interpreter.is_static && has_transfer { interpreter.instruction_result = InstructionResult::CallNotAllowedInsideStatic; return; @@ -406,7 +406,7 @@ pub fn call(interpreter: &mut Interpreter, host: & let local_gas_limit = u64::try_from(local_gas_limit).unwrap_or(u64::MAX); pop!(interpreter, value); - let has_transfer = value != U256::ZERO; + let has_transfer = !value.is_zero(); if interpreter.is_static && has_transfer { interpreter.instruction_result = InstructionResult::CallNotAllowedInsideStatic; return; @@ -474,7 +474,7 @@ pub fn call_code(interpreter: &mut Interpreter, ho let Some(mut gas_limit) = calc_call_gas::( interpreter, is_cold, - value != U256::ZERO, + !value.is_zero(), false, local_gas_limit, ) else { @@ -484,7 +484,7 @@ pub fn call_code(interpreter: &mut Interpreter, ho gas!(interpreter, gas_limit); // add call stipend if there is value to be transferred. - if value != U256::ZERO { + if !value.is_zero() { gas_limit = gas_limit.saturating_add(gas::CALL_STIPEND); } diff --git a/crates/interpreter/src/instructions/control.rs b/crates/interpreter/src/instructions/control.rs index 4aacffd9e4..40e9ace212 100644 --- a/crates/interpreter/src/instructions/control.rs +++ b/crates/interpreter/src/instructions/control.rs @@ -62,7 +62,7 @@ pub fn jump(interpreter: &mut Interpreter, _host: &mut H) { pub fn jumpi(interpreter: &mut Interpreter, _host: &mut H) { gas!(interpreter, gas::HIGH); pop!(interpreter, target, cond); - if cond != U256::ZERO { + if !cond.is_zero() { jump_inner(interpreter, target); } } diff --git a/crates/interpreter/src/instructions/i256.rs b/crates/interpreter/src/instructions/i256.rs index d7f72446d9..07d897450a 100644 --- a/crates/interpreter/src/instructions/i256.rs +++ b/crates/interpreter/src/instructions/i256.rs @@ -33,7 +33,7 @@ pub fn i256_sign(val: &U256) -> Sign { Sign::Minus } else { // SAFETY: false == 0 == Zero, true == 1 == Plus - unsafe { core::mem::transmute::(*val != U256::ZERO) } + unsafe { core::mem::transmute::(!val.is_zero()) } } } diff --git a/crates/precompile/src/modexp.rs b/crates/precompile/src/modexp.rs index 8d9e5da8c0..4839bff751 100644 --- a/crates/precompile/src/modexp.rs +++ b/crates/precompile/src/modexp.rs @@ -32,7 +32,7 @@ pub fn berlin_run(input: &Bytes, gas_limit: u64) -> PrecompileResult { pub fn calculate_iteration_count(exp_length: u64, exp_highp: &U256) -> u64 { let mut iteration_count: u64 = 0; - if exp_length <= 32 && *exp_highp == U256::ZERO { + if exp_length <= 32 && exp_highp.is_zero() { iteration_count = 0; } else if exp_length <= 32 { iteration_count = exp_highp.bit_len() as u64 - 1; diff --git a/crates/primitives/src/state.rs b/crates/primitives/src/state.rs index ff2e99f8b4..d6ddb3d215 100644 --- a/crates/primitives/src/state.rs +++ b/crates/primitives/src/state.rs @@ -273,8 +273,8 @@ impl AccountInfo { /// - balance is zero /// - nonce is zero pub fn is_empty(&self) -> bool { - let code_empty = self.is_empty_code_hash() || self.code_hash == B256::ZERO; - code_empty && self.balance == U256::ZERO && self.nonce == 0 + let code_empty = self.is_empty_code_hash() || self.code_hash.is_zero(); + code_empty && self.balance.is_zero() && self.nonce == 0 } /// Returns `true` if the account is not empty. diff --git a/crates/revm/src/context/evm_context.rs b/crates/revm/src/context/evm_context.rs index db009efe32..9e322a3a60 100644 --- a/crates/revm/src/context/evm_context.rs +++ b/crates/revm/src/context/evm_context.rs @@ -11,7 +11,7 @@ use crate::{ primitives::{ keccak256, Address, Bytecode, Bytes, CreateScheme, EVMError, Env, Eof, SpecId::{self, *}, - B256, EOF_MAGIC_BYTES, U256, + B256, EOF_MAGIC_BYTES, }, ContextPrecompiles, FrameOrResult, CALL_STACK_LIMIT, }; @@ -185,7 +185,7 @@ impl EvmContext { // Touch address. For "EIP-158 State Clear", this will erase empty accounts. match inputs.value { // if transfer value is zero, load account and force the touch. - CallValue::Transfer(value) if value == U256::ZERO => { + CallValue::Transfer(value) if value.is_zero() => { self.load_account(inputs.target_address)?; self.journaled_state.touch(&inputs.target_address); } @@ -458,6 +458,7 @@ impl EvmContext { #[cfg(any(test, feature = "test-utils"))] pub(crate) mod test_utils { use super::*; + use crate::primitives::U256; use crate::{ db::{CacheDB, EmptyDB}, journaled_state::JournaledState, @@ -542,6 +543,7 @@ pub(crate) mod test_utils { #[cfg(test)] mod tests { use super::*; + use crate::primitives::U256; use crate::{ db::{CacheDB, EmptyDB}, primitives::{address, Bytecode}, diff --git a/crates/revm/src/db/in_memory_db.rs b/crates/revm/src/db/in_memory_db.rs index fb0befed2e..58ab9ba1ba 100644 --- a/crates/revm/src/db/in_memory_db.rs +++ b/crates/revm/src/db/in_memory_db.rs @@ -71,7 +71,7 @@ impl CacheDB { .or_insert_with(|| code.clone()); } } - if account.code_hash == B256::ZERO { + if account.code_hash.is_zero() { account.code_hash = KECCAK_EMPTY; } } diff --git a/crates/revm/src/db/states/bundle_state.rs b/crates/revm/src/db/states/bundle_state.rs index 22797c8761..b218e49c10 100644 --- a/crates/revm/src/db/states/bundle_state.rs +++ b/crates/revm/src/db/states/bundle_state.rs @@ -605,7 +605,7 @@ impl BundleState { for (key, slot) in account.storage { // If storage was destroyed that means that storage was wiped. // In that case we need to check if present storage value is different then ZERO. - let destroyed_and_not_zero = was_destroyed && slot.present_value != U256::ZERO; + let destroyed_and_not_zero = was_destroyed && !slot.present_value.is_zero(); // If account is not destroyed check if original values was changed, // so we can update it. diff --git a/crates/revm/src/journaled_state.rs b/crates/revm/src/journaled_state.rs index bea240895c..a9cfa4ccee 100644 --- a/crates/revm/src/journaled_state.rs +++ b/crates/revm/src/journaled_state.rs @@ -399,7 +399,7 @@ impl JournaledState { had_value, } => { let tkey = (address, key); - if had_value == U256::ZERO { + if had_value.is_zero() { // if previous value is zero, remove it transient_storage.remove(&tkey); } else { @@ -525,7 +525,7 @@ impl JournaledState { }; Ok(SelfDestructResult { - had_value: balance != U256::ZERO, + had_value: !balance.is_zero(), is_cold: load_result.is_cold, target_exists: !load_result.is_empty, previously_destroyed, @@ -762,7 +762,7 @@ impl JournaledState { /// EIP-1153: Transient storage opcodes #[inline] pub fn tstore(&mut self, address: Address, key: U256, new: U256) { - let had_value = if new == U256::ZERO { + let had_value = if new.is_zero() { // if new values is zero, remove entry from transient storage. // if previous values was some insert it inside journal. // If it is none nothing should be inserted. diff --git a/crates/revm/src/optimism/l1block.rs b/crates/revm/src/optimism/l1block.rs index e348718db2..86e32850fa 100644 --- a/crates/revm/src/optimism/l1block.rs +++ b/crates/revm/src/optimism/l1block.rs @@ -99,7 +99,7 @@ impl L1BlockInfo { // Check if the L1 fee scalars are empty. If so, we use the Bedrock cost function. The L1 fee overhead is // only necessary if `empty_scalars` is true, as it was deprecated in Ecotone. - let empty_scalars = l1_blob_base_fee == U256::ZERO + let empty_scalars = l1_blob_base_fee.is_zero() && l1_fee_scalars[BASE_FEE_SCALAR_OFFSET..BLOB_BASE_FEE_SCALAR_OFFSET + 4] == EMPTY_SCALARS; let l1_fee_overhead = empty_scalars