From ca637f3b7357340a105d43aa18cdf7d4654265d6 Mon Sep 17 00:00:00 2001 From: Avi Cohen Date: Mon, 17 Jun 2024 10:55:18 +0300 Subject: [PATCH 1/3] chore: switch versioned contstants to versioned constants 13.1.1 for the replay batcher --- Cargo.toml | 8 +- .../resources/versioned_constants.json | 318 +++++++++--------- 2 files changed, 159 insertions(+), 167 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 103fa3da93..ad5ada4b7f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,10 +20,10 @@ ark-secp256k1 = "0.4.0" ark-secp256r1 = "0.4.0" assert_matches = "1.5.0" cached = "0.44.0" -cairo-lang-casm = "2.7.0-rc.2" -cairo-lang-runner = "2.7.0-rc.2" -cairo-lang-starknet-classes = "2.7.0-rc.2" -cairo-lang-utils = "2.7.0-rc.2" +cairo-lang-casm = "2.7.0-rc.1" +cairo-lang-runner = "2.7.0-rc.1" +cairo-lang-starknet-classes = "2.7.0-rc.1" +cairo-lang-utils = "2.7.0-rc.1" cairo-vm = "1.0.0-rc5" criterion = "0.3" derive_more = "0.99.17" diff --git a/crates/blockifier/resources/versioned_constants.json b/crates/blockifier/resources/versioned_constants.json index 0ec062c975..791dac8b9b 100644 --- a/crates/blockifier/resources/versioned_constants.json +++ b/crates/blockifier/resources/versioned_constants.json @@ -8,7 +8,7 @@ "max_calldata_length": 5000, "max_contract_bytecode_size": 81920 }, - "invoke_tx_max_n_steps": 10000000, + "invoke_tx_max_n_steps": 4000000, "l2_resource_gas_costs": { "gas_per_data_felt": [ 128, @@ -19,173 +19,170 @@ 1 ], "gas_per_code_byte": [ - 875, + 32, 1000 ] }, - "disable_cairo0_redeclaration": true, "max_recursion_depth": 50, "os_constants": { - "block_hash_contract_address": 1, - "call_contract_gas_cost": { - "entry_point_gas_cost": 1, - "step_gas_cost": 10, - "syscall_base_gas_cost": 1 - }, + "nop_entry_point_offset": -1, + "entry_point_type_external": 0, + "entry_point_type_l1_handler": 1, + "entry_point_type_constructor": 2, + "l1_handler_version": 0, + "sierra_array_len_bound": 4294967296, "constructor_entry_point_selector": "0x28ffe4ff0f226a9107253e17a904099aa4f63a02a5621de0576e5aa71bc5194", + "execute_entry_point_selector": "0x15d40a3d6ca2ac30f4031e42be28da9b056fef9bb7357ac5e85627ee876e5ad", + "validate_entry_point_selector": "0x162da33a4585851fe8d3af3c2a9c60b557814e221e0d4f30ff0b2189d9c7775", + "validate_declare_entry_point_selector": "0x289da278a8dc833409cabfdad1581e8e7d40e42dcaed693fa4008dcdb4963b3", + "validate_deploy_entry_point_selector": "0x36fcbf06cd96843058359e1a75928beacfac10727dab22a3972f0af8aa92895", + "transfer_entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e", "default_entry_point_selector": 0, - "deploy_gas_cost": { - "entry_point_gas_cost": 1, - "step_gas_cost": 200, - "syscall_base_gas_cost": 1 + "block_hash_contract_address": 1, + "stored_block_hash_buffer": 10, + "step_gas_cost": 100, + "range_check_gas_cost": 70, + "memory_hole_gas_cost": 10, + "initial_gas_cost": { + "step_gas_cost": 100000000 }, - "emit_event_gas_cost": { - "step_gas_cost": 10, - "syscall_base_gas_cost": 1 + "entry_point_initial_budget": { + "step_gas_cost": 100 + }, + "syscall_base_gas_cost": { + "step_gas_cost": 100 }, "entry_point_gas_cost": { "entry_point_initial_budget": 1, "step_gas_cost": 500 }, - "entry_point_initial_budget": { - "step_gas_cost": 100 - }, - "entry_point_type_constructor": 2, - "entry_point_type_external": 0, - "entry_point_type_l1_handler": 1, - "error_block_number_out_of_range": "Block number out of range", - "error_invalid_input_len": "Invalid input length", - "error_invalid_argument": "Invalid argument", - "error_out_of_gas": "Out of gas", - "execute_entry_point_selector": "0x15d40a3d6ca2ac30f4031e42be28da9b056fef9bb7357ac5e85627ee876e5ad", "fee_transfer_gas_cost": { "entry_point_gas_cost": 1, "step_gas_cost": 100 }, - "get_block_hash_gas_cost": { - "step_gas_cost": 50, - "syscall_base_gas_cost": 1 + "transaction_gas_cost": { + "entry_point_gas_cost": 2, + "fee_transfer_gas_cost": 1, + "step_gas_cost": 100 }, - "get_execution_info_gas_cost": { + "call_contract_gas_cost": { + "syscall_base_gas_cost": 1, "step_gas_cost": 10, - "syscall_base_gas_cost": 1 + "entry_point_gas_cost": 1 }, - "initial_gas_cost": { - "step_gas_cost": 100000000 + "deploy_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 200, + "entry_point_gas_cost": 1 }, - "keccak_gas_cost": { - "syscall_base_gas_cost": 1 + "get_block_hash_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 50 + }, + "get_execution_info_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 10 }, - "keccak_round_cost_gas_cost": 180000, - "l1_gas": "L1_GAS", - "l1_gas_index": 0, - "l1_handler_version": 0, - "l2_gas": "L2_GAS", - "l2_gas_index": 1, "library_call_gas_cost": { "call_contract_gas_cost": 1 }, - "sha256_process_block_gas_cost": { - "step_gas_cost": 1852, - "range_check_gas_cost": 65, - "bitwise_builtin_gas_cost": 1115, - "syscall_base_gas_cost": 1 - }, - "memory_hole_gas_cost": 10, - "nop_entry_point_offset": -1, - "range_check_gas_cost": 70, - "bitwise_builtin_gas_cost": 594, "replace_class_gas_cost": { - "step_gas_cost": 50, - "syscall_base_gas_cost": 1 + "syscall_base_gas_cost": 1, + "step_gas_cost": 50 + }, + "storage_read_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 50 + }, + "storage_write_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 50 + }, + "emit_event_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 10 + }, + "send_message_to_l1_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 50 }, "secp256k1_add_gas_cost": { - "range_check_gas_cost": 29, - "step_gas_cost": 406 + "step_gas_cost": 406, + "range_check_gas_cost": 29 }, "secp256k1_get_point_from_x_gas_cost": { - "memory_hole_gas_cost": 20, + "step_gas_cost": 391, "range_check_gas_cost": 30, - "step_gas_cost": 391 + "memory_hole_gas_cost": 20 }, "secp256k1_get_xy_gas_cost": { - "memory_hole_gas_cost": 40, + "step_gas_cost": 239, "range_check_gas_cost": 11, - "step_gas_cost": 239 + "memory_hole_gas_cost": 40 }, "secp256k1_mul_gas_cost": { - "memory_hole_gas_cost": 2, + "step_gas_cost": 76501, "range_check_gas_cost": 7045, - "step_gas_cost": 76501 + "memory_hole_gas_cost": 2 }, "secp256k1_new_gas_cost": { - "memory_hole_gas_cost": 40, + "step_gas_cost": 475, "range_check_gas_cost": 35, - "step_gas_cost": 475 + "memory_hole_gas_cost": 40 }, "secp256r1_add_gas_cost": { - "range_check_gas_cost": 57, - "step_gas_cost": 589 + "step_gas_cost": 589, + "range_check_gas_cost": 57 }, "secp256r1_get_point_from_x_gas_cost": { - "memory_hole_gas_cost": 20, + "step_gas_cost": 510, "range_check_gas_cost": 44, - "step_gas_cost": 510 + "memory_hole_gas_cost": 20 }, "secp256r1_get_xy_gas_cost": { - "memory_hole_gas_cost": 40, + "step_gas_cost": 241, "range_check_gas_cost": 11, - "step_gas_cost": 241 + "memory_hole_gas_cost": 40 }, "secp256r1_mul_gas_cost": { - "memory_hole_gas_cost": 2, + "step_gas_cost": 125340, "range_check_gas_cost": 13961, - "step_gas_cost": 125340 + "memory_hole_gas_cost": 2 }, "secp256r1_new_gas_cost": { - "memory_hole_gas_cost": 40, + "step_gas_cost": 594, "range_check_gas_cost": 49, - "step_gas_cost": 594 - }, - "send_message_to_l1_gas_cost": { - "step_gas_cost": 50, - "syscall_base_gas_cost": 1 + "memory_hole_gas_cost": 40 }, - "sierra_array_len_bound": 4294967296, - "step_gas_cost": 100, - "storage_read_gas_cost": { - "step_gas_cost": 50, - "syscall_base_gas_cost": 1 - }, - "storage_write_gas_cost": { - "step_gas_cost": 50, + "keccak_gas_cost": { "syscall_base_gas_cost": 1 }, - "stored_block_hash_buffer": 10, - "syscall_base_gas_cost": { - "step_gas_cost": 100 - }, - "transaction_gas_cost": { - "entry_point_gas_cost": 2, - "fee_transfer_gas_cost": 1, - "step_gas_cost": 100 + "keccak_round_cost_gas_cost": 180000, + "sha256_process_block_gas_cost": { + "step_gas_cost": 0, + "range_check_gas_cost": 0, + "syscall_base_gas_cost": 0 }, - "transfer_entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e", - "validate_declare_entry_point_selector": "0x289da278a8dc833409cabfdad1581e8e7d40e42dcaed693fa4008dcdb4963b3", - "validate_deploy_entry_point_selector": "0x36fcbf06cd96843058359e1a75928beacfac10727dab22a3972f0af8aa92895", - "validate_entry_point_selector": "0x162da33a4585851fe8d3af3c2a9c60b557814e221e0d4f30ff0b2189d9c7775", + "error_block_number_out_of_range": "Block number out of range", + "error_out_of_gas": "Out of gas", + "error_invalid_input_len": "Invalid input length", + "error_invalid_argument": "Invalid argument", + "validated": "VALID", + "l1_gas": "L1_GAS", + "l2_gas": "L2_GAS", + "l1_gas_index": 0, + "l2_gas_index": 1, "validate_rounding_consts": { "validate_block_number_rounding": 100, "validate_timestamp_rounding": 3600 - }, - "validated": "VALID" + } }, "os_resources": { "execute_syscalls": { "CallContract": { - "n_steps": 827, + "n_steps": 760, "builtin_instance_counter": { - "range_check_builtin": 15 + "range_check_builtin": 20 }, "n_memory_holes": 0 }, @@ -204,10 +201,10 @@ "n_memory_holes": 0 }, "Deploy": { - "n_steps": 1097, + "n_steps": 1012, "builtin_instance_counter": { "pedersen_builtin": 7, - "range_check_builtin": 18 + "range_check_builtin": 19 }, "n_memory_holes": 0 }, @@ -283,9 +280,9 @@ "n_memory_holes": 0 }, "LibraryCall": { - "n_steps": 818, + "n_steps": 751, "builtin_instance_counter": { - "range_check_builtin": 15 + "range_check_builtin": 20 }, "n_memory_holes": 0 }, @@ -304,89 +301,86 @@ "n_memory_holes": 0 }, "Secp256k1Add": { - "n_steps": 410, + "n_steps": 408, "builtin_instance_counter": { "range_check_builtin": 29 }, "n_memory_holes": 0 }, "Secp256k1GetPointFromX": { - "n_steps": 395, + "n_steps": 393, "builtin_instance_counter": { "range_check_builtin": 30 }, "n_memory_holes": 0 }, "Secp256k1GetXy": { - "n_steps": 207, + "n_steps": 205, "builtin_instance_counter": { "range_check_builtin": 11 }, "n_memory_holes": 0 }, "Secp256k1Mul": { - "n_steps": 76505, + "n_steps": 76503, "builtin_instance_counter": { "range_check_builtin": 7045 }, "n_memory_holes": 0 }, "Secp256k1New": { - "n_steps": 461, + "n_steps": 459, "builtin_instance_counter": { "range_check_builtin": 35 }, "n_memory_holes": 0 }, "Secp256r1Add": { - "n_steps": 593, + "n_steps": 591, "builtin_instance_counter": { "range_check_builtin": 57 }, "n_memory_holes": 0 }, "Secp256r1GetPointFromX": { - "n_steps": 514, + "n_steps": 512, "builtin_instance_counter": { "range_check_builtin": 44 }, "n_memory_holes": 0 }, "Secp256r1GetXy": { - "n_steps": 209, + "n_steps": 207, "builtin_instance_counter": { "range_check_builtin": 11 }, "n_memory_holes": 0 }, "Secp256r1Mul": { - "n_steps": 125344, + "n_steps": 125342, "builtin_instance_counter": { "range_check_builtin": 13961 }, "n_memory_holes": 0 }, "Secp256r1New": { - "n_steps": 580, + "n_steps": 578, "builtin_instance_counter": { "range_check_builtin": 49 }, "n_memory_holes": 0 }, "SendMessageToL1": { - "n_steps": 141, + "n_steps": 139, "builtin_instance_counter": { "range_check_builtin": 1 }, "n_memory_holes": 0 }, "Sha256ProcessBlock": { - "n_steps": 1855, - "builtin_instance_counter": { - "range_check_builtin": 65, - "bitwise_builtin": 1115 - }, - "n_memory_holes": 0 + "builtin_instance_counter": {}, + "n_memory_holes": 0, + "n_steps": 0 }, "StorageRead": { "n_steps": 87, @@ -405,12 +399,12 @@ }, "execute_txs_inner": { "Declare": { - "deprecated_resources": { + "resources": { "constant": { - "n_steps": 2973, + "n_steps": 2839, "builtin_instance_counter": { "pedersen_builtin": 16, - "range_check_builtin": 53 + "range_check_builtin": 63 }, "n_memory_holes": 0 }, @@ -420,13 +414,12 @@ "n_memory_holes": 0 } }, - "resources": { + "deprecated_resources": { "constant": { - "n_steps": 3079, + "n_steps": 2839, "builtin_instance_counter": { - "pedersen_builtin": 4, - "range_check_builtin": 58, - "poseidon_builtin": 10 + "pedersen_builtin": 16, + "range_check_builtin": 63 }, "n_memory_holes": 0 }, @@ -438,12 +431,12 @@ } }, "DeployAccount": { - "deprecated_resources": { + "resources": { "constant": { - "n_steps": 4015, + "n_steps": 3792, "builtin_instance_counter": { "pedersen_builtin": 23, - "range_check_builtin": 72 + "range_check_builtin": 83 }, "n_memory_holes": 0 }, @@ -455,13 +448,12 @@ "n_memory_holes": 0 } }, - "resources": { + "deprecated_resources": { "constant": { - "n_steps": 4137, + "n_steps": 3792, "builtin_instance_counter": { - "pedersen_builtin": 11, - "range_check_builtin": 77, - "poseidon_builtin": 10 + "pedersen_builtin": 23, + "range_check_builtin": 83 }, "n_memory_holes": 0 }, @@ -475,12 +467,12 @@ } }, "InvokeFunction": { - "deprecated_resources": { + "resources": { "constant": { - "n_steps": 3763, + "n_steps": 3546, "builtin_instance_counter": { "pedersen_builtin": 14, - "range_check_builtin": 69 + "range_check_builtin": 80 }, "n_memory_holes": 0 }, @@ -492,13 +484,12 @@ "n_memory_holes": 0 } }, - "resources": { + "deprecated_resources": { "constant": { - "n_steps": 3904, + "n_steps": 3546, "builtin_instance_counter": { - "pedersen_builtin": 4, - "range_check_builtin": 74, - "poseidon_builtin": 11 + "pedersen_builtin": 14, + "range_check_builtin": 80 }, "n_memory_holes": 0 }, @@ -512,12 +503,12 @@ } }, "L1Handler": { - "deprecated_resources": { + "resources": { "constant": { - "n_steps": 1233, + "n_steps": 1146, "builtin_instance_counter": { "pedersen_builtin": 11, - "range_check_builtin": 16 + "range_check_builtin": 17 }, "n_memory_holes": 0 }, @@ -529,10 +520,13 @@ "n_memory_holes": 0 } }, - "resources": { + "deprecated_resources": { "constant": { - "n_steps": 0, - "builtin_instance_counter": {}, + "n_steps": 1146, + "builtin_instance_counter": { + "pedersen_builtin": 11, + "range_check_builtin": 17 + }, "n_memory_holes": 0 }, "calldata_factor": { @@ -546,18 +540,16 @@ } }, "compute_os_kzg_commitment_info": { - "n_steps": 113, - "builtin_instance_counter": { - "range_check_builtin": 17 - }, + "n_steps": 0, + "builtin_instance_counter": {}, "n_memory_holes": 0 } }, "validate_max_n_steps": 1000000, "vm_resource_fee_cost": { "add_mod_builtin": [ - 4, - 100 + 0, + 1 ], "bitwise_builtin": [ 16, @@ -576,8 +568,8 @@ 100 ], "mul_mod_builtin": [ - 4, - 100 + 0, + 1 ], "n_steps": [ 25, @@ -600,8 +592,8 @@ 100 ], "range_check96_builtin": [ - 4, - 100 + 0, + 1 ] } } From 358088058052763d3ab27f9d78217ae64e2ecf3e Mon Sep 17 00:00:00 2001 From: Avi Cohen Date: Mon, 15 Jul 2024 17:29:25 +0300 Subject: [PATCH 2/3] Remove output_builting from runner --- crates/blockifier/src/execution/entry_point_execution.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/blockifier/src/execution/entry_point_execution.rs b/crates/blockifier/src/execution/entry_point_execution.rs index 8f726cd0f6..d37f55d6a0 100644 --- a/crates/blockifier/src/execution/entry_point_execution.rs +++ b/crates/blockifier/src/execution/entry_point_execution.rs @@ -157,7 +157,6 @@ pub fn initialize_execution_context<'a>( BuiltinName::bitwise, BuiltinName::ec_op, BuiltinName::ecdsa, - BuiltinName::output, BuiltinName::pedersen, BuiltinName::poseidon, BuiltinName::range_check, From db5ec51cce88c5b536b0ed9fa93d19d1e94adaa6 Mon Sep 17 00:00:00 2001 From: avi-starkware Date: Tue, 16 Jul 2024 16:24:43 +0300 Subject: [PATCH 3/3] fix: offset segment arena instance counter for older vm versions (#2090) --- Cargo.toml | 8 ++++---- crates/blockifier/resources/versioned_constants.json | 1 + .../resources/versioned_constants_13_0.json | 1 + .../resources/versioned_constants_13_1.json | 1 + .../resources/versioned_constants_13_1_1.json | 1 + .../execution/deprecated_entry_point_execution.rs | 12 ++++++++++-- .../src/execution/entry_point_execution.rs | 11 +++++++++-- crates/blockifier/src/execution/execution_utils.rs | 2 ++ crates/blockifier/src/versioned_constants.rs | 5 +++++ 9 files changed, 34 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ad5ada4b7f..103fa3da93 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,10 +20,10 @@ ark-secp256k1 = "0.4.0" ark-secp256r1 = "0.4.0" assert_matches = "1.5.0" cached = "0.44.0" -cairo-lang-casm = "2.7.0-rc.1" -cairo-lang-runner = "2.7.0-rc.1" -cairo-lang-starknet-classes = "2.7.0-rc.1" -cairo-lang-utils = "2.7.0-rc.1" +cairo-lang-casm = "2.7.0-rc.2" +cairo-lang-runner = "2.7.0-rc.2" +cairo-lang-starknet-classes = "2.7.0-rc.2" +cairo-lang-utils = "2.7.0-rc.2" cairo-vm = "1.0.0-rc5" criterion = "0.3" derive_more = "0.99.17" diff --git a/crates/blockifier/resources/versioned_constants.json b/crates/blockifier/resources/versioned_constants.json index 791dac8b9b..48832c863d 100644 --- a/crates/blockifier/resources/versioned_constants.json +++ b/crates/blockifier/resources/versioned_constants.json @@ -24,6 +24,7 @@ ] }, "max_recursion_depth": 50, + "count_segment_arena_cells_not_instances": true, "os_constants": { "nop_entry_point_offset": -1, "entry_point_type_external": 0, diff --git a/crates/blockifier/resources/versioned_constants_13_0.json b/crates/blockifier/resources/versioned_constants_13_0.json index 1531f6fc13..ff8f797307 100644 --- a/crates/blockifier/resources/versioned_constants_13_0.json +++ b/crates/blockifier/resources/versioned_constants_13_0.json @@ -5,6 +5,7 @@ }, "invoke_tx_max_n_steps": 3000000, "max_recursion_depth": 50, + "count_segment_arena_cells_not_instances": true, "os_constants": { "nop_entry_point_offset": -1, "entry_point_type_external": 0, diff --git a/crates/blockifier/resources/versioned_constants_13_1.json b/crates/blockifier/resources/versioned_constants_13_1.json index 4e28f7b711..0b8de5265d 100644 --- a/crates/blockifier/resources/versioned_constants_13_1.json +++ b/crates/blockifier/resources/versioned_constants_13_1.json @@ -24,6 +24,7 @@ ] }, "max_recursion_depth": 50, + "count_segment_arena_cells_not_instances": true, "os_constants": { "nop_entry_point_offset": -1, "entry_point_type_external": 0, diff --git a/crates/blockifier/resources/versioned_constants_13_1_1.json b/crates/blockifier/resources/versioned_constants_13_1_1.json index 791dac8b9b..48832c863d 100644 --- a/crates/blockifier/resources/versioned_constants_13_1_1.json +++ b/crates/blockifier/resources/versioned_constants_13_1_1.json @@ -24,6 +24,7 @@ ] }, "max_recursion_depth": 50, + "count_segment_arena_cells_not_instances": true, "os_constants": { "nop_entry_point_offset": -1, "entry_point_type_external": 0, diff --git a/crates/blockifier/src/execution/deprecated_entry_point_execution.rs b/crates/blockifier/src/execution/deprecated_entry_point_execution.rs index 73b2c7b855..7442918ca4 100644 --- a/crates/blockifier/src/execution/deprecated_entry_point_execution.rs +++ b/crates/blockifier/src/execution/deprecated_entry_point_execution.rs @@ -1,3 +1,4 @@ +use cairo_vm::types::builtin_name::BuiltinName; use cairo_vm::types::layout_name::LayoutName; use cairo_vm::types::relocatable::{MaybeRelocatable, Relocatable}; use cairo_vm::vm::errors::vm_errors::VirtualMachineError; @@ -6,6 +7,7 @@ use starknet_api::core::EntryPointSelector; use starknet_api::deprecated_contract_class::EntryPointType; use starknet_api::hash::StarkHash; +use super::execution_utils::SEGMENT_ARENA_BUILTIN_SIZE; use crate::abi::abi_utils::selector_from_name; use crate::abi::constants::{CONSTRUCTOR_ENTRY_POINT_NAME, DEFAULT_ENTRY_POINT_SELECTOR}; use crate::execution::call_info::{CallExecution, CallInfo}; @@ -227,12 +229,18 @@ pub fn finalize_execution( // Take into account the VM execution resources of the current call, without inner calls. // Has to happen after marking holes in segments as accessed. - let vm_resources_without_inner_calls = runner + let mut vm_resources_without_inner_calls = runner .get_execution_resources() .map_err(VirtualMachineError::RunnerError)? .filter_unused_builtins(); - *syscall_handler.resources += &vm_resources_without_inner_calls; let versioned_constants = syscall_handler.context.versioned_constants(); + if versioned_constants.count_segment_arena_cells_not_instances { + vm_resources_without_inner_calls + .builtin_instance_counter + .get_mut(&BuiltinName::segment_arena) + .map_or_else(|| {}, |val| *val *= SEGMENT_ARENA_BUILTIN_SIZE); + } + *syscall_handler.resources += &vm_resources_without_inner_calls; // Take into account the syscall resources of the current call. *syscall_handler.resources += &versioned_constants .get_additional_os_syscall_resources(&syscall_handler.syscall_counter)?; diff --git a/crates/blockifier/src/execution/entry_point_execution.rs b/crates/blockifier/src/execution/entry_point_execution.rs index d37f55d6a0..372ef68185 100644 --- a/crates/blockifier/src/execution/entry_point_execution.rs +++ b/crates/blockifier/src/execution/entry_point_execution.rs @@ -17,6 +17,7 @@ use crate::execution::entry_point::{ use crate::execution::errors::{EntryPointExecutionError, PostExecutionError, PreExecutionError}; use crate::execution::execution_utils::{ read_execution_retdata, write_felt, write_maybe_relocatable, Args, ReadOnlySegments, + SEGMENT_ARENA_BUILTIN_SIZE, }; use crate::execution::syscalls::hint_processor::SyscallHintProcessor; use crate::state::state_api::State; @@ -318,12 +319,18 @@ pub fn finalize_execution( // Take into account the VM execution resources of the current call, without inner calls. // Has to happen after marking holes in segments as accessed. - let vm_resources_without_inner_calls = runner + let mut vm_resources_without_inner_calls = runner .get_execution_resources() .map_err(VirtualMachineError::RunnerError)? .filter_unused_builtins(); - *syscall_handler.resources += &vm_resources_without_inner_calls; let versioned_constants = syscall_handler.context.versioned_constants(); + if versioned_constants.count_segment_arena_cells_not_instances { + vm_resources_without_inner_calls + .builtin_instance_counter + .get_mut(&BuiltinName::segment_arena) + .map_or_else(|| {}, |val| *val *= SEGMENT_ARENA_BUILTIN_SIZE); + } + *syscall_handler.resources += &vm_resources_without_inner_calls; // Take into account the syscall resources of the current call. *syscall_handler.resources += &versioned_constants .get_additional_os_syscall_resources(&syscall_handler.syscall_counter)?; diff --git a/crates/blockifier/src/execution/execution_utils.rs b/crates/blockifier/src/execution/execution_utils.rs index 326e1a6337..8934b133dc 100644 --- a/crates/blockifier/src/execution/execution_utils.rs +++ b/crates/blockifier/src/execution/execution_utils.rs @@ -34,6 +34,8 @@ use crate::transaction::objects::TransactionInfo; pub type Args = Vec; +pub const SEGMENT_ARENA_BUILTIN_SIZE: usize = 3; + /// Executes a specific call to a contract entry point and returns its output. pub fn execute_entry_point_call( call: CallEntryPoint, diff --git a/crates/blockifier/src/versioned_constants.rs b/crates/blockifier/src/versioned_constants.rs index 0114144755..699e17f886 100644 --- a/crates/blockifier/src/versioned_constants.rs +++ b/crates/blockifier/src/versioned_constants.rs @@ -48,6 +48,11 @@ pub struct VersionedConstants { pub l2_resource_gas_costs: L2ResourceGasCosts, pub max_recursion_depth: usize, pub validate_max_n_steps: u32, + // BACKWARD COMPATIBILITY: If true, the segment_arena builtin instance counter will be + // multiplied by 3. This offsets a bug in the old vm where the counter counted the number of + // cells used by instances of the builtin, instead of the number of instances. + #[serde(default)] + pub count_segment_arena_cells_not_instances: bool, // Transactions settings. #[serde(default)]