diff --git a/crates/vm/levm/src/errors.rs b/crates/vm/levm/src/errors.rs index 77c5581724c..4604dca55d0 100644 --- a/crates/vm/levm/src/errors.rs +++ b/crates/vm/levm/src/errors.rs @@ -96,8 +96,10 @@ pub enum TxValidationError { priority_fee: U256, max_fee_per_gas: U256, }, - #[error("Intrinsic gas too low")] + #[error("Transaction gas limit lower than the minimum gas cost to execute the transaction")] IntrinsicGasTooLow, + #[error("Transaction gas limit lower than the gas cost floor for calldata tokens")] + IntrinsicGasBelowFloorGasCost, #[error( "Gas allowance exceeded. Block gas limit: {block_gas_limit}, transaction gas limit: {tx_gas_limit}" )] diff --git a/crates/vm/levm/src/hooks/default_hook.rs b/crates/vm/levm/src/hooks/default_hook.rs index 22ce5f7d161..4ed68e1c28b 100644 --- a/crates/vm/levm/src/hooks/default_hook.rs +++ b/crates/vm/levm/src/hooks/default_hook.rs @@ -11,8 +11,6 @@ use crate::{ use bytes::Bytes; use ethrex_common::{Address, U256, types::Fork}; -use std::cmp::max; - pub const MAX_REFUND_QUOTIENT: u64 = 5; pub struct DefaultHook; @@ -248,6 +246,10 @@ pub fn validate_min_gas_limit(vm: &mut VM<'_>) -> Result<(), VMError> { let calldata = vm.current_call_frame.calldata.clone(); let intrinsic_gas: u64 = vm.get_intrinsic_gas()?; + if vm.current_call_frame.gas_limit < intrinsic_gas { + return Err(TxValidationError::IntrinsicGasTooLow.into()); + } + // calldata_cost = tokens_in_calldata * 4 let calldata_cost: u64 = gas_cost::tx_calldata(&calldata)?; @@ -261,9 +263,8 @@ pub fn validate_min_gas_limit(vm: &mut VM<'_>) -> Result<(), VMError> { .checked_add(TX_BASE_COST) .ok_or(InternalError::Overflow)?; - let min_gas_limit = max(intrinsic_gas, floor_cost_by_tokens); - if vm.current_call_frame.gas_limit < min_gas_limit { - return Err(TxValidationError::IntrinsicGasTooLow.into()); + if vm.current_call_frame.gas_limit < floor_cost_by_tokens { + return Err(TxValidationError::IntrinsicGasBelowFloorGasCost.into()); } Ok(()) diff --git a/tooling/ef_tests/blockchain/deserialize.rs b/tooling/ef_tests/blockchain/deserialize.rs index 396dcdcb25e..166adb4e40d 100644 --- a/tooling/ef_tests/blockchain/deserialize.rs +++ b/tooling/ef_tests/blockchain/deserialize.rs @@ -40,7 +40,7 @@ where ) } "TransactionException.INTRINSIC_GAS_TOO_LOW" => { - BlockChainExpectedException::TxtException("Intrinsic gas too low".to_string()) + BlockChainExpectedException::TxtException("Transaction gas limit lower than the minimum gas cost to execute the transaction".to_string()) } "TransactionException.INSUFFICIENT_ACCOUNT_FUNDS" => { BlockChainExpectedException::TxtException( diff --git a/tooling/ef_tests/state/deserialize.rs b/tooling/ef_tests/state/deserialize.rs index 391969072d9..f4772d7fc90 100644 --- a/tooling/ef_tests/state/deserialize.rs +++ b/tooling/ef_tests/state/deserialize.rs @@ -41,6 +41,9 @@ where "TransactionException.INTRINSIC_GAS_TOO_LOW" => { TransactionExpectedException::IntrinsicGasTooLow } + "TransactionException.INTRINSIC_BELOW_FLOOR_GAS_COST" => { + TransactionExpectedException::IntrinsicGasBelowFloorGasCost + } "TransactionException.INSUFFICIENT_ACCOUNT_FUNDS" => { TransactionExpectedException::InsufficientAccountFunds } diff --git a/tooling/ef_tests/state/runner/levm_runner.rs b/tooling/ef_tests/state/runner/levm_runner.rs index ae2e28e5178..e8e5c781a8a 100644 --- a/tooling/ef_tests/state/runner/levm_runner.rs +++ b/tooling/ef_tests/state/runner/levm_runner.rs @@ -309,6 +309,9 @@ fn exception_is_expected( ( TransactionExpectedException::IntrinsicGasTooLow, VMError::TxValidation(TxValidationError::IntrinsicGasTooLow) + ) | ( + TransactionExpectedException::IntrinsicGasBelowFloorGasCost, + VMError::TxValidation(TxValidationError::IntrinsicGasBelowFloorGasCost) ) | ( TransactionExpectedException::InsufficientAccountFunds, VMError::TxValidation(TxValidationError::InsufficientAccountFunds) diff --git a/tooling/ef_tests/state/types.rs b/tooling/ef_tests/state/types.rs index 41408aa3d05..cd7307ef72c 100644 --- a/tooling/ef_tests/state/types.rs +++ b/tooling/ef_tests/state/types.rs @@ -156,6 +156,7 @@ pub enum TransactionExpectedException { Type3TxInvalidBlobVersionedHash, Type4TxContractCreation, IntrinsicGasTooLow, + IntrinsicGasBelowFloorGasCost, InsufficientAccountFunds, SenderNotEoa, PriorityGreaterThanMaxFeePerGas, diff --git a/tooling/ef_tests/state_v2/src/modules/deserialize.rs b/tooling/ef_tests/state_v2/src/modules/deserialize.rs index a00d7bbd651..d8d61457577 100644 --- a/tooling/ef_tests/state_v2/src/modules/deserialize.rs +++ b/tooling/ef_tests/state_v2/src/modules/deserialize.rs @@ -38,6 +38,9 @@ where "TransactionException.INTRINSIC_GAS_TOO_LOW" => { TransactionExpectedException::IntrinsicGasTooLow } + "TransactionException.INTRINSIC_GAS_BELOW_FLOOR_GAS_COST" => { + TransactionExpectedException::IntrinsicGasBelowFloorGasCost + } "TransactionException.INSUFFICIENT_ACCOUNT_FUNDS" => { TransactionExpectedException::InsufficientAccountFunds } diff --git a/tooling/ef_tests/state_v2/src/modules/result_check.rs b/tooling/ef_tests/state_v2/src/modules/result_check.rs index 6cf7a2bcd40..be32ef27def 100644 --- a/tooling/ef_tests/state_v2/src/modules/result_check.rs +++ b/tooling/ef_tests/state_v2/src/modules/result_check.rs @@ -160,6 +160,9 @@ fn exception_matches_expected( ( TransactionExpectedException::IntrinsicGasTooLow, VMError::TxValidation(TxValidationError::IntrinsicGasTooLow) + ) | ( + TransactionExpectedException::IntrinsicGasBelowFloorGasCost, + VMError::TxValidation(TxValidationError::IntrinsicGasBelowFloorGasCost) ) | ( TransactionExpectedException::InsufficientAccountFunds, VMError::TxValidation(TxValidationError::InsufficientAccountFunds) diff --git a/tooling/ef_tests/state_v2/src/modules/types.rs b/tooling/ef_tests/state_v2/src/modules/types.rs index 2c868a3b297..7799e100230 100644 --- a/tooling/ef_tests/state_v2/src/modules/types.rs +++ b/tooling/ef_tests/state_v2/src/modules/types.rs @@ -447,6 +447,7 @@ pub enum TransactionExpectedException { Type3TxInvalidBlobVersionedHash, Type4TxContractCreation, IntrinsicGasTooLow, + IntrinsicGasBelowFloorGasCost, InsufficientAccountFunds, SenderNotEoa, PriorityGreaterThanMaxFeePerGas,