From 1fb5bb803487b60e510a7070f030e818888825c1 Mon Sep 17 00:00:00 2001 From: Yonatan-Starkware Date: Sun, 8 Dec 2024 10:44:03 +0200 Subject: [PATCH] chore(blockifier): split builtin gas costs from base gas costs --- .../resources/versioned_constants_0_13_0.json | 49 ++++---- .../resources/versioned_constants_0_13_1.json | 49 ++++---- .../versioned_constants_0_13_1_1.json | 49 ++++---- .../resources/versioned_constants_0_13_2.json | 51 ++++---- .../versioned_constants_0_13_2_1.json | 51 ++++---- .../resources/versioned_constants_0_13_3.json | 51 ++++---- .../resources/versioned_constants_0_13_4.json | 76 ++++++------ .../src/execution/entry_point_execution.rs | 12 +- .../execution/native/entry_point_execution.rs | 12 +- crates/blockifier/src/versioned_constants.rs | 115 +++++++++++------- .../src/versioned_constants_test.rs | 7 +- 11 files changed, 266 insertions(+), 256 deletions(-) diff --git a/crates/blockifier/resources/versioned_constants_0_13_0.json b/crates/blockifier/resources/versioned_constants_0_13_0.json index 1407a6a7fa..253c78fbd9 100644 --- a/crates/blockifier/resources/versioned_constants_0_13_0.json +++ b/crates/blockifier/resources/versioned_constants_0_13_0.json @@ -73,15 +73,17 @@ "default_entry_point_selector": 0, "stored_block_hash_buffer": 10, "step_gas_cost": 100, - "range_check_gas_cost": 70, - "keccak_builtin_gas_cost": 0, - "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, - "ecdsa_gas_cost": 0, + "builtin_gas_costs": { + "range_check": 70, + "keccak": 0, + "pedersen": 0, + "bitwise": 0, + "ecop": 0, + "poseidon": 0, + "add_mod": 0, + "mul_mod": 0, + "ecdsa": 0 + }, "memory_hole_gas_cost": 10, "os_contract_addresses": { "block_hash_contract_address": 1, @@ -101,11 +103,6 @@ "entry_point_initial_budget": 1, "step_gas_cost": 600 }, - "transaction_gas_cost": { - "entry_point_initial_budget": 2, - "fee_transfer_gas_cost": 1, - "step_gas_cost": 1100 - }, "error_block_number_out_of_range": "Block number out of range", "error_out_of_gas": "Out of gas", "error_entry_point_failed": "ENTRYPOINT_FAILED", @@ -167,48 +164,48 @@ }, "secp256k1_add": { "step_gas_cost": 406, - "range_check_gas_cost": 29 + "range_check": 29 }, "secp256k1_get_point_from_x": { "step_gas_cost": 391, - "range_check_gas_cost": 30, + "range_check": 30, "memory_hole_gas_cost": 20 }, "secp256k1_get_xy": { "step_gas_cost": 239, - "range_check_gas_cost": 11, + "range_check": 11, "memory_hole_gas_cost": 40 }, "secp256k1_mul": { "step_gas_cost": 76401, - "range_check_gas_cost": 7045 + "range_check": 7045 }, "secp256k1_new": { "step_gas_cost": 475, - "range_check_gas_cost": 35, + "range_check": 35, "memory_hole_gas_cost": 40 }, "secp256r1_add": { "step_gas_cost": 589, - "range_check_gas_cost": 57 + "range_check": 57 }, "secp256r1_get_point_from_x": { "step_gas_cost": 510, - "range_check_gas_cost": 44, + "range_check": 44, "memory_hole_gas_cost": 20 }, "secp256r1_get_xy": { "step_gas_cost": 241, - "range_check_gas_cost": 11, + "range_check": 11, "memory_hole_gas_cost": 40 }, "secp256r1_mul": { "step_gas_cost": 125240, - "range_check_gas_cost": 13961 + "range_check": 13961 }, "secp256r1_new": { "step_gas_cost": 594, - "range_check_gas_cost": 49, + "range_check": 49, "memory_hole_gas_cost": 40 }, "keccak": { @@ -217,7 +214,7 @@ "keccak_round_cost": 180000, "sha256_process_block": { "step_gas_cost": 0, - "range_check_gas_cost": 0, + "range_check": 0, "syscall_base_gas_cost": 0 } } @@ -620,4 +617,4 @@ 1000 ] } -} +} \ No newline at end of file diff --git a/crates/blockifier/resources/versioned_constants_0_13_1.json b/crates/blockifier/resources/versioned_constants_0_13_1.json index 56c7cc5203..4ff60452d6 100644 --- a/crates/blockifier/resources/versioned_constants_0_13_1.json +++ b/crates/blockifier/resources/versioned_constants_0_13_1.json @@ -73,15 +73,17 @@ "default_entry_point_selector": 0, "stored_block_hash_buffer": 10, "step_gas_cost": 100, - "range_check_gas_cost": 70, - "keccak_builtin_gas_cost": 0, - "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, - "ecdsa_gas_cost": 0, + "builtin_gas_costs": { + "range_check": 70, + "keccak": 0, + "pedersen": 0, + "bitwise": 0, + "ecop": 0, + "poseidon": 0, + "add_mod": 0, + "mul_mod": 0, + "ecdsa": 0 + }, "os_contract_addresses": { "block_hash_contract_address": 1, "alias_contract_address": 2, @@ -101,11 +103,6 @@ "entry_point_initial_budget": 1, "step_gas_cost": 600 }, - "transaction_gas_cost": { - "entry_point_initial_budget": 2, - "fee_transfer_gas_cost": 1, - "step_gas_cost": 1100 - }, "error_block_number_out_of_range": "Block number out of range", "error_out_of_gas": "Out of gas", "error_entry_point_failed": "ENTRYPOINT_FAILED", @@ -171,50 +168,50 @@ }, "secp256k1_add": { "step_gas_cost": 406, - "range_check_gas_cost": 29 + "range_check": 29 }, "secp256k1_get_point_from_x": { "step_gas_cost": 391, - "range_check_gas_cost": 30, + "range_check": 30, "memory_hole_gas_cost": 20 }, "secp256k1_get_xy": { "step_gas_cost": 239, - "range_check_gas_cost": 11, + "range_check": 11, "memory_hole_gas_cost": 40 }, "secp256k1_mul": { "step_gas_cost": 76501, - "range_check_gas_cost": 7045, + "range_check": 7045, "memory_hole_gas_cost": 2 }, "secp256k1_new": { "step_gas_cost": 475, - "range_check_gas_cost": 35, + "range_check": 35, "memory_hole_gas_cost": 40 }, "secp256r1_add": { "step_gas_cost": 589, - "range_check_gas_cost": 57 + "range_check": 57 }, "secp256r1_get_point_from_x": { "step_gas_cost": 510, - "range_check_gas_cost": 44, + "range_check": 44, "memory_hole_gas_cost": 20 }, "secp256r1_get_xy": { "step_gas_cost": 241, - "range_check_gas_cost": 11, + "range_check": 11, "memory_hole_gas_cost": 40 }, "secp256r1_mul": { "step_gas_cost": 125340, - "range_check_gas_cost": 13961, + "range_check": 13961, "memory_hole_gas_cost": 2 }, "secp256r1_new": { "step_gas_cost": 594, - "range_check_gas_cost": 49, + "range_check": 49, "memory_hole_gas_cost": 40 }, "keccak": { @@ -223,7 +220,7 @@ "keccak_round_cost": 180000, "sha256_process_block": { "step_gas_cost": 0, - "range_check_gas_cost": 0, + "range_check": 0, "syscall_base_gas_cost": 0 } } @@ -656,4 +653,4 @@ 10000 ] } -} +} \ No newline at end of file diff --git a/crates/blockifier/resources/versioned_constants_0_13_1_1.json b/crates/blockifier/resources/versioned_constants_0_13_1_1.json index ede36b46e0..eab722f385 100644 --- a/crates/blockifier/resources/versioned_constants_0_13_1_1.json +++ b/crates/blockifier/resources/versioned_constants_0_13_1_1.json @@ -73,15 +73,17 @@ "default_entry_point_selector": 0, "stored_block_hash_buffer": 10, "step_gas_cost": 100, - "range_check_gas_cost": 70, - "keccak_builtin_gas_cost": 0, - "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, - "ecdsa_gas_cost": 0, + "builtin_gas_costs": { + "range_check": 70, + "keccak": 0, + "pedersen": 0, + "bitwise": 0, + "ecop": 0, + "poseidon": 0, + "add_mod": 0, + "mul_mod": 0, + "ecdsa": 0 + }, "memory_hole_gas_cost": 10, "os_contract_addresses": { "block_hash_contract_address": 1, @@ -101,11 +103,6 @@ "entry_point_initial_budget": 1, "step_gas_cost": 600 }, - "transaction_gas_cost": { - "entry_point_initial_budget": 2, - "fee_transfer_gas_cost": 1, - "step_gas_cost": 1100 - }, "error_block_number_out_of_range": "Block number out of range", "error_out_of_gas": "Out of gas", "error_entry_point_failed": "ENTRYPOINT_FAILED", @@ -171,50 +168,50 @@ }, "secp256k1_add": { "step_gas_cost": 406, - "range_check_gas_cost": 29 + "range_check": 29 }, "secp256k1_get_point_from_x": { "step_gas_cost": 391, - "range_check_gas_cost": 30, + "range_check": 30, "memory_hole_gas_cost": 20 }, "secp256k1_get_xy": { "step_gas_cost": 239, - "range_check_gas_cost": 11, + "range_check": 11, "memory_hole_gas_cost": 40 }, "secp256k1_mul": { "step_gas_cost": 76501, - "range_check_gas_cost": 7045, + "range_check": 7045, "memory_hole_gas_cost": 2 }, "secp256k1_new": { "step_gas_cost": 475, - "range_check_gas_cost": 35, + "range_check": 35, "memory_hole_gas_cost": 40 }, "secp256r1_add": { "step_gas_cost": 589, - "range_check_gas_cost": 57 + "range_check": 57 }, "secp256r1_get_point_from_x": { "step_gas_cost": 510, - "range_check_gas_cost": 44, + "range_check": 44, "memory_hole_gas_cost": 20 }, "secp256r1_get_xy": { "step_gas_cost": 241, - "range_check_gas_cost": 11, + "range_check": 11, "memory_hole_gas_cost": 40 }, "secp256r1_mul": { "step_gas_cost": 125340, - "range_check_gas_cost": 13961, + "range_check": 13961, "memory_hole_gas_cost": 2 }, "secp256r1_new": { "step_gas_cost": 594, - "range_check_gas_cost": 49, + "range_check": 49, "memory_hole_gas_cost": 40 }, "keccak": { @@ -223,7 +220,7 @@ "keccak_round_cost": 180000, "sha256_process_block": { "step_gas_cost": 0, - "range_check_gas_cost": 0, + "range_check": 0, "syscall_base_gas_cost": 0 } } @@ -656,4 +653,4 @@ 10000 ] } -} +} \ No newline at end of file diff --git a/crates/blockifier/resources/versioned_constants_0_13_2.json b/crates/blockifier/resources/versioned_constants_0_13_2.json index 1366040075..62e106ba08 100644 --- a/crates/blockifier/resources/versioned_constants_0_13_2.json +++ b/crates/blockifier/resources/versioned_constants_0_13_2.json @@ -93,26 +93,23 @@ "alias_contract_address": 2, "reserved_contract_address": 3 }, - "range_check_gas_cost": 70, - "keccak_builtin_gas_cost": 0, - "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, - "ecdsa_gas_cost": 0, + "builtin_gas_costs": { + "range_check": 70, + "keccak": 0, + "pedersen": 0, + "bitwise": 594, + "ecop": 0, + "poseidon": 0, + "add_mod": 0, + "mul_mod": 0, + "ecdsa": 0 + }, "sierra_array_len_bound": 4294967296, "step_gas_cost": 100, "stored_block_hash_buffer": 10, "syscall_base_gas_cost": { "step_gas_cost": 100 }, - "transaction_gas_cost": { - "entry_point_initial_budget": 2, - "fee_transfer_gas_cost": 1, - "step_gas_cost": 1100 - }, "transfer_entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e", "validate_declare_entry_point_selector": "0x289da278a8dc833409cabfdad1581e8e7d40e42dcaed693fa4008dcdb4963b3", "validate_deploy_entry_point_selector": "0x36fcbf06cd96843058359e1a75928beacfac10727dab22a3972f0af8aa92895", @@ -156,8 +153,8 @@ }, "sha256_process_block": { "step_gas_cost": 1852, - "range_check_gas_cost": 65, - "bitwise_builtin_gas_cost": 1115, + "range_check": 65, + "bitwise": 1115, "syscall_base_gas_cost": 1 }, "replace_class": { @@ -165,51 +162,51 @@ "syscall_base_gas_cost": 1 }, "secp256k1_add": { - "range_check_gas_cost": 29, + "range_check": 29, "step_gas_cost": 406 }, "secp256k1_get_point_from_x": { "memory_hole_gas_cost": 20, - "range_check_gas_cost": 30, + "range_check": 30, "step_gas_cost": 391 }, "secp256k1_get_xy": { "memory_hole_gas_cost": 40, - "range_check_gas_cost": 11, + "range_check": 11, "step_gas_cost": 239 }, "secp256k1_mul": { "memory_hole_gas_cost": 2, - "range_check_gas_cost": 7045, + "range_check": 7045, "step_gas_cost": 76501 }, "secp256k1_new": { "memory_hole_gas_cost": 40, - "range_check_gas_cost": 35, + "range_check": 35, "step_gas_cost": 475 }, "secp256r1_add": { - "range_check_gas_cost": 57, + "range_check": 57, "step_gas_cost": 589 }, "secp256r1_get_point_from_x": { "memory_hole_gas_cost": 20, - "range_check_gas_cost": 44, + "range_check": 44, "step_gas_cost": 510 }, "secp256r1_get_xy": { "memory_hole_gas_cost": 40, - "range_check_gas_cost": 11, + "range_check": 11, "step_gas_cost": 241 }, "secp256r1_mul": { "memory_hole_gas_cost": 2, - "range_check_gas_cost": 13961, + "range_check": 13961, "step_gas_cost": 125340 }, "secp256r1_new": { "memory_hole_gas_cost": 40, - "range_check_gas_cost": 49, + "range_check": 49, "step_gas_cost": 594 }, "send_message_to_l1": { @@ -663,4 +660,4 @@ 10000 ] } -} +} \ No newline at end of file diff --git a/crates/blockifier/resources/versioned_constants_0_13_2_1.json b/crates/blockifier/resources/versioned_constants_0_13_2_1.json index aecdba873a..345d933016 100644 --- a/crates/blockifier/resources/versioned_constants_0_13_2_1.json +++ b/crates/blockifier/resources/versioned_constants_0_13_2_1.json @@ -93,26 +93,23 @@ "alias_contract_address": 2, "reserved_contract_address": 3 }, - "range_check_gas_cost": 70, - "keccak_builtin_gas_cost": 0, - "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, - "ecdsa_gas_cost": 0, + "builtin_gas_costs": { + "range_check": 70, + "keccak": 0, + "pedersen": 0, + "bitwise": 594, + "ecop": 0, + "poseidon": 0, + "add_mod": 0, + "mul_mod": 0, + "ecdsa": 0 + }, "sierra_array_len_bound": 4294967296, "step_gas_cost": 100, "stored_block_hash_buffer": 10, "syscall_base_gas_cost": { "step_gas_cost": 100 }, - "transaction_gas_cost": { - "entry_point_initial_budget": 2, - "fee_transfer_gas_cost": 1, - "step_gas_cost": 1100 - }, "transfer_entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e", "validate_declare_entry_point_selector": "0x289da278a8dc833409cabfdad1581e8e7d40e42dcaed693fa4008dcdb4963b3", "validate_deploy_entry_point_selector": "0x36fcbf06cd96843058359e1a75928beacfac10727dab22a3972f0af8aa92895", @@ -156,8 +153,8 @@ }, "sha256_process_block": { "step_gas_cost": 1852, - "range_check_gas_cost": 65, - "bitwise_builtin_gas_cost": 1115, + "range_check": 65, + "bitwise": 1115, "syscall_base_gas_cost": 1 }, "replace_class": { @@ -165,51 +162,51 @@ "syscall_base_gas_cost": 1 }, "secp256k1_add": { - "range_check_gas_cost": 29, + "range_check": 29, "step_gas_cost": 406 }, "secp256k1_get_point_from_x": { "memory_hole_gas_cost": 20, - "range_check_gas_cost": 30, + "range_check": 30, "step_gas_cost": 391 }, "secp256k1_get_xy": { "memory_hole_gas_cost": 40, - "range_check_gas_cost": 11, + "range_check": 11, "step_gas_cost": 239 }, "secp256k1_mul": { "memory_hole_gas_cost": 2, - "range_check_gas_cost": 7045, + "range_check": 7045, "step_gas_cost": 76501 }, "secp256k1_new": { "memory_hole_gas_cost": 40, - "range_check_gas_cost": 35, + "range_check": 35, "step_gas_cost": 475 }, "secp256r1_add": { - "range_check_gas_cost": 57, + "range_check": 57, "step_gas_cost": 589 }, "secp256r1_get_point_from_x": { "memory_hole_gas_cost": 20, - "range_check_gas_cost": 44, + "range_check": 44, "step_gas_cost": 510 }, "secp256r1_get_xy": { "memory_hole_gas_cost": 40, - "range_check_gas_cost": 11, + "range_check": 11, "step_gas_cost": 241 }, "secp256r1_mul": { "memory_hole_gas_cost": 2, - "range_check_gas_cost": 13961, + "range_check": 13961, "step_gas_cost": 125340 }, "secp256r1_new": { "memory_hole_gas_cost": 40, - "range_check_gas_cost": 49, + "range_check": 49, "step_gas_cost": 594 }, "send_message_to_l1": { @@ -663,4 +660,4 @@ 10000 ] } -} +} \ No newline at end of file diff --git a/crates/blockifier/resources/versioned_constants_0_13_3.json b/crates/blockifier/resources/versioned_constants_0_13_3.json index aecdba873a..345d933016 100644 --- a/crates/blockifier/resources/versioned_constants_0_13_3.json +++ b/crates/blockifier/resources/versioned_constants_0_13_3.json @@ -93,26 +93,23 @@ "alias_contract_address": 2, "reserved_contract_address": 3 }, - "range_check_gas_cost": 70, - "keccak_builtin_gas_cost": 0, - "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, - "ecdsa_gas_cost": 0, + "builtin_gas_costs": { + "range_check": 70, + "keccak": 0, + "pedersen": 0, + "bitwise": 594, + "ecop": 0, + "poseidon": 0, + "add_mod": 0, + "mul_mod": 0, + "ecdsa": 0 + }, "sierra_array_len_bound": 4294967296, "step_gas_cost": 100, "stored_block_hash_buffer": 10, "syscall_base_gas_cost": { "step_gas_cost": 100 }, - "transaction_gas_cost": { - "entry_point_initial_budget": 2, - "fee_transfer_gas_cost": 1, - "step_gas_cost": 1100 - }, "transfer_entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e", "validate_declare_entry_point_selector": "0x289da278a8dc833409cabfdad1581e8e7d40e42dcaed693fa4008dcdb4963b3", "validate_deploy_entry_point_selector": "0x36fcbf06cd96843058359e1a75928beacfac10727dab22a3972f0af8aa92895", @@ -156,8 +153,8 @@ }, "sha256_process_block": { "step_gas_cost": 1852, - "range_check_gas_cost": 65, - "bitwise_builtin_gas_cost": 1115, + "range_check": 65, + "bitwise": 1115, "syscall_base_gas_cost": 1 }, "replace_class": { @@ -165,51 +162,51 @@ "syscall_base_gas_cost": 1 }, "secp256k1_add": { - "range_check_gas_cost": 29, + "range_check": 29, "step_gas_cost": 406 }, "secp256k1_get_point_from_x": { "memory_hole_gas_cost": 20, - "range_check_gas_cost": 30, + "range_check": 30, "step_gas_cost": 391 }, "secp256k1_get_xy": { "memory_hole_gas_cost": 40, - "range_check_gas_cost": 11, + "range_check": 11, "step_gas_cost": 239 }, "secp256k1_mul": { "memory_hole_gas_cost": 2, - "range_check_gas_cost": 7045, + "range_check": 7045, "step_gas_cost": 76501 }, "secp256k1_new": { "memory_hole_gas_cost": 40, - "range_check_gas_cost": 35, + "range_check": 35, "step_gas_cost": 475 }, "secp256r1_add": { - "range_check_gas_cost": 57, + "range_check": 57, "step_gas_cost": 589 }, "secp256r1_get_point_from_x": { "memory_hole_gas_cost": 20, - "range_check_gas_cost": 44, + "range_check": 44, "step_gas_cost": 510 }, "secp256r1_get_xy": { "memory_hole_gas_cost": 40, - "range_check_gas_cost": 11, + "range_check": 11, "step_gas_cost": 241 }, "secp256r1_mul": { "memory_hole_gas_cost": 2, - "range_check_gas_cost": 13961, + "range_check": 13961, "step_gas_cost": 125340 }, "secp256r1_new": { "memory_hole_gas_cost": 40, - "range_check_gas_cost": 49, + "range_check": 49, "step_gas_cost": 594 }, "send_message_to_l1": { @@ -663,4 +660,4 @@ 10000 ] } -} +} \ No newline at end of file diff --git a/crates/blockifier/resources/versioned_constants_0_13_4.json b/crates/blockifier/resources/versioned_constants_0_13_4.json index dbb15ca39d..75f7c8a1b2 100644 --- a/crates/blockifier/resources/versioned_constants_0_13_4.json +++ b/crates/blockifier/resources/versioned_constants_0_13_4.json @@ -91,27 +91,23 @@ "alias_contract_address": 2, "reserved_contract_address": 3 }, - "range_check_gas_cost": 70, - "keccak_builtin_gas_cost": 136189, - "pedersen_gas_cost": 4050, - "bitwise_builtin_gas_cost": 583, - "ecop_gas_cost": 4085, - "poseidon_gas_cost": 491, - "add_mod_gas_cost": 230, - "mul_mod_gas_cost": 604, - "ecdsa_gas_cost": 10561, + "builtin_gas_costs": { + "range_check": 70, + "keccak": 136189, + "pedersen": 4050, + "bitwise": 583, + "ecop": 4085, + "poseidon": 491, + "add_mod": 230, + "mul_mod": 604, + "ecdsa": 10561 + }, "sierra_array_len_bound": 4294967296, "step_gas_cost": 100, "stored_block_hash_buffer": 10, "syscall_base_gas_cost": { "step_gas_cost": 100 }, - "transaction_gas_cost": { - "step_gas_cost": 4098, - "pedersen_gas_cost": 4, - "range_check_gas_cost": 77, - "poseidon_gas_cost": 11 - }, "transfer_entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e", "validate_declare_entry_point_selector": "0x289da278a8dc833409cabfdad1581e8e7d40e42dcaed693fa4008dcdb4963b3", "validate_deploy_entry_point_selector": "0x36fcbf06cd96843058359e1a75928beacfac10727dab22a3972f0af8aa92895", @@ -125,25 +121,25 @@ "call_contract": { "entry_point_initial_budget": 1, "step_gas_cost": 860, - "range_check_gas_cost": 15 + "range_check": 15 }, "deploy": { "entry_point_initial_budget": 1, "step_gas_cost": 1128, - "range_check_gas_cost": 18, - "pedersen_gas_cost": 7 + "range_check": 18, + "pedersen": 7 }, "emit_event": { "step_gas_cost": 100, - "range_check_gas_cost": 1 + "range_check": 1 }, "get_block_hash": { "step_gas_cost": 104, - "range_check_gas_cost": 2 + "range_check": 2 }, "get_execution_info": { "step_gas_cost": 100, - "range_check_gas_cost": 1 + "range_check": 1 }, "keccak": { "syscall_base_gas_cost": 1 @@ -152,81 +148,81 @@ "library_call": { "entry_point_initial_budget": 1, "step_gas_cost": 836, - "range_check_gas_cost": 15 + "range_check": 15 }, "sha256_process_block": { "step_gas_cost": 1855, - "range_check_gas_cost": 65, - "bitwise_builtin_gas_cost": 1115, + "range_check": 65, + "bitwise": 1115, "syscall_base_gas_cost": 1 }, "replace_class": { "step_gas_cost": 104, - "range_check_gas_cost": 1 + "range_check": 1 }, "secp256k1_add": { - "range_check_gas_cost": 29, + "range_check": 29, "step_gas_cost": 410 }, "secp256k1_get_point_from_x": { "memory_hole_gas_cost": 20, - "range_check_gas_cost": 30, + "range_check": 30, "step_gas_cost": 395 }, "secp256k1_get_xy": { "memory_hole_gas_cost": 40, - "range_check_gas_cost": 11, + "range_check": 11, "step_gas_cost": 207 }, "secp256k1_mul": { "memory_hole_gas_cost": 2, - "range_check_gas_cost": 7045, + "range_check": 7045, "step_gas_cost": 76505 }, "secp256k1_new": { "memory_hole_gas_cost": 40, - "range_check_gas_cost": 35, + "range_check": 35, "step_gas_cost": 461 }, "secp256r1_add": { - "range_check_gas_cost": 57, + "range_check": 57, "step_gas_cost": 593 }, "secp256r1_get_point_from_x": { "memory_hole_gas_cost": 20, - "range_check_gas_cost": 44, + "range_check": 44, "step_gas_cost": 514 }, "secp256r1_get_xy": { "memory_hole_gas_cost": 40, - "range_check_gas_cost": 11, + "range_check": 11, "step_gas_cost": 209 }, "secp256r1_mul": { "memory_hole_gas_cost": 2, - "range_check_gas_cost": 13961, + "range_check": 13961, "step_gas_cost": 125344 }, "secp256r1_new": { "memory_hole_gas_cost": 40, - "range_check_gas_cost": 49, + "range_check": 49, "step_gas_cost": 580 }, "send_message_to_l1": { "step_gas_cost": 141, - "range_check_gas_cost": 1 + "range_check": 1 }, "storage_read": { "step_gas_cost": 100, - "range_check_gas_cost": 1 + "range_check": 1 }, "storage_write": { "step_gas_cost": 100, - "range_check_gas_cost": 1 + "range_check": 1 }, "get_class_hash_at": { "step_gas_cost": 100, - "range_check_gas_cost": 1 + "range_check": 1 } } }, @@ -666,4 +662,4 @@ 10000 ] } -} +} \ No newline at end of file diff --git a/crates/blockifier/src/execution/entry_point_execution.rs b/crates/blockifier/src/execution/entry_point_execution.rs index b9a6531eeb..0667962145 100644 --- a/crates/blockifier/src/execution/entry_point_execution.rs +++ b/crates/blockifier/src/execution/entry_point_execution.rs @@ -196,12 +196,12 @@ fn prepare_program_extra_data( // Create the builtin cost segment, the builtin order should be the same as the price builtin // array in the os in compiled_class.cairo in load_compiled_class_facts. let builtin_price_array = [ - gas_costs.base.pedersen_gas_cost, - gas_costs.base.bitwise_builtin_gas_cost, - gas_costs.base.ecop_gas_cost, - gas_costs.base.poseidon_gas_cost, - gas_costs.base.add_mod_gas_cost, - gas_costs.base.mul_mod_gas_cost, + gas_costs.builtins.pedersen, + gas_costs.builtins.bitwise, + gas_costs.builtins.ecop, + gas_costs.builtins.poseidon, + gas_costs.builtins.add_mod, + gas_costs.builtins.mul_mod, ]; let data = builtin_price_array diff --git a/crates/blockifier/src/execution/native/entry_point_execution.rs b/crates/blockifier/src/execution/native/entry_point_execution.rs index 343d37c219..ee713aa263 100644 --- a/crates/blockifier/src/execution/native/entry_point_execution.rs +++ b/crates/blockifier/src/execution/native/entry_point_execution.rs @@ -32,12 +32,12 @@ pub fn execute_entry_point_call( let builtin_costs = BuiltinCosts { // todo(rodrigo): Unsure of what value `const` means, but 1 is the right value. r#const: 1, - pedersen: gas_costs.base.pedersen_gas_cost, - bitwise: gas_costs.base.bitwise_builtin_gas_cost, - ecop: gas_costs.base.ecop_gas_cost, - poseidon: gas_costs.base.poseidon_gas_cost, - add_mod: gas_costs.base.add_mod_gas_cost, - mul_mod: gas_costs.base.mul_mod_gas_cost, + pedersen: gas_costs.builtins.pedersen, + bitwise: gas_costs.builtins.bitwise, + ecop: gas_costs.builtins.ecop, + poseidon: gas_costs.builtins.poseidon, + add_mod: gas_costs.builtins.add_mod, + mul_mod: gas_costs.builtins.mul_mod, }; // Grow the stack (if it's below the red zone) to handle deep Cairo recursions - diff --git a/crates/blockifier/src/versioned_constants.rs b/crates/blockifier/src/versioned_constants.rs index 9e46492fa8..faa9043bf1 100644 --- a/crates/blockifier/src/versioned_constants.rs +++ b/crates/blockifier/src/versioned_constants.rs @@ -386,6 +386,7 @@ impl VersionedConstants { .iter() .map(|(builtin, amount)| { let builtin_cost = gas_costs + .builtins .get_builtin_gas_cost(builtin) .unwrap_or_else(|err| panic!("Failed to get gas cost: {}", err)); builtin_cost * u64_from_usize(*amount) @@ -660,48 +661,43 @@ impl SyscallGasCosts { pub struct BaseGasCosts { 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, - // Priced builtins. - pub keccak_builtin_gas_cost: u64, - 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, - pub ecdsa_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 default_initial_gas_cost: u64, // Compiler gas costs. pub entry_point_initial_budget: u64, pub syscall_base_gas_cost: u64, - // OS gas costs. - pub transaction_gas_cost: u64, } -/// Gas cost constants. For more documentation see in core/os/constants.cairo. #[derive(Debug, Default, Deserialize)] -pub struct GasCosts { - pub base: BaseGasCosts, - pub syscalls: SyscallGasCosts, +pub struct BuiltinGasCosts { + // 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: u64, + // Priced builtins. + pub keccak: u64, + pub pedersen: u64, + pub bitwise: u64, + pub ecop: u64, + pub poseidon: u64, + pub add_mod: u64, + pub mul_mod: u64, + pub ecdsa: u64, } -impl GasCosts { +impl BuiltinGasCosts { pub fn get_builtin_gas_cost(&self, builtin: &BuiltinName) -> Result { let gas_cost = match *builtin { - BuiltinName::range_check => self.base.range_check_gas_cost, - BuiltinName::pedersen => self.base.pedersen_gas_cost, - BuiltinName::bitwise => self.base.bitwise_builtin_gas_cost, - BuiltinName::ec_op => self.base.ecop_gas_cost, - BuiltinName::keccak => self.base.keccak_builtin_gas_cost, - BuiltinName::poseidon => self.base.poseidon_gas_cost, - BuiltinName::range_check96 => self.base.range_check_gas_cost, - BuiltinName::add_mod => self.base.add_mod_gas_cost, - BuiltinName::mul_mod => self.base.mul_mod_gas_cost, - BuiltinName::ecdsa => self.base.ecdsa_gas_cost, + BuiltinName::range_check => self.range_check, + BuiltinName::pedersen => self.pedersen, + BuiltinName::bitwise => self.bitwise, + BuiltinName::ec_op => self.ecop, + BuiltinName::keccak => self.keccak, + BuiltinName::poseidon => self.poseidon, + BuiltinName::range_check96 => self.range_check, + BuiltinName::add_mod => self.add_mod, + BuiltinName::mul_mod => self.mul_mod, + BuiltinName::ecdsa => self.ecdsa, BuiltinName::segment_arena => return Err(GasCostsError::VirtualBuiltin), BuiltinName::output => { return Err(GasCostsError::UnsupportedBuiltinInCairo1 { builtin: *builtin }); @@ -712,6 +708,14 @@ impl GasCosts { } } +/// Gas cost constants. For more documentation see in core/os/constants.cairo. +#[derive(Debug, Default, Deserialize)] +pub struct GasCosts { + pub base: BaseGasCosts, + pub builtins: BuiltinGasCosts, + pub syscalls: SyscallGasCosts, +} + // Below, serde first deserializes the json into a regular IndexMap wrapped by the newtype // `OsConstantsRawJson`, then calls the `try_from` of the newtype, which handles the // conversion into actual values. @@ -730,7 +734,7 @@ impl OsConstants { // not used by the blockifier but included for transparency. These constanst will be ignored // during the creation of the struct containing the gas costs. - const ADDITIONAL_FIELDS: [&'static str; 30] = [ + const ADDITIONAL_FIELDS: [&'static str; 31] = [ "block_hash_contract_address", "constructor_entry_point_selector", "default_entry_point_selector", @@ -761,6 +765,7 @@ impl OsConstants { "validate_rounding_consts", "validated", "syscall_gas_costs", + "builtin_gas_costs", ]; } @@ -770,9 +775,12 @@ impl TryFrom<&OsConstantsRawJson> for GasCosts { fn try_from(raw_json_data: &OsConstantsRawJson) -> Result { let base_value: Value = serde_json::to_value(&raw_json_data.parse_base()?)?; let base: BaseGasCosts = serde_json::from_value(base_value)?; - let syscalls_value: Value = serde_json::to_value(&raw_json_data.parse_syscalls(&base)?)?; + let builtins_value: Value = serde_json::to_value(&raw_json_data.parse_builtin()?)?; + let builtins: BuiltinGasCosts = serde_json::from_value(builtins_value)?; + let syscalls_value: Value = + serde_json::to_value(&raw_json_data.parse_syscalls(&base, &builtins)?)?; let syscalls: SyscallGasCosts = serde_json::from_value(syscalls_value)?; - Ok(GasCosts { base, syscalls }) + Ok(GasCosts { base, builtins, syscalls }) } } @@ -846,13 +854,34 @@ impl OsConstantsRawJson { fn parse_syscalls( &self, base: &BaseGasCosts, + builtins: &BuiltinGasCosts, ) -> Result, OsConstantsSerdeError> { let mut gas_costs = IndexMap::new(); let syscalls: IndexMap = serde_json::from_value( (self.raw_json_file_as_dict.get("syscall_gas_costs").unwrap()).clone(), )?; for (key, value) in syscalls { - self.add_to_syscalls(&key, &value, &mut gas_costs, base)?; + self.add_to_syscalls(&key, &value, &mut gas_costs, base, builtins)?; + } + Ok(gas_costs) + } + + fn parse_builtin(&self) -> Result, OsConstantsSerdeError> { + let mut gas_costs = IndexMap::new(); + let builtins: IndexMap = serde_json::from_value( + (self.raw_json_file_as_dict.get("builtin_gas_costs").unwrap()).clone(), + )?; + for (key, value) in builtins { + match value { + Value::Number(n) => { + let cost = n.as_u64().ok_or_else(|| OsConstantsSerdeError::OutOfRange { + key: key.to_string(), + value: n.clone(), + })?; + gas_costs.insert(key.to_string(), cost); + } + _ => return Err(OsConstantsSerdeError::UnhandledValueType(value.clone())), + } } Ok(gas_costs) } @@ -925,6 +954,7 @@ impl OsConstantsRawJson { value: &Value, syscalls: &mut IndexMap, base: &BaseGasCosts, + builtins: &BuiltinGasCosts, ) -> Result<(), OsConstantsSerdeError> { let mut cost = 0; match value { @@ -933,19 +963,18 @@ impl OsConstantsRawJson { let inner_value = match inner_key.as_str() { "step_gas_cost" => base.step_gas_cost, "memory_hole_gas_cost" => base.memory_hole_gas_cost, - "range_check_gas_cost" => base.range_check_gas_cost, - "keccak_builtin_gas_cost" => base.keccak_builtin_gas_cost, - "pedersen_gas_cost" => base.pedersen_gas_cost, - "bitwise_builtin_gas_cost" => base.bitwise_builtin_gas_cost, - "ecop_gas_cost" => base.ecop_gas_cost, - "poseidon_gas_cost" => base.poseidon_gas_cost, - "add_mod_gas_cost" => base.add_mod_gas_cost, - "mul_mod_gas_cost" => base.mul_mod_gas_cost, - "ecdsa_gas_cost" => base.ecdsa_gas_cost, "default_initial_gas_cost" => base.default_initial_gas_cost, "entry_point_initial_budget" => base.entry_point_initial_budget, "syscall_base_gas_cost" => base.syscall_base_gas_cost, - "transaction_gas_cost" => base.transaction_gas_cost, + "range_check" => builtins.range_check, + "keccak" => builtins.keccak, + "pedersen" => builtins.pedersen, + "bitwise" => builtins.bitwise, + "ecop" => builtins.ecop, + "poseidon" => builtins.poseidon, + "add_mod" => builtins.add_mod, + "mul_mod" => builtins.mul_mod, + "ecdsa" => builtins.ecdsa, _ => { return Err(OsConstantsSerdeError::KeyNotFound { key: key.to_string(), diff --git a/crates/blockifier/src/versioned_constants_test.rs b/crates/blockifier/src/versioned_constants_test.rs index 4f9b96c16f..2a56911127 100644 --- a/crates/blockifier/src/versioned_constants_test.rs +++ b/crates/blockifier/src/versioned_constants_test.rs @@ -19,7 +19,7 @@ fn test_successful_gas_costs_parsing() { "entry_point_initial_budget": { "step_gas_cost": 3 }, - "transaction_gas_cost": { + "syscall_base_gas_cost": { "entry_point_initial_budget": 4, "step_gas_cost": 5 }, @@ -33,7 +33,10 @@ fn test_successful_gas_costs_parsing() { assert_eq!(versioned_constants.os_constants.gas_costs.base.entry_point_initial_budget, 2 * 3); // step_gas_cost * 3. // entry_point_initial_budget * 4 + step_gas_cost * 5. - assert_eq!(versioned_constants.os_constants.gas_costs.base.transaction_gas_cost, 6 * 4 + 2 * 5); + assert_eq!( + versioned_constants.os_constants.gas_costs.base.syscall_base_gas_cost, + 6 * 4 + 2 * 5 + ); } /// Assert versioned constants overrides are used when provided.