Skip to content

Commit

Permalink
chore(blockifier): replace entry_point_gas_cost with initial_budget
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonatan-Starkware committed Nov 28, 2024
1 parent 23231e4 commit 1ed93f2
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 94 deletions.
2 changes: 1 addition & 1 deletion crates/blockifier/cairo_native
Submodule cairo_native updated 99 files
+63 −78 .github/workflows/bench-hyperfine.yml
+1 −1 .github/workflows/publish.yml
+11 −56 .github/workflows/release.yml
+2 −2 .github/workflows/starknet-blocks.yml
+1 −1 CODEOWNERS
+182 −193 Cargo.lock
+2 −2 Cargo.toml
+5 −15 benches/compile_time.rs
+8 −20 benches/libfuncs.rs
+1 −1 benches/util.rs
+2 −2 env.sh
+3 −6 examples/easy_api.rs
+3 −6 examples/erc20.rs
+3 −6 examples/invoke.rs
+3 −6 examples/starknet.rs
+1 −1 runtime/Cargo.toml
+5 −9 runtime/src/lib.rs
+8 −11 src/arch.rs
+26 −13 src/arch/aarch64.rs
+26 −15 src/arch/x86_64.rs
+2 −4 src/bin/cairo-native-compile.rs
+1 −1 src/bin/cairo-native-dump.rs
+3 −5 src/bin/cairo-native-run.rs
+1 −1 src/bin/cairo-native-stress/main.rs
+1 −5 src/bin/scarb-native-dump.rs
+3 −5 src/bin/utils/test.rs
+1 −3 src/cache/aot.rs
+2 −4 src/cache/jit.rs
+8 −4 src/compiler.rs
+25 −14 src/context.rs
+1 −1 src/debug.rs
+2 −3 src/error.rs
+17 −13 src/executor.rs
+30 −31 src/executor/aot.rs
+71 −70 src/executor/contract.rs
+13 −19 src/executor/jit.rs
+52 −98 src/libfuncs.rs
+87 −0 src/libfuncs/ap_tracking.rs
+244 −107 src/libfuncs/array.rs
+4 −3 src/libfuncs/bitwise.rs
+5 −5 src/libfuncs/bool.rs
+77 −74 src/libfuncs/bounded_int.rs
+24 −13 src/libfuncs/box.rs
+33 −0 src/libfuncs/branch_align.rs
+12 −6 src/libfuncs/bytes31.rs
+39 −27 src/libfuncs/cast.rs
+185 −98 src/libfuncs/circuit.rs
+1 −1 src/libfuncs/const.rs
+22 −8 src/libfuncs/debug.rs
+2 −2 src/libfuncs/drop.rs
+2 −2 src/libfuncs/dup.rs
+23 −19 src/libfuncs/ec.rs
+12 −13 src/libfuncs/enum.rs
+74 −40 src/libfuncs/felt252.rs
+16 −7 src/libfuncs/felt252_dict.rs
+11 −6 src/libfuncs/felt252_dict_entry.rs
+31 −18 src/libfuncs/gas.rs
+9 −9 src/libfuncs/int_range.rs
+59 −28 src/libfuncs/mem.rs
+42 −16 src/libfuncs/nullable.rs
+7 −6 src/libfuncs/pedersen.rs
+8 −8 src/libfuncs/poseidon.rs
+56 −24 src/libfuncs/sint128.rs
+61 −29 src/libfuncs/sint16.rs
+61 −29 src/libfuncs/sint32.rs
+61 −29 src/libfuncs/sint64.rs
+61 −29 src/libfuncs/sint8.rs
+29 −0 src/libfuncs/snapshot_take.rs
+365 −129 src/libfuncs/starknet.rs
+1 −1 src/libfuncs/struct.rs
+102 −47 src/libfuncs/uint128.rs
+98 −42 src/libfuncs/uint16.rs
+46 −23 src/libfuncs/uint256.rs
+84 −40 src/libfuncs/uint32.rs
+39 −19 src/libfuncs/uint512.rs
+101 −42 src/libfuncs/uint64.rs
+83 −39 src/libfuncs/uint8.rs
+30 −0 src/libfuncs/unconditional_jump.rs
+30 −0 src/libfuncs/unwrap_non_zero.rs
+1 −1 src/metadata/debug_utils.rs
+1 −1 src/metadata/gas.rs
+4 −4 src/module.rs
+5 −5 src/starknet.rs
+3 −3 src/types.rs
+39 −18 src/types/array.rs
+2 −2 src/types/box.rs
+2 −2 src/types/circuit.rs
+16 −4 src/types/enum.rs
+11 −4 src/types/felt252_dict.rs
+6 −3 src/types/nullable.rs
+15 −3 src/types/snapshot.rs
+10 −3 src/types/starknet.rs
+2 −2 src/types/struct.rs
+18 −17 src/utils.rs
+2 −154 src/utils/block_ext.rs
+65 −90 src/values.rs
+6 −17 tests/common.rs
+1 −1 tests/tests/compile_library.rs
+2 −4 tests/tests/trampoline.rs
22 changes: 9 additions & 13 deletions crates/blockifier/resources/versioned_constants_0_13_0.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,28 +89,24 @@
"syscall_base_gas_cost": {
"step_gas_cost": 100
},
"entry_point_gas_cost": {
"entry_point_initial_budget": 1,
"step_gas_cost": 500
},
"fee_transfer_gas_cost": {
"entry_point_gas_cost": 1,
"step_gas_cost": 100
"entry_point_initial_budget": 1,
"step_gas_cost": 600
},
"transaction_gas_cost": {
"entry_point_gas_cost": 2,
"entry_point_initial_budget": 2,
"fee_transfer_gas_cost": 1,
"step_gas_cost": 100
"step_gas_cost": 1100
},
"call_contract_gas_cost": {
"syscall_base_gas_cost": 1,
"step_gas_cost": 10,
"entry_point_gas_cost": 1
"step_gas_cost": 510,
"entry_point_initial_budget": 1
},
"deploy_gas_cost": {
"syscall_base_gas_cost": 1,
"step_gas_cost": 200,
"entry_point_gas_cost": 1
"step_gas_cost": 700,
"entry_point_initial_budget": 1
},
"get_block_hash_gas_cost": {
"syscall_base_gas_cost": 1,
Expand Down Expand Up @@ -611,4 +607,4 @@
1000
]
}
}
}
20 changes: 8 additions & 12 deletions crates/blockifier/resources/versioned_constants_0_13_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,28 +89,24 @@
"syscall_base_gas_cost": {
"step_gas_cost": 100
},
"entry_point_gas_cost": {
"entry_point_initial_budget": 1,
"step_gas_cost": 500
},
"fee_transfer_gas_cost": {
"entry_point_gas_cost": 1,
"step_gas_cost": 100
"entry_point_initial_budget": 1,
"step_gas_cost": 600
},
"transaction_gas_cost": {
"entry_point_gas_cost": 2,
"entry_point_initial_budget": 2,
"fee_transfer_gas_cost": 1,
"step_gas_cost": 100
"step_gas_cost": 1100
},
"call_contract_gas_cost": {
"syscall_base_gas_cost": 1,
"step_gas_cost": 10,
"entry_point_gas_cost": 1
"step_gas_cost": 510,
"entry_point_initial_budget": 1
},
"deploy_gas_cost": {
"syscall_base_gas_cost": 1,
"step_gas_cost": 200,
"entry_point_gas_cost": 1
"step_gas_cost": 700,
"entry_point_initial_budget": 1
},
"get_block_hash_gas_cost": {
"syscall_base_gas_cost": 1,
Expand Down
20 changes: 8 additions & 12 deletions crates/blockifier/resources/versioned_constants_0_13_1_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,28 +89,24 @@
"syscall_base_gas_cost": {
"step_gas_cost": 100
},
"entry_point_gas_cost": {
"entry_point_initial_budget": 1,
"step_gas_cost": 500
},
"fee_transfer_gas_cost": {
"entry_point_gas_cost": 1,
"step_gas_cost": 100
"entry_point_initial_budget": 1,
"step_gas_cost": 600
},
"transaction_gas_cost": {
"entry_point_gas_cost": 2,
"entry_point_initial_budget": 2,
"fee_transfer_gas_cost": 1,
"step_gas_cost": 100
"step_gas_cost": 1100
},
"call_contract_gas_cost": {
"syscall_base_gas_cost": 1,
"step_gas_cost": 10,
"entry_point_gas_cost": 1
"step_gas_cost": 510,
"entry_point_initial_budget": 1
},
"deploy_gas_cost": {
"syscall_base_gas_cost": 1,
"step_gas_cost": 200,
"entry_point_gas_cost": 1
"step_gas_cost": 700,
"entry_point_initial_budget": 1
},
"get_block_hash_gas_cost": {
"syscall_base_gas_cost": 1,
Expand Down
20 changes: 8 additions & 12 deletions crates/blockifier/resources/versioned_constants_0_13_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,21 @@
"os_constants": {
"block_hash_contract_address": 1,
"call_contract_gas_cost": {
"entry_point_gas_cost": 1,
"step_gas_cost": 10,
"entry_point_initial_budget": 1,
"step_gas_cost": 510,
"syscall_base_gas_cost": 1
},
"constructor_entry_point_selector": "0x28ffe4ff0f226a9107253e17a904099aa4f63a02a5621de0576e5aa71bc5194",
"default_entry_point_selector": 0,
"deploy_gas_cost": {
"entry_point_gas_cost": 1,
"step_gas_cost": 200,
"entry_point_initial_budget": 1,
"step_gas_cost": 700,
"syscall_base_gas_cost": 1
},
"emit_event_gas_cost": {
"step_gas_cost": 10,
"syscall_base_gas_cost": 1
},
"entry_point_gas_cost": {
"entry_point_initial_budget": 1,
"step_gas_cost": 500
},
"entry_point_initial_budget": {
"step_gas_cost": 100
},
Expand All @@ -91,8 +87,8 @@
"error_entry_point_not_found": "ENTRYPOINT_NOT_FOUND",
"execute_entry_point_selector": "0x15d40a3d6ca2ac30f4031e42be28da9b056fef9bb7357ac5e85627ee876e5ad",
"fee_transfer_gas_cost": {
"entry_point_gas_cost": 1,
"step_gas_cost": 100
"entry_point_initial_budget": 1,
"step_gas_cost": 600
},
"get_block_hash_gas_cost": {
"step_gas_cost": 50,
Expand Down Expand Up @@ -207,9 +203,9 @@
"step_gas_cost": 100
},
"transaction_gas_cost": {
"entry_point_gas_cost": 2,
"entry_point_initial_budget": 2,
"fee_transfer_gas_cost": 1,
"step_gas_cost": 100
"step_gas_cost": 1100
},
"transfer_entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e",
"validate_declare_entry_point_selector": "0x289da278a8dc833409cabfdad1581e8e7d40e42dcaed693fa4008dcdb4963b3",
Expand Down
20 changes: 8 additions & 12 deletions crates/blockifier/resources/versioned_constants_0_13_2_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,21 @@
"os_constants": {
"block_hash_contract_address": 1,
"call_contract_gas_cost": {
"entry_point_gas_cost": 1,
"step_gas_cost": 10,
"entry_point_initial_budget": 1,
"step_gas_cost": 510,
"syscall_base_gas_cost": 1
},
"constructor_entry_point_selector": "0x28ffe4ff0f226a9107253e17a904099aa4f63a02a5621de0576e5aa71bc5194",
"default_entry_point_selector": 0,
"deploy_gas_cost": {
"entry_point_gas_cost": 1,
"step_gas_cost": 200,
"entry_point_initial_budget": 1,
"step_gas_cost": 700,
"syscall_base_gas_cost": 1
},
"emit_event_gas_cost": {
"step_gas_cost": 10,
"syscall_base_gas_cost": 1
},
"entry_point_gas_cost": {
"entry_point_initial_budget": 1,
"step_gas_cost": 500
},
"entry_point_initial_budget": {
"step_gas_cost": 100
},
Expand All @@ -91,8 +87,8 @@
"error_entry_point_not_found": "ENTRYPOINT_NOT_FOUND",
"execute_entry_point_selector": "0x15d40a3d6ca2ac30f4031e42be28da9b056fef9bb7357ac5e85627ee876e5ad",
"fee_transfer_gas_cost": {
"entry_point_gas_cost": 1,
"step_gas_cost": 100
"entry_point_initial_budget": 1,
"step_gas_cost": 600
},
"get_block_hash_gas_cost": {
"step_gas_cost": 50,
Expand Down Expand Up @@ -207,9 +203,9 @@
"step_gas_cost": 100
},
"transaction_gas_cost": {
"entry_point_gas_cost": 2,
"entry_point_initial_budget": 2,
"fee_transfer_gas_cost": 1,
"step_gas_cost": 100
"step_gas_cost": 1100
},
"transfer_entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e",
"validate_declare_entry_point_selector": "0x289da278a8dc833409cabfdad1581e8e7d40e42dcaed693fa4008dcdb4963b3",
Expand Down
20 changes: 8 additions & 12 deletions crates/blockifier/resources/versioned_constants_0_13_3.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,21 @@
"os_constants": {
"block_hash_contract_address": 1,
"call_contract_gas_cost": {
"entry_point_gas_cost": 1,
"step_gas_cost": 10,
"entry_point_initial_budget": 1,
"step_gas_cost": 510,
"syscall_base_gas_cost": 1
},
"constructor_entry_point_selector": "0x28ffe4ff0f226a9107253e17a904099aa4f63a02a5621de0576e5aa71bc5194",
"default_entry_point_selector": 0,
"deploy_gas_cost": {
"entry_point_gas_cost": 1,
"step_gas_cost": 200,
"entry_point_initial_budget": 1,
"step_gas_cost": 700,
"syscall_base_gas_cost": 1
},
"emit_event_gas_cost": {
"step_gas_cost": 10,
"syscall_base_gas_cost": 1
},
"entry_point_gas_cost": {
"entry_point_initial_budget": 1,
"step_gas_cost": 500
},
"entry_point_initial_budget": {
"step_gas_cost": 100
},
Expand All @@ -91,8 +87,8 @@
"error_entry_point_not_found": "ENTRYPOINT_NOT_FOUND",
"execute_entry_point_selector": "0x15d40a3d6ca2ac30f4031e42be28da9b056fef9bb7357ac5e85627ee876e5ad",
"fee_transfer_gas_cost": {
"entry_point_gas_cost": 1,
"step_gas_cost": 100
"entry_point_initial_budget": 1,
"step_gas_cost": 600
},
"get_block_hash_gas_cost": {
"step_gas_cost": 50,
Expand Down Expand Up @@ -207,9 +203,9 @@
"step_gas_cost": 100
},
"transaction_gas_cost": {
"entry_point_gas_cost": 2,
"entry_point_initial_budget": 2,
"fee_transfer_gas_cost": 1,
"step_gas_cost": 100
"step_gas_cost": 1100
},
"transfer_entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e",
"validate_declare_entry_point_selector": "0x289da278a8dc833409cabfdad1581e8e7d40e42dcaed693fa4008dcdb4963b3",
Expand Down
10 changes: 3 additions & 7 deletions crates/blockifier/resources/versioned_constants_0_13_4.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@
"os_constants": {
"block_hash_contract_address": 1,
"call_contract_gas_cost": {
"entry_point_gas_cost": 1,
"entry_point_initial_budget": 1,
"step_gas_cost": 860,
"range_check_gas_cost": 15
},
"constructor_entry_point_selector": "0x28ffe4ff0f226a9107253e17a904099aa4f63a02a5621de0576e5aa71bc5194",
"default_entry_point_selector": 0,
"deploy_gas_cost": {
"entry_point_gas_cost": 1,
"entry_point_initial_budget": 1,
"step_gas_cost": 1128,
"range_check_gas_cost": 18,
"pedersen_gas_cost": 7
Expand All @@ -74,10 +74,6 @@
"step_gas_cost": 100,
"range_check_gas_cost": 1
},
"entry_point_gas_cost": {
"entry_point_initial_budget": 1,
"step_gas_cost": 500
},
"entry_point_initial_budget": {
"step_gas_cost": 100
},
Expand Down Expand Up @@ -114,7 +110,7 @@
"l1_data_gas_index": 2,
"l2_gas_index": 1,
"library_call_gas_cost": {
"entry_point_gas_cost": 1,
"entry_point_initial_budget": 1,
"step_gas_cost": 836,
"range_check_gas_cost": 15
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub const REQUIRED_GAS_CALL_CONTRACT_TEST: u64 = 170370;
pub const REQUIRED_GAS_CALL_CONTRACT_TEST: u64 = 120370;
pub const REQUIRED_GAS_STORAGE_READ_WRITE_TEST: u64 = 16990;
pub const REQUIRED_GAS_GET_CLASS_HASH_AT_TEST: u64 = 7830;
pub const REQUIRED_GAS_LIBRARY_CALL_TEST: u64 = 167970;
pub const REQUIRED_GAS_LIBRARY_CALL_TEST: u64 = 117970;
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn no_constructor(cairo_version: CairoVersion) {
let deploy_call = &entry_point_call.execute_directly(&mut state).unwrap();
assert_eq!(
deploy_call.execution,
CallExecution { retdata: retdata![], gas_consumed: 205200, ..CallExecution::default() }
CallExecution { retdata: retdata![], gas_consumed: 155200, ..CallExecution::default() }
);

let deployed_contract_address = calculate_contract_address(
Expand Down Expand Up @@ -119,7 +119,7 @@ fn with_constructor(cairo_version: CairoVersion) {
let deploy_call = &entry_point_call.execute_directly(&mut state).unwrap();
assert_eq!(
deploy_call.execution,
CallExecution { retdata: retdata![], gas_consumed: 214550, ..CallExecution::default() }
CallExecution { retdata: retdata![], gas_consumed: 164550, ..CallExecution::default() }
);

let constructor_call = &deploy_call.inner_calls[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn test_library_call_assert_fails(cairo_version: CairoVersion) {
// 'ENTRYPOINT_FAILED'.
felt!("0x454e545259504f494e545f4641494c4544")
]),
gas_consumed: 150980,
gas_consumed: 100980,
failed: true,
..Default::default()
}
Expand Down Expand Up @@ -133,7 +133,7 @@ fn test_nested_library_call(cairo_version: CairoVersion) {
class_hash: Some(test_class_hash),
code_address: None,
call_type: CallType::Delegate,
initial_gas: 9998985960,
initial_gas: 9999085960,
..trivial_external_entry_point_new(test_contract)
};
let library_entry_point = CallEntryPoint {
Expand All @@ -148,12 +148,12 @@ fn test_nested_library_call(cairo_version: CairoVersion) {
class_hash: Some(test_class_hash),
code_address: None,
call_type: CallType::Delegate,
initial_gas: 9999136940,
initial_gas: 9999186940,
..trivial_external_entry_point_new(test_contract)
};
let storage_entry_point = CallEntryPoint {
calldata: calldata![felt!(key), felt!(value)],
initial_gas: 9998834320,
initial_gas: 9998984320,
..nested_storage_entry_point
};

Expand Down Expand Up @@ -243,7 +243,7 @@ fn test_nested_library_call(cairo_version: CairoVersion) {
call: main_entry_point.clone(),
execution: CallExecution {
retdata: retdata![felt!(value)],
gas_consumed: 475110,
gas_consumed: 325110,
..CallExecution::default()
},
charged_resources: main_call_resources,
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/transaction/transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ fn add_kzg_da_resources_to_resources_mapping(
},
validate_gas_consumed: 4740, // The gas consumption results from parsing the input
// arguments.
execute_gas_consumed: 162080,
execute_gas_consumed: 112080,
inner_call_initial_gas: versioned_constants_for_account_testing().default_initial_gas_cost(),
},
CairoVersion::Cairo1)]
Expand Down
Loading

0 comments on commit 1ed93f2

Please sign in to comment.