From bbcfa84b412463286ed1c51e051d49809813bb36 Mon Sep 17 00:00:00 2001 From: meship-starkware Date: Mon, 6 Jan 2025 09:57:36 +0200 Subject: [PATCH] fix: fix gas cost in tests --- crates/blockifier/cairo_native | 2 +- .../syscalls/syscall_tests/constants.rs | 8 +++---- .../syscalls/syscall_tests/deploy.rs | 6 ++--- .../syscalls/syscall_tests/emit_event.rs | 2 +- .../syscall_tests/get_class_hash_at.rs | 3 ++- .../syscalls/syscall_tests/keccak.rs | 2 +- .../syscalls/syscall_tests/library_call.rs | 10 ++++---- .../syscalls/syscall_tests/out_of_gas.rs | 5 +++- .../execution/syscalls/syscall_tests/secp.rs | 4 ++-- .../syscalls/syscall_tests/sha256.rs | 2 +- .../src/transaction/transactions_test.rs | 24 ++++--------------- 11 files changed, 28 insertions(+), 40 deletions(-) diff --git a/crates/blockifier/cairo_native b/crates/blockifier/cairo_native index 76e83965d3..185e94bce3 160000 --- a/crates/blockifier/cairo_native +++ b/crates/blockifier/cairo_native @@ -1 +1 @@ -Subproject commit 76e83965d3bf1252eb6c68200a3accd5fd1ec004 +Subproject commit 185e94bce3e380db988f98d96b4ddcb3e6c044bc diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/constants.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/constants.rs index 1abd092c44..2ed4a312da 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/constants.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/constants.rs @@ -1,5 +1,5 @@ -pub const REQUIRED_GAS_CALL_CONTRACT_TEST: u64 = 130830; -pub const REQUIRED_GAS_STORAGE_READ_WRITE_TEST: u64 = 26850; +pub const REQUIRED_GAS_CALL_CONTRACT_TEST: u64 = 130760; +pub const REQUIRED_GAS_STORAGE_READ_WRITE_TEST: u64 = 27550; pub const REQUIRED_GAS_GET_CLASS_HASH_AT_TEST: u64 = 17760; -pub const REQUIRED_GAS_LIBRARY_CALL_TEST: u64 = 128430; -pub const REQUIRED_GAS_GET_BLOCK_HASH_TEST: u64 = 15220; +pub const REQUIRED_GAS_LIBRARY_CALL_TEST: u64 = 128360; +pub const REQUIRED_GAS_GET_BLOCK_HASH_TEST: u64 = 15920; diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/deploy.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/deploy.rs index addc6dd125..01d06024bf 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/deploy.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/deploy.rs @@ -43,7 +43,7 @@ fn no_constructor(runnable_version: RunnableCairo1) { let deploy_call = &entry_point_call.execute_directly(&mut state).unwrap(); assert_eq!( deploy_call.execution, - CallExecution { retdata: retdata![], gas_consumed: 155600, ..CallExecution::default() } + CallExecution { retdata: retdata![], gas_consumed: 154430, ..CallExecution::default() } ); let deployed_contract_address = calculate_contract_address( @@ -124,7 +124,7 @@ fn with_constructor(runnable_version: RunnableCairo1) { let deploy_call = &entry_point_call.execute_directly(&mut state).unwrap(); assert_eq!( deploy_call.execution, - CallExecution { retdata: retdata![], gas_consumed: 174880, ..CallExecution::default() } + CallExecution { retdata: retdata![], gas_consumed: 174910, ..CallExecution::default() } ); let constructor_call = &deploy_call.inner_calls[0]; @@ -136,7 +136,7 @@ fn with_constructor(runnable_version: RunnableCairo1) { // The test contract constructor returns its first argument. retdata: retdata![constructor_calldata[0]], // This reflects the gas cost of storage write syscall. - gas_consumed: 14540, + gas_consumed: 15140, ..CallExecution::default() } ); diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/emit_event.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/emit_event.rs index a71695f638..c788994e47 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/emit_event.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/emit_event.rs @@ -41,7 +41,7 @@ fn positive_flow(runnable_version: RunnableCairo1) { call_info.execution, CallExecution { events: vec![OrderedEvent { order: 0, event }], - gas_consumed: 57260, + gas_consumed: 41880, ..Default::default() } ); diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/get_class_hash_at.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/get_class_hash_at.rs index 11322694a9..7e482b5a71 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/get_class_hash_at.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/get_class_hash_at.rs @@ -34,13 +34,14 @@ fn test_get_class_hash_at(runnable_version: RunnableCairo1) { ..trivial_external_entry_point_new(test_contract) }; let positive_call_info = positive_entry_point_call.execute_directly(&mut state).unwrap(); + let redeposit_gas = 300; assert!(positive_call_info.accessed_contract_addresses.contains(&address)); assert!(positive_call_info.read_class_hash_values[0] == class_hash); assert_eq!( positive_call_info.execution, CallExecution { retdata: retdata!(), - gas_consumed: REQUIRED_GAS_GET_CLASS_HASH_AT_TEST, + gas_consumed: REQUIRED_GAS_GET_CLASS_HASH_AT_TEST + redeposit_gas, failed: false, ..CallExecution::default() } diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/keccak.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/keccak.rs index 33e0967596..e5653d902d 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/keccak.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/keccak.rs @@ -26,6 +26,6 @@ fn test_keccak(runnable_version: RunnableCairo1) { pretty_assertions::assert_eq!( entry_point_call.execute_directly(&mut state).unwrap().execution, - CallExecution { gas_consumed: 255947, ..CallExecution::from_retdata(retdata![]) } + CallExecution { gas_consumed: 245767, ..CallExecution::from_retdata(retdata![]) } ); } diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/library_call.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/library_call.rs index b9a4f21c1f..db92759292 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/library_call.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/library_call.rs @@ -83,7 +83,7 @@ fn test_library_call_assert_fails(runnable_version: RunnableCairo1) { // 'ENTRYPOINT_FAILED'. felt!("0x454e545259504f494e545f4641494c4544") ]), - gas_consumed: 111580, + gas_consumed: 105050, failed: true, ..Default::default() } @@ -123,7 +123,7 @@ fn test_nested_library_call(runnable_version: RunnableCairo1) { class_hash: Some(test_class_hash), code_address: None, call_type: CallType::Delegate, - initial_gas: 9999084760, + initial_gas: 9999084430, ..trivial_external_entry_point_new(test_contract) }; let library_entry_point = CallEntryPoint { @@ -138,12 +138,12 @@ fn test_nested_library_call(runnable_version: RunnableCairo1) { class_hash: Some(test_class_hash), code_address: None, call_type: CallType::Delegate, - initial_gas: 9999186340, + initial_gas: 9999185240, ..trivial_external_entry_point_new(test_contract) }; let storage_entry_point = CallEntryPoint { calldata: calldata![felt!(key), felt!(value)], - initial_gas: 9998982660, + initial_gas: 9998981630, ..nested_storage_entry_point }; @@ -191,7 +191,7 @@ fn test_nested_library_call(runnable_version: RunnableCairo1) { ..Default::default() }; - let main_gas_consumed = 336630; + let main_gas_consumed = 338360; let expected_call_info = CallInfo { call: main_entry_point.clone(), execution: CallExecution { diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/out_of_gas.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/out_of_gas.rs index 0a8d22b24d..c30bc19a62 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/out_of_gas.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/out_of_gas.rs @@ -39,6 +39,7 @@ fn test_out_of_gas(runnable_version: RunnableCairo1) { // We hit the out of gas error right before executing the syscall. let syscall_base_gas_cost = gas_costs.base.syscall_base_gas_cost; + let redeposit_gas = 300; let syscall_required_gas = get_block_hash_gas_cost - syscall_base_gas_cost; let call_info = entry_point_call.clone().execute_directly(&mut state).unwrap(); assert_eq!( @@ -46,7 +47,9 @@ fn test_out_of_gas(runnable_version: RunnableCairo1) { CallExecution { // 'Out of gas' retdata: retdata![felt!["0x4f7574206f6620676173"]], - gas_consumed: constants::REQUIRED_GAS_GET_BLOCK_HASH_TEST - syscall_required_gas, + gas_consumed: constants::REQUIRED_GAS_GET_BLOCK_HASH_TEST + - syscall_required_gas + - redeposit_gas, failed: true, ..Default::default() } diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/secp.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/secp.rs index 6ee01aedd9..30dad231b5 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/secp.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/secp.rs @@ -25,7 +25,7 @@ fn test_secp256k1(runnable_version: RunnableCairo1) { pretty_assertions::assert_eq!( entry_point_call.execute_directly(&mut state).unwrap().execution, - CallExecution { gas_consumed: 17032553, ..Default::default() } + CallExecution { gas_consumed: 17011779, ..Default::default() } ); } @@ -45,6 +45,6 @@ fn test_secp256r1(runnable_version: RunnableCairo1) { pretty_assertions::assert_eq!( entry_point_call.execute_directly(&mut state).unwrap().execution, - CallExecution { gas_consumed: 27570090, ..Default::default() } + CallExecution { gas_consumed: 27571210, ..Default::default() } ); } diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/sha256.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/sha256.rs index 0f6df02d96..5cdd980568 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/sha256.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/sha256.rs @@ -26,6 +26,6 @@ fn test_sha256(runnable_version: RunnableCairo1) { pretty_assertions::assert_eq!( entry_point_call.execute_directly(&mut state).unwrap().execution, - CallExecution { gas_consumed: 882425, ..CallExecution::from_retdata(retdata![]) } + CallExecution { gas_consumed: 870855, ..CallExecution::from_retdata(retdata![]) } ); } diff --git a/crates/blockifier/src/transaction/transactions_test.rs b/crates/blockifier/src/transaction/transactions_test.rs index cc6a9ba4f4..72ca51fa01 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -463,11 +463,7 @@ fn add_kzg_da_resources_to_resources_mapping( }, validate_gas_consumed: 11690, // The gas consumption results from parsing the input // arguments. -<<<<<<< HEAD - execute_gas_consumed: 112610, -======= - execute_gas_consumed: 111210, ->>>>>>> c1a221e35 (chore(cairo_native): update cairo native version to 0.2.5-rc2 and the compiled to 2.10.0-rc.0) + execute_gas_consumed: 111740, }, CairoVersion::Cairo1(RunnableCairo1::Casm))] // TODO(Tzahi): Add calls to cairo1 test contracts (where gas flows to and from the inner call). @@ -2376,11 +2372,7 @@ fn test_l1_handler(#[values(false, true)] use_kzg_da: bool) { // Build the expected call info. let accessed_storage_key = StorageKey::try_from(key).unwrap(); -<<<<<<< HEAD - let gas_consumed = GasAmount(16050); -======= - let gas_consumed = GasAmount(17020); ->>>>>>> c1a221e35 (chore(cairo_native): update cairo native version to 0.2.5-rc2 and the compiled to 2.10.0-rc.0) + let gas_consumed = GasAmount(16950); let expected_call_info = CallInfo { call: CallEntryPoint { class_hash: Some(test_contract.get_class_hash()), @@ -2411,19 +2403,11 @@ fn test_l1_handler(#[values(false, true)] use_kzg_da: bool) { // (currently matches only starknet resources). let expected_gas = match use_kzg_da { true => GasVector { -<<<<<<< HEAD - l1_gas: 17998_u32.into(), + l1_gas: 18007_u32.into(), l1_data_gas: 160_u32.into(), l2_gas: 0_u32.into(), }, - false => GasVector::from_l1_gas(19692_u32.into()), -======= - l1_gas: 18008_u32.into(), - l1_data_gas: 160_u32.into(), - l2_gas: 0_u32.into(), - }, - false => GasVector::from_l1_gas(19702_u32.into()), ->>>>>>> c1a221e35 (chore(cairo_native): update cairo native version to 0.2.5-rc2 and the compiled to 2.10.0-rc.0) + false => GasVector::from_l1_gas(19701_u32.into()), }; let expected_da_gas = match use_kzg_da {