Skip to content

Commit

Permalink
fix: fix gas cost in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
meship-starkware committed Jan 6, 2025
1 parent b7b941f commit bbcfa84
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 40 deletions.
2 changes: 1 addition & 1 deletion crates/blockifier/cairo_native
Submodule cairo_native updated 109 files
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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];
Expand All @@ -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()
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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![]) }
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
};

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ 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!(
call_info.execution,
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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
);
}

Expand All @@ -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() }
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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![]) }
);
}
24 changes: 4 additions & 20 deletions crates/blockifier/src/transaction/transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit bbcfa84

Please sign in to comment.