Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

feat(fee): add os resources to versioned constants #1393

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
608 changes: 449 additions & 159 deletions crates/blockifier/resources/versioned_constants.json

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions crates/blockifier/src/execution/entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ use crate::execution::common_hints::ExecutionMode;
use crate::execution::deprecated_syscalls::hint_processor::SyscallCounter;
use crate::execution::errors::{EntryPointExecutionError, PreExecutionError};
use crate::execution::execution_utils::execute_entry_point_call;
use crate::fee::os_resources::OS_RESOURCES;
use crate::state::state_api::State;
use crate::transaction::objects::{HasRelatedFeeType, TransactionExecutionResult, TransactionInfo};
use crate::transaction::transaction_types::TransactionType;
use crate::utils::usize_from_u128;
use crate::versioned_constants::VersionedConstants;

#[cfg(test)]
#[path = "entry_point_test.rs"]
Expand Down Expand Up @@ -306,7 +306,8 @@ impl EntryPointExecutionContext {
.map(|call_info| call_info.vm_resources.n_steps)
.unwrap_or_default();

let overhead_steps = OS_RESOURCES.resources_for_tx_type(tx_type, calldata_length).n_steps;
let overhead_steps =
self.versioned_constants().os_resources_for_tx_type(tx_type, calldata_length).n_steps;
self.subtract_steps(validate_steps + overhead_steps)
}

Expand All @@ -327,8 +328,12 @@ impl EntryPointExecutionContext {
.join("\n")
}

pub fn versioned_constants(&self) -> &VersionedConstants {
&self.tx_context.block_context.versioned_constants
}

pub fn get_gas_cost(&self, name: &str) -> u64 {
self.tx_context.block_context.versioned_constants.gas_cost(name)
self.versioned_constants().gas_cost(name)
}
}

Expand Down
2 changes: 0 additions & 2 deletions crates/blockifier/src/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ pub mod eth_gas_constants;
pub mod fee_checks;
pub mod fee_utils;
pub mod gas_usage;
pub mod os_resources;
pub mod os_usage;
1 change: 1 addition & 0 deletions crates/blockifier/src/fee/actual_cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ impl<'a> ActualCostBuilder<'a> {
)?;

let mut actual_resources = calculate_tx_resources(
&self.tx_context.block_context.versioned_constants,
execution_resources,
gas_usage_vector,
self.tx_type,
Expand Down
9 changes: 4 additions & 5 deletions crates/blockifier/src/fee/gas_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ 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::os_resources::OS_RESOURCES;
use crate::state::cached_state::StateChangesCount;
use crate::transaction::account_transaction::AccountTransaction;
use crate::transaction::objects::{
Expand Down Expand Up @@ -208,8 +207,9 @@ pub fn estimate_minimal_gas_vector(
tx: &AccountTransaction,
) -> TransactionPreValidationResult<GasVector> {
// TODO(Dori, 1/8/2023): Give names to the constant VM step estimates and regression-test them.
let BlockContext { block_info, versioned_constants, .. } = block_context;
let os_steps_for_type =
OS_RESOURCES.resources_for_tx_type(&tx.tx_type(), tx.calldata_length()).n_steps;
versioned_constants.os_resources_for_tx_type(&tx.tx_type(), tx.calldata_length()).n_steps;
let state_changes_by_account_transaction = match tx {
// We consider the following state changes: sender balance update (storage update) + nonce
// increment (contract modification) (we exclude the sequencer balance update and the ERC20
Expand All @@ -234,9 +234,8 @@ pub fn estimate_minimal_gas_vector(
n_modified_contracts: 1,
},
};
let use_kzg_da = block_context.block_info.use_kzg_da;
let GasVector { l1_gas: gas_cost, blob_gas: blob_gas_cost } =
get_da_gas_cost(state_changes_by_account_transaction, use_kzg_da);
get_da_gas_cost(state_changes_by_account_transaction, block_info.use_kzg_da);

let resources = ResourcesMapping(HashMap::from([
(
Expand All @@ -251,7 +250,7 @@ pub fn estimate_minimal_gas_vector(
(constants::N_STEPS_RESOURCE.to_string(), os_steps_for_type),
]));

Ok(calculate_tx_gas_vector(&resources, &block_context.versioned_constants)?)
Ok(calculate_tx_gas_vector(&resources, versioned_constants)?)
}

/// Compute l1_gas estimation from gas_vector using the following formula:
Expand Down
Loading
Loading