diff --git a/crates/blockifier/resources/versioned_constants.json b/crates/blockifier/resources/versioned_constants.json index f4d859c97d..95b6800e1e 100644 --- a/crates/blockifier/resources/versioned_constants.json +++ b/crates/blockifier/resources/versioned_constants.json @@ -569,53 +569,55 @@ "validate_max_n_steps": 1000000, "min_compiler_version_for_sierra_gas": "2.8.0", "vm_resource_fee_cost": { - "add_mod_builtin": [ - 4, - 100 - ], - "bitwise_builtin": [ - 16, - 100 - ], - "ec_op_builtin": [ - 256, - 100 - ], - "ecdsa_builtin": [ - 512, - 100 - ], - "keccak_builtin": [ - 512, - 100 - ], - "mul_mod_builtin": [ - 4, - 100 - ], + "builtins": { + "add_mod_builtin": [ + 4, + 100 + ], + "bitwise_builtin": [ + 16, + 100 + ], + "ec_op_builtin": [ + 256, + 100 + ], + "ecdsa_builtin": [ + 512, + 100 + ], + "keccak_builtin": [ + 512, + 100 + ], + "mul_mod_builtin": [ + 4, + 100 + ], + "output_builtin": [ + 0, + 1 + ], + "pedersen_builtin": [ + 8, + 100 + ], + "poseidon_builtin": [ + 8, + 100 + ], + "range_check_builtin": [ + 4, + 100 + ], + "range_check96_builtin": [ + 4, + 100 + ] + }, "n_steps": [ 25, 10000 - ], - "output_builtin": [ - 0, - 1 - ], - "pedersen_builtin": [ - 8, - 100 - ], - "poseidon_builtin": [ - 8, - 100 - ], - "range_check_builtin": [ - 4, - 100 - ], - "range_check96_builtin": [ - 4, - 100 ] } } diff --git a/crates/blockifier/resources/versioned_constants_13_0.json b/crates/blockifier/resources/versioned_constants_13_0.json index d13b6c57c6..3e3d9ea9d1 100644 --- a/crates/blockifier/resources/versioned_constants_13_0.json +++ b/crates/blockifier/resources/versioned_constants_13_0.json @@ -521,53 +521,55 @@ "validate_max_n_steps": 1000000, "min_compiler_version_for_sierra_gas": "2.8.0", "vm_resource_fee_cost": { - "add_mod_builtin": [ - 0, - 1 - ], - "bitwise_builtin": [ - 32, - 100 - ], - "ec_op_builtin": [ - 512, - 100 - ], - "ecdsa_builtin": [ - 1024, - 100 - ], - "keccak_builtin": [ - 1024, - 100 - ], - "mul_mod_builtin": [ - 0, - 1 - ], + "builtins": { + "add_mod_builtin": [ + 0, + 1 + ], + "bitwise_builtin": [ + 32, + 100 + ], + "ec_op_builtin": [ + 512, + 100 + ], + "ecdsa_builtin": [ + 1024, + 100 + ], + "keccak_builtin": [ + 1024, + 100 + ], + "mul_mod_builtin": [ + 0, + 1 + ], + "output_builtin": [ + 0, + 1 + ], + "pedersen_builtin": [ + 16, + 100 + ], + "poseidon_builtin": [ + 16, + 100 + ], + "range_check_builtin": [ + 8, + 100 + ], + "range_check96_builtin": [ + 0, + 1 + ] + }, "n_steps": [ 5, 1000 - ], - "output_builtin": [ - 0, - 1 - ], - "pedersen_builtin": [ - 16, - 100 - ], - "poseidon_builtin": [ - 16, - 100 - ], - "range_check_builtin": [ - 8, - 100 - ], - "range_check96_builtin": [ - 0, - 1 ] } } diff --git a/crates/blockifier/resources/versioned_constants_13_1.json b/crates/blockifier/resources/versioned_constants_13_1.json index dea6bed849..5904fee673 100644 --- a/crates/blockifier/resources/versioned_constants_13_1.json +++ b/crates/blockifier/resources/versioned_constants_13_1.json @@ -557,53 +557,55 @@ "validate_max_n_steps": 1000000, "min_compiler_version_for_sierra_gas": "2.8.0", "vm_resource_fee_cost": { - "add_mod_builtin": [ - 0, - 1 - ], - "bitwise_builtin": [ - 16, - 100 - ], - "ec_op_builtin": [ - 256, - 100 - ], - "ecdsa_builtin": [ - 512, - 100 - ], - "keccak_builtin": [ - 512, - 100 - ], - "mul_mod_builtin": [ - 0, - 1 - ], + "builtins": { + "add_mod_builtin": [ + 0, + 1 + ], + "bitwise_builtin": [ + 16, + 100 + ], + "ec_op_builtin": [ + 256, + 100 + ], + "ecdsa_builtin": [ + 512, + 100 + ], + "keccak_builtin": [ + 512, + 100 + ], + "mul_mod_builtin": [ + 0, + 1 + ], + "output_builtin": [ + 0, + 1 + ], + "pedersen_builtin": [ + 8, + 100 + ], + "poseidon_builtin": [ + 8, + 100 + ], + "range_check_builtin": [ + 4, + 100 + ], + "range_check96_builtin": [ + 0, + 1 + ] + }, "n_steps": [ 25, 10000 - ], - "output_builtin": [ - 0, - 1 - ], - "pedersen_builtin": [ - 8, - 100 - ], - "poseidon_builtin": [ - 8, - 100 - ], - "range_check_builtin": [ - 4, - 100 - ], - "range_check96_builtin": [ - 0, - 1 ] } } diff --git a/crates/blockifier/resources/versioned_constants_13_1_1.json b/crates/blockifier/resources/versioned_constants_13_1_1.json index 8eb58a3a5b..297ca9017c 100644 --- a/crates/blockifier/resources/versioned_constants_13_1_1.json +++ b/crates/blockifier/resources/versioned_constants_13_1_1.json @@ -26,7 +26,7 @@ "max_recursion_depth": 50, "segment_arena_cells": true, "disable_cairo0_redeclaration": false, - "enable_reverts": false, + "enable_reverts": false, "os_constants": { "nop_entry_point_offset": -1, "entry_point_type_external": 0, @@ -557,53 +557,55 @@ "validate_max_n_steps": 1000000, "min_compiler_version_for_sierra_gas": "2.8.0", "vm_resource_fee_cost": { - "add_mod_builtin": [ - 0, - 1 - ], - "bitwise_builtin": [ - 16, - 100 - ], - "ec_op_builtin": [ - 256, - 100 - ], - "ecdsa_builtin": [ - 512, - 100 - ], - "keccak_builtin": [ - 512, - 100 - ], - "mul_mod_builtin": [ - 0, - 1 - ], + "builtins": { + "add_mod_builtin": [ + 0, + 1 + ], + "bitwise_builtin": [ + 16, + 100 + ], + "ec_op_builtin": [ + 256, + 100 + ], + "ecdsa_builtin": [ + 512, + 100 + ], + "keccak_builtin": [ + 512, + 100 + ], + "mul_mod_builtin": [ + 0, + 1 + ], + "output_builtin": [ + 0, + 1 + ], + "pedersen_builtin": [ + 8, + 100 + ], + "poseidon_builtin": [ + 8, + 100 + ], + "range_check_builtin": [ + 4, + 100 + ], + "range_check96_builtin": [ + 0, + 1 + ] + }, "n_steps": [ 25, 10000 - ], - "output_builtin": [ - 0, - 1 - ], - "pedersen_builtin": [ - 8, - 100 - ], - "poseidon_builtin": [ - 8, - 100 - ], - "range_check_builtin": [ - 4, - 100 - ], - "range_check96_builtin": [ - 0, - 1 ] } } diff --git a/crates/blockifier/resources/versioned_constants_13_2.json b/crates/blockifier/resources/versioned_constants_13_2.json index f7b93716a2..2fc52f74a8 100644 --- a/crates/blockifier/resources/versioned_constants_13_2.json +++ b/crates/blockifier/resources/versioned_constants_13_2.json @@ -563,53 +563,55 @@ "validate_max_n_steps": 1000000, "min_compiler_version_for_sierra_gas": "2.8.0", "vm_resource_fee_cost": { - "add_mod_builtin": [ - 4, - 100 - ], - "bitwise_builtin": [ - 16, - 100 - ], - "ec_op_builtin": [ - 256, - 100 - ], - "ecdsa_builtin": [ - 512, - 100 - ], - "keccak_builtin": [ - 512, - 100 - ], - "mul_mod_builtin": [ - 4, - 100 - ], + "builtins": { + "add_mod_builtin": [ + 4, + 100 + ], + "bitwise_builtin": [ + 16, + 100 + ], + "ec_op_builtin": [ + 256, + 100 + ], + "ecdsa_builtin": [ + 512, + 100 + ], + "keccak_builtin": [ + 512, + 100 + ], + "mul_mod_builtin": [ + 4, + 100 + ], + "output_builtin": [ + 0, + 1 + ], + "pedersen_builtin": [ + 8, + 100 + ], + "poseidon_builtin": [ + 8, + 100 + ], + "range_check_builtin": [ + 4, + 100 + ], + "range_check96_builtin": [ + 4, + 100 + ] + }, "n_steps": [ 25, 10000 - ], - "output_builtin": [ - 0, - 1 - ], - "pedersen_builtin": [ - 8, - 100 - ], - "poseidon_builtin": [ - 8, - 100 - ], - "range_check_builtin": [ - 4, - 100 - ], - "range_check96_builtin": [ - 4, - 100 ] } } diff --git a/crates/blockifier/resources/versioned_constants_13_2_1.json b/crates/blockifier/resources/versioned_constants_13_2_1.json index 4ec50e4dcb..8a241390af 100644 --- a/crates/blockifier/resources/versioned_constants_13_2_1.json +++ b/crates/blockifier/resources/versioned_constants_13_2_1.json @@ -563,53 +563,55 @@ "validate_max_n_steps": 1000000, "min_compiler_version_for_sierra_gas": "2.8.0", "vm_resource_fee_cost": { - "add_mod_builtin": [ - 4, - 100 - ], - "bitwise_builtin": [ - 16, - 100 - ], - "ec_op_builtin": [ - 256, - 100 - ], - "ecdsa_builtin": [ - 512, - 100 - ], - "keccak_builtin": [ - 512, - 100 - ], - "mul_mod_builtin": [ - 4, - 100 - ], + "builtins": { + "add_mod_builtin": [ + 4, + 100 + ], + "bitwise_builtin": [ + 16, + 100 + ], + "ec_op_builtin": [ + 256, + 100 + ], + "ecdsa_builtin": [ + 512, + 100 + ], + "keccak_builtin": [ + 512, + 100 + ], + "mul_mod_builtin": [ + 4, + 100 + ], + "output_builtin": [ + 0, + 1 + ], + "pedersen_builtin": [ + 8, + 100 + ], + "poseidon_builtin": [ + 8, + 100 + ], + "range_check_builtin": [ + 4, + 100 + ], + "range_check96_builtin": [ + 4, + 100 + ] + }, "n_steps": [ 25, 10000 - ], - "output_builtin": [ - 0, - 1 - ], - "pedersen_builtin": [ - 8, - 100 - ], - "poseidon_builtin": [ - 8, - 100 - ], - "range_check_builtin": [ - 4, - 100 - ], - "range_check96_builtin": [ - 4, - 100 ] } } diff --git a/crates/blockifier/src/execution/entry_point.rs b/crates/blockifier/src/execution/entry_point.rs index 0f43522e2f..7db977e561 100644 --- a/crates/blockifier/src/execution/entry_point.rs +++ b/crates/blockifier/src/execution/entry_point.rs @@ -187,12 +187,7 @@ impl EntryPointExecutionContext { return block_upper_bound; } - let gas_per_step = versioned_constants - .vm_resource_fee_cost() - .get(constants::N_STEPS_RESOURCE) - .unwrap_or_else(|| { - panic!("{} must appear in `vm_resource_fee_cost`.", constants::N_STEPS_RESOURCE) - }); + let gas_per_step = versioned_constants.vm_resource_fee_cost().n_steps; // New transactions derive the step limit by the L1 gas resource bounds; deprecated // transactions derive this value from the `max_fee`. diff --git a/crates/blockifier/src/fee/fee_test.rs b/crates/blockifier/src/fee/fee_test.rs index a02225cfbd..821e6e2b93 100644 --- a/crates/blockifier/src/fee/fee_test.rs +++ b/crates/blockifier/src/fee/fee_test.rs @@ -7,7 +7,6 @@ use rstest::rstest; use starknet_api::invoke_tx_args; use starknet_api::transaction::{Fee, Resource, ValidResourceBounds}; -use crate::abi::constants::N_STEPS_RESOURCE; use crate::blockifier::block::GasPrices; use crate::context::BlockContext; use crate::fee::fee_checks::{FeeCheckError, FeeCheckReportFields, PostExecutionReport}; @@ -51,11 +50,10 @@ fn test_simple_get_vm_resource_usage() { // Positive flow. // Verify calculation - in our case, n_steps is the heaviest resource. - let l1_gas_by_vm_usage = - (*versioned_constants.vm_resource_fee_cost().get(N_STEPS_RESOURCE).unwrap() - * (u128_from_usize(vm_resource_usage.n_steps + n_reverted_steps))) - .ceil() - .to_integer(); + let l1_gas_by_vm_usage = (versioned_constants.vm_resource_fee_cost().n_steps + * (u128_from_usize(vm_resource_usage.n_steps + n_reverted_steps))) + .ceil() + .to_integer(); assert_eq!( GasVector::from_l1_gas(l1_gas_by_vm_usage), get_vm_resources_cost( @@ -93,11 +91,10 @@ fn test_float_get_vm_resource_usage() { // Positive flow. // Verify calculation - in our case, n_steps is the heaviest resource. let n_reverted_steps = 300; - let l1_gas_by_vm_usage = - ((*versioned_constants.vm_resource_fee_cost().get(N_STEPS_RESOURCE).unwrap()) - * u128_from_usize(vm_resource_usage.n_steps + n_reverted_steps)) - .ceil() - .to_integer(); + let l1_gas_by_vm_usage = (versioned_constants.vm_resource_fee_cost().n_steps + * u128_from_usize(vm_resource_usage.n_steps + n_reverted_steps)) + .ceil() + .to_integer(); assert_eq!( GasVector::from_l1_gas(l1_gas_by_vm_usage), get_vm_resources_cost( @@ -111,15 +108,13 @@ fn test_float_get_vm_resource_usage() { // Another positive flow, this time the heaviest resource is ecdsa_builtin. vm_resource_usage.n_steps = 200; - let l1_gas_by_vm_usage = ((*versioned_constants - .vm_resource_fee_cost() - .get(BuiltinName::ecdsa.to_str_with_suffix()) - .unwrap()) - * u128_from_usize( - *vm_resource_usage.builtin_instance_counter.get(&BuiltinName::ecdsa).unwrap(), - )) - .ceil() - .to_integer(); + let l1_gas_by_vm_usage = + ((*versioned_constants.vm_resource_fee_cost().builtins.get(&BuiltinName::ecdsa).unwrap()) + * u128_from_usize( + *vm_resource_usage.builtin_instance_counter.get(&BuiltinName::ecdsa).unwrap(), + )) + .ceil() + .to_integer(); assert_eq!( GasVector::from_l1_gas(l1_gas_by_vm_usage), diff --git a/crates/blockifier/src/fee/fee_utils.rs b/crates/blockifier/src/fee/fee_utils.rs index 8a97267815..7244ed46fe 100644 --- a/crates/blockifier/src/fee/fee_utils.rs +++ b/crates/blockifier/src/fee/fee_utils.rs @@ -1,5 +1,6 @@ use std::collections::HashSet; +use cairo_vm::types::builtin_name::BuiltinName; use cairo_vm::vm::runners::cairo_runner::ExecutionResources; use num_bigint::BigUint; use starknet_api::core::ContractAddress; @@ -8,7 +9,6 @@ use starknet_api::transaction::{Fee, Resource}; use starknet_types_core::felt::Felt; use crate::abi::abi_utils::get_fee_token_var_address; -use crate::abi::constants; use crate::abi::sierra_types::next_storage_key; use crate::blockifier::block::BlockInfo; use crate::context::{BlockContext, TransactionContext}; @@ -41,31 +41,32 @@ pub fn get_vm_resources_cost( ) -> TransactionFeeResult { // TODO(Yoni, 1/7/2024): rename vm -> cairo. let vm_resource_fee_costs = versioned_constants.vm_resource_fee_cost(); - let mut vm_resource_usage_for_fee = vm_resource_usage.prover_builtins_by_name(); - vm_resource_usage_for_fee.insert( - constants::N_STEPS_RESOURCE.to_string(), - vm_resource_usage.total_n_steps() + n_reverted_steps, - ); + let vm_resource_usage_for_fee = vm_resource_usage.prover_builtins(); // Validate used Cairo resources. - let used_resource_names = HashSet::<&String>::from_iter(vm_resource_usage_for_fee.keys()); - assert!( - used_resource_names.is_subset(&HashSet::from_iter(vm_resource_fee_costs.keys())), + HashSet::<&BuiltinName>::from_iter(vm_resource_usage_for_fee.keys()) + .is_subset(&HashSet::from_iter(vm_resource_fee_costs.builtins.keys())), "{:#?} should contain {:#?}", - vm_resource_fee_costs.keys(), - used_resource_names, + vm_resource_fee_costs.builtins.keys(), + vm_resource_usage_for_fee.keys(), ); - // Convert Cairo usage to L1 gas usage. + // Convert Cairo builtin usage to L1 gas usage. + // Do so by taking the maximum of the usage of each builtin + step usage. let vm_l1_gas_usage = vm_resource_fee_costs + .builtins .iter() - .map(|(key, resource_val)| { - ((*resource_val) - * u128_from_usize(vm_resource_usage_for_fee.get(key).cloned().unwrap_or_default())) - .ceil() - .to_integer() + // Builtin costs and usage. + .map(|(builtin, resource_cost)| { + (*resource_cost, vm_resource_usage_for_fee.get(builtin).cloned().unwrap_or_default()) }) + // Step costs and usage. + .chain(vec![( + vm_resource_fee_costs.n_steps, + vm_resource_usage.total_n_steps() + n_reverted_steps, + )]) + .map(|(cost, usage)| (cost * u128_from_usize(usage)).ceil().to_integer()) .fold(0, u128::max); match computation_mode { diff --git a/crates/blockifier/src/transaction/objects.rs b/crates/blockifier/src/transaction/objects.rs index 938d801ced..7854504ea4 100644 --- a/crates/blockifier/src/transaction/objects.rs +++ b/crates/blockifier/src/transaction/objects.rs @@ -518,7 +518,6 @@ pub trait ExecutionResourcesTraits { fn total_n_steps(&self) -> usize; fn to_resources_mapping(&self) -> ResourcesMapping; fn prover_builtins(&self) -> HashMap; - fn prover_builtins_by_name(&self) -> HashMap; } impl ExecutionResourcesTraits for ExecutionResources { @@ -546,18 +545,15 @@ impl ExecutionResourcesTraits for ExecutionResources { builtins } - fn prover_builtins_by_name(&self) -> HashMap { - self.prover_builtins() - .iter() - .map(|(builtin, value)| (builtin.to_str_with_suffix().to_string(), *value)) - .collect() - } - // TODO(Nimrod, 1/5/2024): Delete this function when it's no longer in use. fn to_resources_mapping(&self) -> ResourcesMapping { let mut map = HashMap::from([(abi_constants::N_STEPS_RESOURCE.to_string(), self.total_n_steps())]); - map.extend(self.prover_builtins_by_name()); + map.extend( + self.prover_builtins() + .iter() + .map(|(builtin, value)| (builtin.to_str_with_suffix().to_string(), *value)), + ); ResourcesMapping(map) } diff --git a/crates/blockifier/src/versioned_constants.rs b/crates/blockifier/src/versioned_constants.rs index 1ac9279637..7294aec95b 100644 --- a/crates/blockifier/src/versioned_constants.rs +++ b/crates/blockifier/src/versioned_constants.rs @@ -84,6 +84,25 @@ impl Default for CompilerVersion { } } +#[derive(Clone, Debug, Default, Deserialize)] +pub struct VmResourceCosts { + pub n_steps: ResourceCost, + #[serde(deserialize_with = "builtin_map_from_string_map")] + pub builtins: HashMap, +} + +// TODO: This (along with the Serialize impl) is implemented in pub(crate) scope in the VM (named +// serde_generic_map_impl); use it if and when it's public. +fn builtin_map_from_string_map<'de, D: Deserializer<'de>>( + d: D, +) -> Result, D::Error> { + HashMap::::deserialize(d)? + .into_iter() + .map(|(k, v)| BuiltinName::from_str_with_suffix(&k).map(|k| (k, v))) + .collect::>>() + .ok_or(D::Error::custom("Invalid builtin name")) +} + /// Contains constants for the Blockifier that may vary between versions. /// Additional constants in the JSON file, not used by Blockifier but included for transparency, are /// automatically ignored during deserialization. @@ -118,9 +137,7 @@ pub struct VersionedConstants { os_resources: Arc, // Fee related. - // TODO: Consider making this a struct, this will require change the way we access these - // values. - vm_resource_fee_cost: Arc>, + vm_resource_fee_cost: Arc, // Just to make sure the value exists, but don't use the actual values. #[allow(dead_code)] gateway: serde::de::IgnoredAny, @@ -153,7 +170,7 @@ impl VersionedConstants { /// Returns the following ratio: L2_gas_price/L1_gas_price. pub fn l1_to_l2_gas_price_ratio(&self) -> ResourceCost { Ratio::new(1, u128::from(self.os_constants.gas_costs.step_gas_cost)) - * self.vm_resource_fee_cost()["n_steps"] + * self.vm_resource_fee_cost().n_steps } /// Returns the initial gas of any transaction to run with. @@ -162,7 +179,7 @@ impl VersionedConstants { os_consts.gas_costs.initial_gas_cost - os_consts.gas_costs.transaction_gas_cost } - pub fn vm_resource_fee_cost(&self) -> &HashMap { + pub fn vm_resource_fee_cost(&self) -> &VmResourceCosts { &self.vm_resource_fee_cost } @@ -210,29 +227,25 @@ impl VersionedConstants { #[cfg(any(feature = "testing", test))] pub fn create_for_account_testing() -> Self { let step_cost = ResourceCost::from_integer(1); - let vm_resource_fee_cost = Arc::new(HashMap::from([ - (crate::abi::constants::N_STEPS_RESOURCE.to_string(), step_cost), - (BuiltinName::pedersen.to_str_with_suffix().to_string(), ResourceCost::from_integer(1)), - ( - BuiltinName::range_check.to_str_with_suffix().to_string(), - ResourceCost::from_integer(1), - ), - (BuiltinName::ecdsa.to_str_with_suffix().to_string(), ResourceCost::from_integer(1)), - (BuiltinName::bitwise.to_str_with_suffix().to_string(), ResourceCost::from_integer(1)), - (BuiltinName::poseidon.to_str_with_suffix().to_string(), ResourceCost::from_integer(1)), - (BuiltinName::output.to_str_with_suffix().to_string(), ResourceCost::from_integer(1)), - (BuiltinName::ec_op.to_str_with_suffix().to_string(), ResourceCost::from_integer(1)), - ( - BuiltinName::range_check96.to_str_with_suffix().to_string(), - ResourceCost::from_integer(1), - ), - (BuiltinName::add_mod.to_str_with_suffix().to_string(), ResourceCost::from_integer(1)), - (BuiltinName::mul_mod.to_str_with_suffix().to_string(), ResourceCost::from_integer(1)), - ])); + let vm_resource_fee_cost = Arc::new(VmResourceCosts { + n_steps: step_cost, + builtins: HashMap::from([ + (BuiltinName::pedersen, ResourceCost::from_integer(1)), + (BuiltinName::range_check, ResourceCost::from_integer(1)), + (BuiltinName::ecdsa, ResourceCost::from_integer(1)), + (BuiltinName::bitwise, ResourceCost::from_integer(1)), + (BuiltinName::poseidon, ResourceCost::from_integer(1)), + (BuiltinName::output, ResourceCost::from_integer(1)), + (BuiltinName::ec_op, ResourceCost::from_integer(1)), + (BuiltinName::range_check96, ResourceCost::from_integer(1)), + (BuiltinName::add_mod, ResourceCost::from_integer(1)), + (BuiltinName::mul_mod, ResourceCost::from_integer(1)), + ]), + }); // Maintain the ratio between L1 gas price and L2 gas price. let latest = Self::create_for_testing(); - let latest_step_cost = latest.vm_resource_fee_cost["n_steps"]; + let latest_step_cost = latest.vm_resource_fee_cost.n_steps; let mut archival_data_gas_costs = latest.archival_data_gas_costs; archival_data_gas_costs.gas_per_code_byte *= latest_step_cost / step_cost; archival_data_gas_costs.gas_per_data_felt *= latest_step_cost / step_cost;