diff --git a/crates/blockifier/src/fee/fee_checks.rs b/crates/blockifier/src/fee/fee_checks.rs index c337bbcf91f..c1952d2b022 100644 --- a/crates/blockifier/src/fee/fee_checks.rs +++ b/crates/blockifier/src/fee/fee_checks.rs @@ -186,7 +186,7 @@ impl FeeCheckReport { ) -> TransactionExecutionResult<()> { let TransactionReceipt { fee, .. } = *tx_receipt; let (balance_low, balance_high, can_pay) = - get_balance_and_if_covers_fee(state, tx_context, fee)?; + get_balance_and_if_covers_fee(state, tx_context, fee).map_err(Box::new)?; if can_pay { return Ok(()); } diff --git a/crates/blockifier/src/transaction/account_transaction.rs b/crates/blockifier/src/transaction/account_transaction.rs index cea8c705b72..522f51f6c00 100644 --- a/crates/blockifier/src/transaction/account_transaction.rs +++ b/crates/blockifier/src/transaction/account_transaction.rs @@ -483,7 +483,7 @@ impl AccountTransaction { Ok(fee_transfer_call .execute(state, &mut context, &mut remaining_gas_for_fee_transfer) - .map_err(TransactionFeeError::ExecuteFeeTransferError)?) + .map_err(|error| Box::new(TransactionFeeError::ExecuteFeeTransferError(error)))?) } /// Handles fee transfer in concurrent execution. @@ -799,7 +799,7 @@ impl ExecutableTransaction for AccountTransaction { } // Nonce and fee check should be done before running user code. - self.perform_pre_validation_stage(state, &tx_context)?; + self.perform_pre_validation_stage(state, &tx_context).map_err(Box::new)?; // Run validation and execution. let initial_gas = tx_context.initial_sierra_gas(); diff --git a/crates/blockifier/src/transaction/account_transactions_test.rs b/crates/blockifier/src/transaction/account_transactions_test.rs index 540b6325e12..c34fdccb4e4 100644 --- a/crates/blockifier/src/transaction/account_transactions_test.rs +++ b/crates/blockifier/src/transaction/account_transactions_test.rs @@ -267,9 +267,11 @@ fn test_fee_enforcement( if enforce_fee { assert_matches!( result, - Err(TransactionExecutionError::TransactionPreValidationError( + Err(TransactionExecutionError::TransactionPreValidationError(boxed_error)) + if matches!( + *boxed_error, TransactionPreValidationError::TransactionFeeError(_) - )) + ) ); } else { assert!(result.is_ok()); diff --git a/crates/blockifier/src/transaction/errors.rs b/crates/blockifier/src/transaction/errors.rs index 1d17f9e6e50..d2fe3153265 100644 --- a/crates/blockifier/src/transaction/errors.rs +++ b/crates/blockifier/src/transaction/errors.rs @@ -105,9 +105,9 @@ pub enum TransactionExecutionError { #[error(transparent)] StateError(#[from] StateError), #[error(transparent)] - TransactionFeeError(#[from] TransactionFeeError), + TransactionFeeError(#[from] Box), #[error(transparent)] - TransactionPreValidationError(#[from] TransactionPreValidationError), + TransactionPreValidationError(#[from] Box), #[error(transparent)] TryFromIntError(#[from] std::num::TryFromIntError), #[error( diff --git a/crates/blockifier/src/transaction/execution_flavors_test.rs b/crates/blockifier/src/transaction/execution_flavors_test.rs index db24eb6d26a..929ce12ce06 100644 --- a/crates/blockifier/src/transaction/execution_flavors_test.rs +++ b/crates/blockifier/src/transaction/execution_flavors_test.rs @@ -229,13 +229,15 @@ fn test_invalid_nonce_pre_validate( let result = account_tx.execute(&mut state, &block_context); assert_matches!( result.unwrap_err(), - TransactionExecutionError::TransactionPreValidationError( + TransactionExecutionError::TransactionPreValidationError(boxed_error) + if matches!( + *boxed_error, TransactionPreValidationError::InvalidNonce { address, account_nonce: expected_nonce, incoming_tx_nonce } + if (address, expected_nonce, incoming_tx_nonce) == + (account_address, account_nonce, invalid_nonce) ) - if (address, expected_nonce, incoming_tx_nonce) == - (account_address, account_nonce, invalid_nonce) ); } // Pre-validation scenarios. @@ -277,7 +279,9 @@ fn test_simulate_validate_pre_validate_with_charge_fee( if is_deprecated { assert_matches!( err, - TransactionExecutionError::TransactionPreValidationError( + TransactionExecutionError::TransactionPreValidationError(boxed_error) + if matches!( + *boxed_error, TransactionPreValidationError::TransactionFeeError( TransactionFeeError::MaxFeeTooLow { .. } ) @@ -286,15 +290,17 @@ fn test_simulate_validate_pre_validate_with_charge_fee( } else { assert_matches!( err, - TransactionExecutionError::TransactionPreValidationError( + TransactionExecutionError::TransactionPreValidationError(boxed_error) + => assert_matches!( + *boxed_error, TransactionPreValidationError::TransactionFeeError( TransactionFeeError::InsufficientResourceBounds { errors } ) - ) => - assert_matches!( - errors[0], - ResourceBoundsError::MaxGasAmountTooLow { resource , .. } - if resource == Resource::L1Gas + => assert_matches!( + errors[0], + ResourceBoundsError::MaxGasAmountTooLow { resource , .. } + if resource == Resource::L1Gas + ) ) ); } @@ -327,7 +333,9 @@ fn test_simulate_validate_pre_validate_with_charge_fee( if is_deprecated { assert_matches!( result.unwrap_err(), - TransactionExecutionError::TransactionPreValidationError( + TransactionExecutionError::TransactionPreValidationError(boxed_error) + if matches!( + *boxed_error, TransactionPreValidationError::TransactionFeeError( TransactionFeeError::MaxFeeExceedsBalance { .. } ) @@ -336,12 +344,14 @@ fn test_simulate_validate_pre_validate_with_charge_fee( } else { assert_matches!( result.unwrap_err(), - TransactionExecutionError::TransactionPreValidationError( + TransactionExecutionError::TransactionPreValidationError(boxed_error) + if matches!( + *boxed_error, TransactionPreValidationError::TransactionFeeError( TransactionFeeError::GasBoundsExceedBalance {resource, .. } ) + if resource == Resource::L1Gas ) - if resource == Resource::L1Gas ); } @@ -367,15 +377,17 @@ fn test_simulate_validate_pre_validate_with_charge_fee( nonce_manager.rollback(account_address); assert_matches!( err, - TransactionExecutionError::TransactionPreValidationError( + TransactionExecutionError::TransactionPreValidationError(boxed_error) + => assert_matches!( + *boxed_error, TransactionPreValidationError::TransactionFeeError( TransactionFeeError::InsufficientResourceBounds{ errors } ) - ) => - assert_matches!( - errors[0], - ResourceBoundsError::MaxGasPriceTooLow { resource, .. } - if resource == Resource::L1Gas + => assert_matches!( + errors[0], + ResourceBoundsError::MaxGasPriceTooLow { resource, .. } + if resource == Resource::L1Gas + ) ) ); } diff --git a/crates/blockifier/src/transaction/l1_handler_transaction.rs b/crates/blockifier/src/transaction/l1_handler_transaction.rs index 373bdf5f518..0085b3f3b6c 100644 --- a/crates/blockifier/src/transaction/l1_handler_transaction.rs +++ b/crates/blockifier/src/transaction/l1_handler_transaction.rs @@ -98,12 +98,12 @@ impl ExecutableTransaction for L1HandlerTransaction { // For now, assert only that any amount of fee was paid. // The error message still indicates the required fee. if paid_fee == Fee(0) { - return Err(TransactionExecutionError::TransactionFeeError( + return Err(TransactionExecutionError::TransactionFeeError(Box::new( TransactionFeeError::InsufficientFee { paid_fee, actual_fee: receipt.fee, }, - )); + ))); } Ok(l1_handler_tx_execution_info(execute_call_info, receipt, None)) diff --git a/crates/blockifier/src/transaction/transactions_test.rs b/crates/blockifier/src/transaction/transactions_test.rs index fc44906e60f..c9dc268e056 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -1017,37 +1017,45 @@ fn assert_resource_bounds_exceed_balance_failure( TransactionInfo::Deprecated(context) => { assert_matches!( tx_error, - TransactionExecutionError::TransactionPreValidationError( + TransactionExecutionError::TransactionPreValidationError(boxed_error) + if matches!( + *boxed_error, TransactionPreValidationError::TransactionFeeError( - TransactionFeeError::MaxFeeExceedsBalance{ max_fee, .. })) - if max_fee == context.max_fee + TransactionFeeError::MaxFeeExceedsBalance{ max_fee, .. } + ) + if max_fee == context.max_fee + ) ); } TransactionInfo::Current(context) => match context.resource_bounds { ValidResourceBounds::L1Gas(l1_bounds) => assert_matches!( tx_error, - TransactionExecutionError::TransactionPreValidationError( + TransactionExecutionError::TransactionPreValidationError(boxed_error) + if matches!( + *boxed_error, TransactionPreValidationError::TransactionFeeError( TransactionFeeError::GasBoundsExceedBalance{ resource, max_amount, max_price, .. } ) + if max_amount == l1_bounds.max_amount + && max_price == l1_bounds.max_price_per_unit + && resource == L1Gas ) - if max_amount == l1_bounds.max_amount - && max_price == l1_bounds.max_price_per_unit - && resource == L1Gas ), ValidResourceBounds::AllResources(actual_bounds) => { assert_matches!( tx_error, - TransactionExecutionError::TransactionPreValidationError( + TransactionExecutionError::TransactionPreValidationError(boxed_error) + if matches!( + *boxed_error, TransactionPreValidationError::TransactionFeeError( TransactionFeeError::ResourcesBoundsExceedBalance { bounds: error_bounds, .. } ) + if actual_bounds == error_bounds ) - if actual_bounds == error_bounds ); } }, @@ -1268,12 +1276,15 @@ fn test_insufficient_new_resource_bounds_pre_validation( let next_nonce = match valid_resources_tx { Ok(_) => 1, Err(err) => match err { - TransactionExecutionError::TransactionPreValidationError( - TransactionPreValidationError::TransactionFeeError( - TransactionFeeError::InsufficientResourceBounds { .. }, - ), - ) => panic!("Transaction failed with expected minimal resource bounds."), - // Ignore failures other than those above (e.g., post-validation errors). + TransactionExecutionError::TransactionPreValidationError(boxed_error) => { + match *boxed_error { + TransactionPreValidationError::TransactionFeeError( + TransactionFeeError::InsufficientResourceBounds { .. }, + ) => panic!("Transaction failed with expected minimal resource bounds."), + // Ignore failures other than those above (e.g., post-validation errors). + _ => 0, + } + } _ => 0, }, }; @@ -1301,17 +1312,17 @@ fn test_insufficient_new_resource_bounds_pre_validation( let execution_error = invalid_v3_tx.execute(&mut state, &block_context).unwrap_err(); assert_matches!( execution_error, - TransactionExecutionError::TransactionPreValidationError( + TransactionExecutionError::TransactionPreValidationError(boxed_error) + => assert_matches!( + *boxed_error, TransactionPreValidationError::TransactionFeeError( TransactionFeeError::InsufficientResourceBounds{errors} - ) - ) => { - assert_matches!( + ) => assert_matches!( errors[0], ResourceBoundsError::MaxGasAmountTooLow{resource, ..} if resource == insufficient_resource ) - } + ) ); } @@ -1332,15 +1343,16 @@ fn test_insufficient_new_resource_bounds_pre_validation( let execution_error = invalid_v3_tx.execute(&mut state, &block_context).unwrap_err(); assert_matches!( execution_error, - TransactionExecutionError::TransactionPreValidationError( + TransactionExecutionError::TransactionPreValidationError(boxed_error) + => assert_matches!( + *boxed_error, TransactionPreValidationError::TransactionFeeError( TransactionFeeError::InsufficientResourceBounds{ errors } + ) => assert_matches!( + errors[0], + ResourceBoundsError::MaxGasPriceTooLow{resource,..} + if resource == insufficient_resource ) - ) => - assert_matches!( - errors[0], - ResourceBoundsError::MaxGasPriceTooLow{resource,..} - if resource == insufficient_resource ) ); } @@ -1359,33 +1371,35 @@ fn test_insufficient_new_resource_bounds_pre_validation( let execution_error = invalid_v3_tx.execute(&mut state, &block_context).unwrap_err(); assert_matches!( execution_error, - TransactionExecutionError::TransactionPreValidationError( + TransactionExecutionError::TransactionPreValidationError(boxed_error) + => assert_matches!( + *boxed_error, TransactionPreValidationError::TransactionFeeError( TransactionFeeError::InsufficientResourceBounds{ errors } - ) - ) => { - assert_eq!(errors.len(), 4); - assert_matches!( - errors[0], - ResourceBoundsError::MaxGasPriceTooLow{resource,..} - if resource == L1Gas - ); - assert_matches!( - errors[1], - ResourceBoundsError::MaxGasPriceTooLow{resource,..} - if resource == L1DataGas - ); - assert_matches!( - errors[2], - ResourceBoundsError::MaxGasAmountTooLow{resource,..} - if resource == L2Gas - ); - assert_matches!( - errors[3], - ResourceBoundsError::MaxGasPriceTooLow{resource,..} - if resource == L2Gas - ); - } + ) => { + assert_eq!(errors.len(), 4); + assert_matches!( + errors[0], + ResourceBoundsError::MaxGasPriceTooLow{resource,..} + if resource == L1Gas + ); + assert_matches!( + errors[1], + ResourceBoundsError::MaxGasPriceTooLow{resource,..} + if resource == L1DataGas + ); + assert_matches!( + errors[2], + ResourceBoundsError::MaxGasAmountTooLow{resource,..} + if resource == L2Gas + ); + assert_matches!( + errors[3], + ResourceBoundsError::MaxGasPriceTooLow{resource,..} + if resource == L2Gas + ); + } + ) ); } @@ -1429,10 +1443,14 @@ fn test_insufficient_deprecated_resource_bounds_pre_validation( // Test error. assert_matches!( execution_error, - TransactionExecutionError::TransactionPreValidationError( + TransactionExecutionError::TransactionPreValidationError(boxed_error) + if matches!( + *boxed_error, TransactionPreValidationError::TransactionFeeError( - TransactionFeeError::MaxFeeTooLow { min_fee, max_fee })) - if max_fee == invalid_max_fee && min_fee == minimal_fee + TransactionFeeError::MaxFeeTooLow { min_fee, max_fee } + ) + if max_fee == invalid_max_fee && min_fee == minimal_fee + ) ); // Test V3 transaction. @@ -1448,19 +1466,20 @@ fn test_insufficient_deprecated_resource_bounds_pre_validation( let execution_error = invalid_v3_tx.execute(&mut state, &block_context).unwrap_err(); assert_matches!( execution_error, - TransactionExecutionError::TransactionPreValidationError( + TransactionExecutionError::TransactionPreValidationError(boxed_error) + => assert_matches!( + *boxed_error, TransactionPreValidationError::TransactionFeeError( TransactionFeeError::InsufficientResourceBounds{ errors } + ) => assert_matches!( + errors[0], + ResourceBoundsError::MaxGasAmountTooLow{ + resource, + max_gas_amount, + minimal_gas_amount} + if max_gas_amount == insufficient_max_l1_gas_amount && + minimal_gas_amount == minimal_l1_gas && resource == L1Gas ) - ) => - assert_matches!( - errors[0], - ResourceBoundsError::MaxGasAmountTooLow{ - resource, - max_gas_amount, - minimal_gas_amount} - if max_gas_amount == insufficient_max_l1_gas_amount && - minimal_gas_amount == minimal_l1_gas && resource == L1Gas ) ); @@ -1473,18 +1492,18 @@ fn test_insufficient_deprecated_resource_bounds_pre_validation( let execution_error = invalid_v3_tx.execute(&mut state, &block_context).unwrap_err(); assert_matches!( execution_error, - TransactionExecutionError::TransactionPreValidationError( + TransactionExecutionError::TransactionPreValidationError(boxed_error) + => assert_matches!( + *boxed_error, TransactionPreValidationError::TransactionFeeError( TransactionFeeError::InsufficientResourceBounds{errors,..} - ) - ) => { - assert_matches!( + ) => assert_matches!( errors[0], ResourceBoundsError::MaxGasPriceTooLow{ resource: L1Gas ,max_gas_price: max_l1_gas_price, actual_gas_price: actual_l1_gas_price } if max_l1_gas_price == insufficient_max_l1_gas_price && actual_l1_gas_price == actual_strk_l1_gas_price.into() ) - } + ) ); } @@ -2817,10 +2836,12 @@ fn test_l1_handler(#[values(false, true)] use_kzg_da: bool) { assert_matches!( error, - TransactionExecutionError::TransactionFeeError( + TransactionExecutionError::TransactionFeeError(boxed_fee_error) + if matches!( + *boxed_fee_error, TransactionFeeError::InsufficientFee { paid_fee, actual_fee } + if paid_fee == Fee(0) && actual_fee == expected_actual_fee ) - if paid_fee == Fee(0) && actual_fee == expected_actual_fee ); } diff --git a/crates/native_blockifier/src/py_testing_wrappers.rs b/crates/native_blockifier/src/py_testing_wrappers.rs index f0d9f607e0d..5eed69a77b1 100644 --- a/crates/native_blockifier/src/py_testing_wrappers.rs +++ b/crates/native_blockifier/src/py_testing_wrappers.rs @@ -8,9 +8,9 @@ use crate::py_objects::PyExecutionResources; #[pyfunction] pub fn raise_error_for_testing() -> NativeBlockifierResult<()> { - Err(TransactionExecutionError::TransactionFeeError( + Err(TransactionExecutionError::TransactionFeeError(Box::new( TransactionFeeError::CairoResourcesNotContainedInFeeCosts, - ) + )) .into()) }