diff --git a/crates/blockifier/resources/versioned_constants.json b/crates/blockifier/resources/versioned_constants.json index 9789f0fb805..ec98120a3b6 100644 --- a/crates/blockifier/resources/versioned_constants.json +++ b/crates/blockifier/resources/versioned_constants.json @@ -102,6 +102,10 @@ "range_check_gas_cost": 70, "pedersen_gas_cost": 4130, "bitwise_builtin_gas_cost": 594, + "ecop_gas_cost": 256, + "poseidon_gas_cost": 500, + "add_mod_gas_cost": 234, + "mul_mod_gas_cost": 616, "replace_class_gas_cost": { "step_gas_cost": 100, "range_check_gas_cost": 1 diff --git a/crates/blockifier/resources/versioned_constants_13_0.json b/crates/blockifier/resources/versioned_constants_13_0.json index 103ea7fca02..4cfe84c042e 100644 --- a/crates/blockifier/resources/versioned_constants_13_0.json +++ b/crates/blockifier/resources/versioned_constants_13_0.json @@ -24,6 +24,12 @@ "stored_block_hash_buffer": 10, "step_gas_cost": 100, "range_check_gas_cost": 70, + "pedersen_gas_cost": 0, + "bitwise_builtin_gas_cost": 0, + "ecop_gas_cost": 0, + "poseidon_gas_cost": 0, + "add_mod_gas_cost": 0, + "mul_mod_gas_cost": 0, "memory_hole_gas_cost": 10, "initial_gas_cost": { "step_gas_cost": 100000000 diff --git a/crates/blockifier/resources/versioned_constants_13_1.json b/crates/blockifier/resources/versioned_constants_13_1.json index 279612a501d..b92d0bb0a9f 100644 --- a/crates/blockifier/resources/versioned_constants_13_1.json +++ b/crates/blockifier/resources/versioned_constants_13_1.json @@ -43,6 +43,12 @@ "stored_block_hash_buffer": 10, "step_gas_cost": 100, "range_check_gas_cost": 70, + "pedersen_gas_cost": 0, + "bitwise_builtin_gas_cost": 0, + "ecop_gas_cost": 0, + "poseidon_gas_cost": 0, + "add_mod_gas_cost": 0, + "mul_mod_gas_cost": 0, "memory_hole_gas_cost": 10, "initial_gas_cost": { "step_gas_cost": 100000000 diff --git a/crates/blockifier/resources/versioned_constants_13_1_1.json b/crates/blockifier/resources/versioned_constants_13_1_1.json index a80475fa16d..7264f5810b8 100644 --- a/crates/blockifier/resources/versioned_constants_13_1_1.json +++ b/crates/blockifier/resources/versioned_constants_13_1_1.json @@ -43,6 +43,12 @@ "stored_block_hash_buffer": 10, "step_gas_cost": 100, "range_check_gas_cost": 70, + "pedersen_gas_cost": 0, + "bitwise_builtin_gas_cost": 0, + "ecop_gas_cost": 0, + "poseidon_gas_cost": 0, + "add_mod_gas_cost": 0, + "mul_mod_gas_cost": 0, "memory_hole_gas_cost": 10, "initial_gas_cost": { "step_gas_cost": 100000000 diff --git a/crates/blockifier/resources/versioned_constants_13_2.json b/crates/blockifier/resources/versioned_constants_13_2.json index a0dd34a749a..96bd9d3e451 100644 --- a/crates/blockifier/resources/versioned_constants_13_2.json +++ b/crates/blockifier/resources/versioned_constants_13_2.json @@ -95,7 +95,12 @@ "memory_hole_gas_cost": 10, "nop_entry_point_offset": -1, "range_check_gas_cost": 70, + "pedersen_gas_cost": 0, "bitwise_builtin_gas_cost": 594, + "ecop_gas_cost": 0, + "poseidon_gas_cost": 0, + "add_mod_gas_cost": 0, + "mul_mod_gas_cost": 0, "replace_class_gas_cost": { "step_gas_cost": 50, "syscall_base_gas_cost": 1 diff --git a/crates/blockifier/src/execution/entry_point_execution.rs b/crates/blockifier/src/execution/entry_point_execution.rs index 3ebae0ad8ed..75f373114f0 100644 --- a/crates/blockifier/src/execution/entry_point_execution.rs +++ b/crates/blockifier/src/execution/entry_point_execution.rs @@ -31,6 +31,7 @@ use crate::execution::execution_utils::{ }; use crate::execution::syscalls::hint_processor::SyscallHintProcessor; use crate::state::state_api::State; +use crate::versioned_constants::VersionedConstants; // TODO(spapini): Try to refactor this file into a StarknetRunner struct. @@ -165,8 +166,12 @@ pub fn initialize_execution_context<'a>( runner.initialize_function_runner_cairo_1(&entry_point.builtins)?; let mut read_only_segments = ReadOnlySegments::default(); - let program_extra_data_length = - prepare_program_extra_data(&mut runner, contract_class, &mut read_only_segments)?; + let program_extra_data_length = prepare_program_extra_data( + &mut runner, + contract_class, + &mut read_only_segments, + context.versioned_constants(), + )?; // Instantiate syscall handler. let initial_syscall_ptr = runner.vm.add_memory_segment(); @@ -193,14 +198,23 @@ fn prepare_program_extra_data( runner: &mut CairoRunner, contract_class: &ContractClassV1, read_only_segments: &mut ReadOnlySegments, + versioned_constants: &VersionedConstants, ) -> Result { // Create the builtin cost segment, with dummy values. - let mut data = vec![]; - - // TODO(spapini): Put real costs here. - for _i in 0..20 { - data.push(MaybeRelocatable::from(0)); - } + let gas_costs = &versioned_constants.os_constants.gas_costs; + let builtin_price_array = [ + gas_costs.pedersen_gas_cost, + gas_costs.bitwise_builtin_gas_cost, + gas_costs.ecop_gas_cost, + gas_costs.poseidon_gas_cost, + gas_costs.add_mod_gas_cost, + gas_costs.mul_mod_gas_cost, + ]; + + let data = builtin_price_array + .iter() + .map(|&x| MaybeRelocatable::from(Felt::from(x))) + .collect::>(); let builtin_cost_segment_start = read_only_segments.allocate(&mut runner.vm, &data)?; // Put a pointer to the builtin cost segment at the end of the program (after the diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/secp.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/secp.rs index 716fa534a2a..60b93c0b9cf 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/secp.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/secp.rs @@ -9,7 +9,7 @@ use crate::test_utils::contracts::FeatureContract; use crate::test_utils::initial_test_state::test_state; use crate::test_utils::{trivial_external_entry_point_new, CairoVersion, BALANCE}; -#[test_case(FeatureContract::TestContract(CairoVersion::Cairo1), 17022270; "VM")] +#[test_case(FeatureContract::TestContract(CairoVersion::Cairo1), 17041278; "VM")] fn test_secp256k1(test_contract: FeatureContract, expected_gas: u64) { let chain_info = &ChainInfo::create_for_testing(); let mut state = test_state(chain_info, BALANCE, &[(test_contract, 1)]); diff --git a/crates/blockifier/src/versioned_constants.rs b/crates/blockifier/src/versioned_constants.rs index 8183338d781..e51098ee31f 100644 --- a/crates/blockifier/src/versioned_constants.rs +++ b/crates/blockifier/src/versioned_constants.rs @@ -459,10 +459,17 @@ impl<'de> Deserialize<'de> for OsResources { #[derive(Debug, Default, Deserialize)] pub struct GasCosts { pub step_gas_cost: u64, + pub memory_hole_gas_cost: u64, // Range check has a hard-coded cost higher than its proof percentage to avoid the overhead of // retrieving its price from the table. pub range_check_gas_cost: u64, - pub memory_hole_gas_cost: u64, + // Priced builtins. + pub pedersen_gas_cost: u64, + pub bitwise_builtin_gas_cost: u64, + pub ecop_gas_cost: u64, + pub poseidon_gas_cost: u64, + pub add_mod_gas_cost: u64, + pub mul_mod_gas_cost: u64, // An estimation of the initial gas for a transaction to run with. This solution is // temporary and this value will be deduced from the transaction's fields. pub initial_gas_cost: u64,