diff --git a/crates/blockifier/src/fee/actual_cost.rs b/crates/blockifier/src/fee/actual_cost.rs index cb99c9559f..c17c1fe952 100644 --- a/crates/blockifier/src/fee/actual_cost.rs +++ b/crates/blockifier/src/fee/actual_cost.rs @@ -7,19 +7,21 @@ use crate::abi::constants as abi_constants; use crate::context::TransactionContext; use crate::execution::call_info::CallInfo; use crate::execution::entry_point::ExecutionResources; -use crate::fee::gas_usage::calculate_tx_gas_usage_vector; +use crate::fee::gas_usage::{calculate_tx_gas_usage_vector, get_da_gas_cost}; use crate::state::cached_state::{CachedState, StateChanges}; use crate::state::state_api::{StateReader, StateResult}; use crate::transaction::objects::{ - HasRelatedFeeType, ResourcesMapping, TransactionExecutionResult, + GasVector, HasRelatedFeeType, ResourcesMapping, TransactionExecutionResult, }; use crate::transaction::transaction_types::TransactionType; use crate::transaction::transaction_utils::calculate_tx_resources; // TODO(Gilad): Use everywhere instead of passing the `actual_{fee,resources}` tuple, which often // get passed around together. +#[derive(Default)] pub struct ActualCost { pub actual_fee: Fee, + pub da_gas: GasVector, pub actual_resources: ResourcesMapping, } @@ -126,11 +128,16 @@ impl<'a> ActualCostBuilder<'a> { // Private methods. + fn use_kzg_da(&self) -> bool { + self.tx_context.block_context.block_info.use_kzg_da + } + // Construct the actual cost object using all fields that were set in the builder. fn calculate_actual_fee_and_resources( self, execution_resources: &ExecutionResources, ) -> TransactionExecutionResult { + let use_kzg_da = self.use_kzg_da(); let state_changes_count = self.state_changes.count_for_fee_charge( self.sender_address, self.tx_context @@ -138,6 +145,7 @@ impl<'a> ActualCostBuilder<'a> { .chain_info .fee_token_address(&self.tx_context.tx_info.fee_type()), ); + let da_gas = get_da_gas_cost(state_changes_count, use_kzg_da); let non_optional_call_infos = self.validate_call_info.into_iter().chain(self.execute_call_info); // Gas usage for SHARP costs and Starknet L1-L2 messages. Includes gas usage for data @@ -146,7 +154,7 @@ impl<'a> ActualCostBuilder<'a> { non_optional_call_infos, state_changes_count, self.l1_payload_size, - self.tx_context.block_context.block_info.use_kzg_da, + use_kzg_da, )?; let mut actual_resources = calculate_tx_resources( @@ -171,6 +179,6 @@ impl<'a> ActualCostBuilder<'a> { Fee(0) }; - Ok(ActualCost { actual_fee, actual_resources }) + Ok(ActualCost { actual_fee, da_gas, actual_resources }) } } diff --git a/crates/blockifier/src/fee/fee_checks.rs b/crates/blockifier/src/fee/fee_checks.rs index 6883cb60d1..a67aca52c3 100644 --- a/crates/blockifier/src/fee/fee_checks.rs +++ b/crates/blockifier/src/fee/fee_checks.rs @@ -76,7 +76,7 @@ impl FeeCheckReport { &tx_context.block_context.block_info, GasVector { l1_gas: info.l1_resource_bounds()?.max_amount.into(), - blob_gas: 0, + l1_data_gas: 0, }, &FeeType::Strk, ), @@ -93,7 +93,7 @@ impl FeeCheckReport { tx_context: &TransactionContext, actual_cost: &ActualCost, ) -> TransactionExecutionResult<()> { - let ActualCost { actual_fee, actual_resources } = actual_cost; + let ActualCost { actual_fee, actual_resources, .. } = actual_cost; let TransactionContext { tx_info, block_context } = tx_context; // First, compare the actual resources used against the upper bound(s) defined by the diff --git a/crates/blockifier/src/fee/fee_test.rs b/crates/blockifier/src/fee/fee_test.rs index 50f477d188..bbf0c7e34a 100644 --- a/crates/blockifier/src/fee/fee_test.rs +++ b/crates/blockifier/src/fee/fee_test.rs @@ -42,7 +42,7 @@ fn test_calculate_l1_gas_by_vm_usage() { // Verify calculation - in our case, n_steps is the heaviest resource. let l1_gas_by_vm_usage = vm_resource_usage.0.get(constants::N_STEPS_RESOURCE).unwrap(); assert_eq!( - GasVector { l1_gas: *l1_gas_by_vm_usage as u128, blob_gas: 0 }, + GasVector { l1_gas: *l1_gas_by_vm_usage as u128, l1_data_gas: 0 }, calculate_l1_gas_by_vm_usage(&versioned_constants, &vm_resource_usage).unwrap() ); @@ -89,6 +89,7 @@ fn test_discounted_gas_overdraft( (constants::L1_GAS_USAGE.to_string(), l1_gas_used), (constants::BLOB_GAS_USAGE.to_string(), l1_data_gas_used), ])), + ..Default::default() }; let charge_fee = true; let report = PostExecutionReport::new( diff --git a/crates/blockifier/src/fee/fee_utils.rs b/crates/blockifier/src/fee/fee_utils.rs index b04da8aedd..df42bf0460 100644 --- a/crates/blockifier/src/fee/fee_utils.rs +++ b/crates/blockifier/src/fee/fee_utils.rs @@ -58,7 +58,7 @@ pub fn calculate_l1_gas_by_vm_usage( .fold(f64::NAN, f64::max); // TODO(Dori, 1/5/2024): Check this conversion. - Ok(GasVector { l1_gas: vm_l1_gas_usage.ceil() as u128, blob_gas: 0 }) + Ok(GasVector { l1_gas: vm_l1_gas_usage.ceil() as u128, l1_data_gas: 0 }) } /// Computes and returns the total L1 gas consumption. @@ -75,7 +75,7 @@ pub fn calculate_tx_gas_vector( Ok(GasVector { l1_gas: u128_from_usize(l1_gas_usage) .expect("Conversion from usize to u128 should not fail."), - blob_gas: u128_from_usize(l1_blob_gas_usage) + l1_data_gas: u128_from_usize(l1_blob_gas_usage) .expect("Conversion from usize to u128 should not fail."), } + vm_usage_gas_vector) } diff --git a/crates/blockifier/src/fee/gas_usage.rs b/crates/blockifier/src/fee/gas_usage.rs index 8535f688da..c30a63af0c 100644 --- a/crates/blockifier/src/fee/gas_usage.rs +++ b/crates/blockifier/src/fee/gas_usage.rs @@ -1,10 +1,10 @@ use std::collections::HashMap; -use super::fee_utils::calculate_tx_gas_vector; use crate::abi::constants; use crate::context::{BlockContext, TransactionContext}; use crate::execution::call_info::{CallInfo, MessageL1CostInfo}; use crate::fee::eth_gas_constants; +use crate::fee::fee_utils::calculate_tx_gas_vector; use crate::state::cached_state::StateChangesCount; use crate::transaction::account_transaction::AccountTransaction; use crate::transaction::objects::{ @@ -56,7 +56,7 @@ pub fn calculate_messages_gas_vector<'a>( + n_l1_to_l2_messages * eth_gas_constants::GAS_PER_COUNTER_DECREASE, ) .expect("Could not convert starknet gas usage from usize to u128."), - blob_gas: 0, + l1_data_gas: 0, } + get_consumed_message_to_l2_emissions_cost(l1_handler_payload_size) + get_log_message_to_l1_emissions_cost(&l2_to_l1_payload_lengths); @@ -65,7 +65,7 @@ pub fn calculate_messages_gas_vector<'a>( message_segment_length * eth_gas_constants::SHARP_GAS_PER_MEMORY_WORD, ) .expect("Could not convert sharp gas usage from usize to u128."), - blob_gas: 0, + l1_data_gas: 0, }; Ok(starknet_gas_usage + sharp_gas_usage) @@ -129,7 +129,7 @@ pub fn get_da_gas_cost(state_changes_count: StateChangesCount, use_kzg_da: bool) (u128_from_usize(gas).expect("Failed to convert L1 gas usage from usize to u128."), 0) }; - GasVector { l1_gas, blob_gas } + GasVector { l1_gas, l1_data_gas: blob_gas } } /// Returns the number of felts added to the output messages segment as a result of adding @@ -164,7 +164,7 @@ pub fn get_consumed_message_to_l2_emissions_cost( ) -> GasVector { match l1_handler_payload_size { // The corresponding transaction is not an L1 handler., - None => GasVector { l1_gas: 0, blob_gas: 0 }, + None => GasVector { l1_gas: 0, l1_data_gas: 0 }, Some(l1_handler_payload_size) => { get_event_emission_cost( constants::CONSUMED_MSG_TO_L2_N_TOPICS, @@ -197,7 +197,7 @@ fn get_event_emission_cost(n_topics: usize, data_length: usize) -> GasVector { + data_length * eth_gas_constants::GAS_PER_LOG_DATA_WORD, ) .expect("Cannot convert event emission gas from usize to u128."), - blob_gas: 0, + l1_data_gas: 0, } } @@ -234,7 +234,7 @@ pub fn estimate_minimal_gas_vector( n_modified_contracts: 1, }, }; - let GasVector { l1_gas: gas_cost, blob_gas: blob_gas_cost } = + let GasVector { l1_gas: gas_cost, l1_data_gas: blob_gas_cost } = get_da_gas_cost(state_changes_by_account_transaction, block_info.use_kzg_da); let resources = ResourcesMapping(HashMap::from([ @@ -265,7 +265,7 @@ pub fn compute_discounted_gas_from_gas_vector( tx_context: &TransactionContext, ) -> u128 { let gas_prices = &tx_context.block_context.block_info.gas_prices; - let GasVector { l1_gas: gas_usage, blob_gas: blob_gas_usage } = gas_usage_vector; + let GasVector { l1_gas: gas_usage, l1_data_gas: blob_gas_usage } = gas_usage_vector; let fee_type = tx_context.tx_info.fee_type(); let gas_price = gas_prices.get_gas_price_by_fee_type(&fee_type); let data_gas_price = gas_prices.get_data_gas_price_by_fee_type(&fee_type); diff --git a/crates/blockifier/src/fee/gas_usage_test.rs b/crates/blockifier/src/fee/gas_usage_test.rs index 445a022db3..478b6cb3b8 100644 --- a/crates/blockifier/src/fee/gas_usage_test.rs +++ b/crates/blockifier/src/fee/gas_usage_test.rs @@ -54,7 +54,7 @@ fn test_get_da_gas_cost_basic(#[case] state_changes_count: StateChangesCount) { let computed_gas_vector = get_da_gas_cost(state_changes_count, true); assert_eq!( - GasVector { l1_gas: 0, blob_gas: u128_from_usize(manual_blob_gas_usage).unwrap() }, + GasVector { l1_gas: 0, l1_data_gas: u128_from_usize(manual_blob_gas_usage).unwrap() }, computed_gas_vector ); } @@ -80,7 +80,7 @@ fn test_calculate_tx_gas_usage_basic(#[values(false, true)] use_kzg_da: bool) { use_kzg_da, ) .unwrap(); - assert_eq!(empty_tx_gas_usage_vector, GasVector { l1_gas: 0, blob_gas: 0 }); + assert_eq!(empty_tx_gas_usage_vector, GasVector { l1_gas: 0, l1_data_gas: 0 }); // DeployAccount. @@ -128,7 +128,7 @@ fn test_calculate_tx_gas_usage_basic(#[values(false, true)] use_kzg_da: bool) { message_segment_length * eth_gas_constants::SHARP_GAS_PER_MEMORY_WORD; let manual_gas_computation = GasVector { l1_gas: u128_from_usize(manual_starknet_gas_usage + manual_sharp_gas_usage).unwrap(), - blob_gas: 0, + l1_data_gas: 0, }; assert_eq!(l1_handler_gas_usage_vector, manual_gas_computation); @@ -190,10 +190,10 @@ fn test_calculate_tx_gas_usage_basic(#[values(false, true)] use_kzg_da: bool) { + usize_from_u128(get_da_gas_cost(l2_to_l1_state_changes_count, use_kzg_da).l1_gas) .unwrap(); let manual_sharp_blob_gas_usage = - get_da_gas_cost(l2_to_l1_state_changes_count, use_kzg_da).blob_gas; + get_da_gas_cost(l2_to_l1_state_changes_count, use_kzg_da).l1_data_gas; let manual_gas_computation = GasVector { l1_gas: u128_from_usize(manual_starknet_gas_usage + manual_sharp_gas_usage).unwrap(), - blob_gas: manual_sharp_blob_gas_usage, + l1_data_gas: manual_sharp_blob_gas_usage, }; assert_eq!(l2_to_l1_messages_gas_usage_vector, manual_gas_computation); @@ -253,7 +253,7 @@ fn test_calculate_tx_gas_usage_basic(#[values(false, true)] use_kzg_da: bool) { // the combined calculation got it once. + u128_from_usize(fee_balance_discount).unwrap(), // Expected blob gas usage is from data availability only. - blob_gas: get_da_gas_cost(combined_state_changes_count, use_kzg_da).blob_gas, + l1_data_gas: get_da_gas_cost(combined_state_changes_count, use_kzg_da).l1_data_gas, }; assert_eq!(expected_gas_vector, gas_usage_vector); diff --git a/crates/blockifier/src/test_utils/deploy_account.rs b/crates/blockifier/src/test_utils/deploy_account.rs index e1a4fd12c5..4c42170aee 100644 --- a/crates/blockifier/src/test_utils/deploy_account.rs +++ b/crates/blockifier/src/test_utils/deploy_account.rs @@ -6,8 +6,7 @@ use starknet_api::transaction::{ TransactionVersion, }; -use super::default_testing_resource_bounds; -use crate::test_utils::NonceManager; +use crate::test_utils::{default_testing_resource_bounds, NonceManager}; use crate::transaction::transactions::DeployAccountTransaction; #[derive(Clone)] diff --git a/crates/blockifier/src/test_utils/struct_impls.rs b/crates/blockifier/src/test_utils/struct_impls.rs index c3e4cf0510..8d90b65803 100644 --- a/crates/blockifier/src/test_utils/struct_impls.rs +++ b/crates/blockifier/src/test_utils/struct_impls.rs @@ -5,11 +5,6 @@ use starknet_api::core::{ChainId, ContractAddress, PatriciaKey}; use starknet_api::hash::StarkHash; use starknet_api::{contract_address, patricia_key}; -use super::{ - CHAIN_ID_NAME, CURRENT_BLOCK_NUMBER, CURRENT_BLOCK_TIMESTAMP, DEFAULT_ETH_L1_DATA_GAS_PRICE, - DEFAULT_ETH_L1_GAS_PRICE, DEFAULT_STRK_L1_DATA_GAS_PRICE, DEFAULT_STRK_L1_GAS_PRICE, - TEST_ERC20_CONTRACT_ADDRESS, TEST_ERC20_CONTRACT_ADDRESS2, TEST_SEQUENCER_ADDRESS, -}; use crate::block::{BlockInfo, GasPrices}; use crate::context::{BlockContext, ChainInfo, FeeTokenAddresses, TransactionContext}; use crate::execution::call_info::{CallExecution, CallInfo, Retdata}; @@ -18,7 +13,12 @@ use crate::execution::entry_point::{ CallEntryPoint, EntryPointExecutionContext, EntryPointExecutionResult, ExecutionResources, }; use crate::state::state_api::State; -use crate::test_utils::get_raw_contract_class; +use crate::test_utils::{ + get_raw_contract_class, CHAIN_ID_NAME, CURRENT_BLOCK_NUMBER, CURRENT_BLOCK_TIMESTAMP, + DEFAULT_ETH_L1_DATA_GAS_PRICE, DEFAULT_ETH_L1_GAS_PRICE, DEFAULT_STRK_L1_DATA_GAS_PRICE, + DEFAULT_STRK_L1_GAS_PRICE, TEST_ERC20_CONTRACT_ADDRESS, TEST_ERC20_CONTRACT_ADDRESS2, + TEST_SEQUENCER_ADDRESS, +}; use crate::transaction::objects::{DeprecatedTransactionInfo, TransactionInfo}; use crate::versioned_constants::VersionedConstants; diff --git a/crates/blockifier/src/transaction/account_transaction.rs b/crates/blockifier/src/transaction/account_transaction.rs index b57f9fb3ea..82706035ee 100644 --- a/crates/blockifier/src/transaction/account_transaction.rs +++ b/crates/blockifier/src/transaction/account_transaction.rs @@ -487,7 +487,7 @@ impl AccountTransaction { post_execution_error.to_string(), ActualCost { actual_fee: post_execution_report.recommended_fee(), - actual_resources: revert_cost.actual_resources, + ..revert_cost }, )) } @@ -512,7 +512,7 @@ impl AccountTransaction { execution_context.error_trace(), ActualCost { actual_fee: post_execution_report.recommended_fee(), - actual_resources: revert_cost.actual_resources, + ..revert_cost }, )) } @@ -582,7 +582,12 @@ impl ExecutableTransaction for AccountTransaction { validate_call_info, execute_call_info, revert_error, - final_cost: ActualCost { actual_fee: final_fee, actual_resources: final_resources }, + final_cost: + ActualCost { + actual_fee: final_fee, + da_gas: final_da_gas, + actual_resources: final_resources, + }, } = self.run_or_revert( state, &mut remaining_gas, @@ -598,6 +603,7 @@ impl ExecutableTransaction for AccountTransaction { execute_call_info, fee_transfer_call_info, actual_fee: final_fee, + da_gas: final_da_gas, actual_resources: final_resources, revert_error, }; diff --git a/crates/blockifier/src/transaction/execution_flavors_test.rs b/crates/blockifier/src/transaction/execution_flavors_test.rs index 83f5b029cf..2d8b532fd0 100644 --- a/crates/blockifier/src/transaction/execution_flavors_test.rs +++ b/crates/blockifier/src/transaction/execution_flavors_test.rs @@ -88,7 +88,7 @@ fn gas_and_fee(base_gas: u64, validate_mode: bool, fee_type: &FeeType) -> (u64, gas, get_fee_by_gas_vector( &BlockContext::create_for_account_testing().block_info, - GasVector { l1_gas: gas.into(), blob_gas: 0 }, + GasVector { l1_gas: gas.into(), l1_data_gas: 0 }, fee_type, ), ) @@ -489,7 +489,7 @@ fn test_simulate_validate_charge_fee_mid_execution( let block_limit_gas = invoke_tx_max_n_steps_as_u64 + 1652; let block_limit_fee = get_fee_by_gas_vector( &block_context.block_info, - GasVector { l1_gas: block_limit_gas.into(), blob_gas: 0 }, + GasVector { l1_gas: block_limit_gas.into(), l1_data_gas: 0 }, &fee_type, ); let tx_execution_info = account_invoke_tx(invoke_tx_args! { diff --git a/crates/blockifier/src/transaction/objects.rs b/crates/blockifier/src/transaction/objects.rs index c8eb3f3afb..12f119a76d 100644 --- a/crates/blockifier/src/transaction/objects.rs +++ b/crates/blockifier/src/transaction/objects.rs @@ -124,10 +124,10 @@ pub struct DeprecatedTransactionInfo { pub max_fee: Fee, } -#[derive(derive_more::Add, derive_more::Sum, Clone, Debug, Default, Eq, PartialEq)] +#[derive(derive_more::Add, derive_more::Sum, Clone, Debug, Default, Eq, PartialEq, Serialize)] pub struct GasVector { pub l1_gas: u128, - pub blob_gas: u128, + pub l1_data_gas: u128, } impl GasVector { @@ -141,10 +141,10 @@ impl GasVector { ); u128::MAX }); - let l1_data_gas_cost = self.blob_gas.checked_mul(blob_gas_price).unwrap_or_else(|| { + let l1_data_gas_cost = self.l1_data_gas.checked_mul(blob_gas_price).unwrap_or_else(|| { log::warn!( "L1 blob gas cost overflowed: multiplication of {} by {} resulted in overflow.", - self.blob_gas, + self.l1_data_gas, blob_gas_price ); u128::MAX @@ -182,6 +182,8 @@ pub struct TransactionExecutionInfo { pub fee_transfer_call_info: Option, /// The actual fee that was charged (in Wei). pub actual_fee: Fee, + /// Actual gas consumption the transaction is charged for data availability. + pub da_gas: GasVector, /// Actual execution resources the transaction is charged for, /// including L1 gas and additional OS resources estimation. pub actual_resources: ResourcesMapping, diff --git a/crates/blockifier/src/transaction/transaction_execution.rs b/crates/blockifier/src/transaction/transaction_execution.rs index 3d38fdf62f..29458dd5c1 100644 --- a/crates/blockifier/src/transaction/transaction_execution.rs +++ b/crates/blockifier/src/transaction/transaction_execution.rs @@ -113,7 +113,7 @@ impl ExecutableTransaction for L1HandlerTransaction { self.run_execute(state, &mut execution_resources, &mut context, &mut remaining_gas)?; let l1_handler_payload_size = self.payload_size(); - let ActualCost { actual_fee, actual_resources } = + let ActualCost { actual_fee, da_gas, actual_resources } = ActualCost::builder_for_l1_handler(tx_context, l1_handler_payload_size) .with_execute_call_info(&execute_call_info) .try_add_state_changes(state)? @@ -131,6 +131,7 @@ impl ExecutableTransaction for L1HandlerTransaction { execute_call_info, fee_transfer_call_info: None, actual_fee: Fee::default(), + da_gas, actual_resources, revert_error: None, }) diff --git a/crates/blockifier/src/transaction/transaction_utils.rs b/crates/blockifier/src/transaction/transaction_utils.rs index 8050f201ca..cd29cfcb69 100644 --- a/crates/blockifier/src/transaction/transaction_utils.rs +++ b/crates/blockifier/src/transaction/transaction_utils.rs @@ -3,13 +3,12 @@ use std::collections::HashMap; use cairo_vm::vm::runners::builtin_runner::SEGMENT_ARENA_BUILTIN_NAME; use starknet_api::transaction::TransactionVersion; -use super::objects::GasVector; use crate::abi::constants; use crate::execution::call_info::CallInfo; use crate::execution::contract_class::ContractClass; use crate::execution::entry_point::ExecutionResources; use crate::transaction::errors::TransactionExecutionError; -use crate::transaction::objects::{ResourcesMapping, TransactionExecutionResult}; +use crate::transaction::objects::{GasVector, ResourcesMapping, TransactionExecutionResult}; use crate::transaction::transaction_types::TransactionType; use crate::utils::usize_from_u128; use crate::versioned_constants::VersionedConstants; @@ -26,7 +25,7 @@ pub fn calculate_tx_resources( ) -> TransactionExecutionResult { let l1_gas_usage = usize_from_u128(gas_vector.l1_gas) .expect("This conversion should not fail as the value is a converted usize."); - let l1_blob_gas_usage = usize_from_u128(gas_vector.blob_gas) + let l1_blob_gas_usage = usize_from_u128(gas_vector.l1_data_gas) .expect("This conversion should not fail as the value is a converted usize."); // Add additional Cairo resources needed for the OS to run the transaction. let total_vm_usage = &execution_resources.vm_resources diff --git a/crates/blockifier/src/transaction/transactions_test.rs b/crates/blockifier/src/transaction/transactions_test.rs index 7f799dc43c..8036233da0 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -426,19 +426,19 @@ fn test_invoke_tx( n_modified_contracts: 1, ..StateChangesCount::default() }; - let GasVector { l1_gas: expected_gas_usage, blob_gas: expected_blob_gas_usage } = - get_da_gas_cost(state_changes_count, use_kzg_da); + let da_gas = get_da_gas_cost(state_changes_count, use_kzg_da); let expected_execution_info = TransactionExecutionInfo { validate_call_info: expected_validate_call_info, execute_call_info: expected_execute_call_info, fee_transfer_call_info: expected_fee_transfer_call_info, actual_fee: expected_actual_fee, + da_gas: da_gas.clone(), actual_resources: ResourcesMapping(HashMap::from([ ( abi_constants::BLOB_GAS_USAGE.to_string(), - usize_from_u128(expected_blob_gas_usage).unwrap(), + usize_from_u128(da_gas.l1_data_gas).unwrap(), ), - (abi_constants::L1_GAS_USAGE.to_string(), usize_from_u128(expected_gas_usage).unwrap()), + (abi_constants::L1_GAS_USAGE.to_string(), usize_from_u128(da_gas.l1_gas).unwrap()), (HASH_BUILTIN_NAME.to_string(), 14 + calldata_length), (RANGE_CHECK_BUILTIN_NAME.to_string(), expected_arguments.range_check), (abi_constants::N_STEPS_RESOURCE.to_string(), expected_arguments.n_steps), @@ -1124,21 +1124,18 @@ fn test_declare_tx( FeatureContract::ERC20.get_class_hash(), ); - let GasVector { l1_gas: expected_gas_usage, blob_gas: expected_blob_gas_usage } = - declare_expected_gas_vector(tx_version, use_kzg_da); + let da_gas = declare_expected_gas_vector(tx_version, use_kzg_da); let expected_execution_info = TransactionExecutionInfo { validate_call_info: expected_validate_call_info, execute_call_info: None, fee_transfer_call_info: expected_fee_transfer_call_info, actual_fee: expected_actual_fee, + da_gas: da_gas.clone(), revert_error: None, actual_resources: ResourcesMapping(HashMap::from([ - (abi_constants::L1_GAS_USAGE.to_string(), expected_gas_usage.try_into().unwrap()), - ( - abi_constants::BLOB_GAS_USAGE.to_string(), - expected_blob_gas_usage.try_into().unwrap(), - ), + (abi_constants::L1_GAS_USAGE.to_string(), da_gas.l1_gas.try_into().unwrap()), + (abi_constants::BLOB_GAS_USAGE.to_string(), da_gas.l1_data_gas.try_into().unwrap()), (HASH_BUILTIN_NAME.to_string(), 16), ( RANGE_CHECK_BUILTIN_NAME.to_string(), @@ -1264,20 +1261,20 @@ fn test_deploy_account_tx( n_class_hash_updates: 1, ..StateChangesCount::default() }; - let GasVector { l1_gas: expected_gas_usage, blob_gas: expected_blob_gas_usage } = - get_da_gas_cost(state_changes_count, use_kzg_da); + let da_gas = get_da_gas_cost(state_changes_count, use_kzg_da); let expected_execution_info = TransactionExecutionInfo { validate_call_info: expected_validate_call_info, execute_call_info: expected_execute_call_info, fee_transfer_call_info: expected_fee_transfer_call_info, actual_fee: expected_actual_fee, + da_gas: da_gas.clone(), revert_error: None, actual_resources: ResourcesMapping(HashMap::from([ - (abi_constants::L1_GAS_USAGE.to_string(), usize_from_u128(expected_gas_usage).unwrap()), + (abi_constants::L1_GAS_USAGE.to_string(), usize_from_u128(da_gas.l1_gas).unwrap()), ( abi_constants::BLOB_GAS_USAGE.to_string(), - usize_from_u128(expected_blob_gas_usage).unwrap(), + usize_from_u128(da_gas.l1_data_gas).unwrap(), ), (HASH_BUILTIN_NAME.to_string(), 23), (RANGE_CHECK_BUILTIN_NAME.to_string(), expected_range_check_builtin), @@ -1498,7 +1495,7 @@ fn test_calculate_tx_gas_usage(#[values(false, true)] use_kzg_da: bool) { let gas_vector = calculate_tx_gas_usage_vector(std::iter::empty(), state_changes_count, None, use_kzg_da) .unwrap(); - let GasVector { l1_gas: l1_gas_usage, blob_gas: l1_blob_gas_usage } = gas_vector; + let GasVector { l1_gas: l1_gas_usage, l1_data_gas: l1_blob_gas_usage } = gas_vector; assert_eq!( u128_from_usize(tx_execution_info.actual_resources.gas_usage()).unwrap(), l1_gas_usage @@ -1543,7 +1540,7 @@ fn test_calculate_tx_gas_usage(#[values(false, true)] use_kzg_da: bool) { let gas_vector = calculate_tx_gas_usage_vector(std::iter::empty(), state_changes_count, None, use_kzg_da) .unwrap(); - let GasVector { l1_gas: l1_gas_usage, blob_gas: l1_blob_gas_usage } = gas_vector; + let GasVector { l1_gas: l1_gas_usage, l1_data_gas: l1_blob_gas_usage } = gas_vector; assert_eq!( u128_from_usize(tx_execution_info.actual_resources.gas_usage()).unwrap(), l1_gas_usage @@ -1710,17 +1707,24 @@ fn test_l1_handler(#[values(false, true)] use_kzg_da: bool) { }; // Build the expected resource mapping. - let (expected_gas_usage, expected_blob_gas_usage) = match use_kzg_da { - true => (16023, 128), - false => (17675, 0), + let expected_gas = match use_kzg_da { + true => GasVector { l1_gas: 16023, l1_data_gas: 128 }, + false => GasVector { l1_gas: 17675, l1_data_gas: 0 }, + }; + let expected_da_gas = match use_kzg_da { + true => GasVector { l1_gas: 0, l1_data_gas: 128 }, + false => GasVector { l1_gas: 1652, l1_data_gas: 0 }, }; let expected_resource_mapping = ResourcesMapping(HashMap::from([ (HASH_BUILTIN_NAME.to_string(), 11 + payload_size), (abi_constants::N_STEPS_RESOURCE.to_string(), 1405), (RANGE_CHECK_BUILTIN_NAME.to_string(), 23), - (abi_constants::L1_GAS_USAGE.to_string(), expected_gas_usage), - (abi_constants::BLOB_GAS_USAGE.to_string(), expected_blob_gas_usage), + (abi_constants::L1_GAS_USAGE.to_string(), usize_from_u128(expected_gas.l1_gas).unwrap()), + ( + abi_constants::BLOB_GAS_USAGE.to_string(), + usize_from_u128(expected_gas.l1_data_gas).unwrap(), + ), ])); // Build the expected execution info. @@ -1729,6 +1733,7 @@ fn test_l1_handler(#[values(false, true)] use_kzg_da: bool) { execute_call_info: Some(expected_call_info), fee_transfer_call_info: None, actual_fee: Fee(0), + da_gas: expected_da_gas, actual_resources: expected_resource_mapping, revert_error: None, }; diff --git a/crates/native_blockifier/src/lib.rs b/crates/native_blockifier/src/lib.rs index 93866e5a8f..36c6fc1301 100644 --- a/crates/native_blockifier/src/lib.rs +++ b/crates/native_blockifier/src/lib.rs @@ -41,6 +41,7 @@ fn native_blockifier(py: Python<'_>, py_module: &PyModule) -> PyResult<()> { pyo3_log::init(); py_module.add_class::()?; + py_module.add_class::()?; py_module.add_class::()?; py_module.add_class::()?; py_module.add_class::()?; @@ -48,7 +49,6 @@ fn native_blockifier(py: Python<'_>, py_module: &PyModule) -> PyResult<()> { py_module.add_class::()?; py_module.add_class::()?; py_module.add_class::()?; - py_module.add_class::()?; py_module.add_class::()?; py_module.add("UndeclaredClassHashError", py.get_type::())?; add_py_exceptions(py, py_module)?;