diff --git a/crates/blockifier/resources/versioned_constants_0_13_4.json b/crates/blockifier/resources/versioned_constants_0_13_4.json index adb97a953f..aac8276e99 100644 --- a/crates/blockifier/resources/versioned_constants_0_13_4.json +++ b/crates/blockifier/resources/versioned_constants_0_13_4.json @@ -116,115 +116,7 @@ "validate_block_number_rounding": 100, "validate_timestamp_rounding": 3600 }, - "validated": "VALID", - "syscall_gas_costs": { - "call_contract": { - "entry_point_initial_budget": 1, - "step_gas_cost": 860, - "range_check": 15 - }, - "deploy": { - "entry_point_initial_budget": 1, - "step_gas_cost": 1128, - "range_check": 18, - "pedersen": 7 - }, - "emit_event": { - "step_gas_cost": 100, - "range_check": 1 - }, - "get_block_hash": { - "step_gas_cost": 104, - "range_check": 2 - }, - "get_execution_info": { - "step_gas_cost": 100, - "range_check": 1 - }, - "keccak": { - "syscall_base_gas_cost": 1 - }, - "keccak_round_cost": 180000, - "library_call": { - "entry_point_initial_budget": 1, - "step_gas_cost": 836, - "range_check": 15 - }, - "sha256_process_block": { - "step_gas_cost": 1855, - "range_check": 65, - "bitwise": 1115, - "syscall_base_gas_cost": 1 - }, - "replace_class": { - "step_gas_cost": 104, - "range_check": 1 - }, - "secp256k1_add": { - "range_check": 29, - "step_gas_cost": 410 - }, - "secp256k1_get_point_from_x": { - "memory_hole_gas_cost": 20, - "range_check": 30, - "step_gas_cost": 395 - }, - "secp256k1_get_xy": { - "memory_hole_gas_cost": 40, - "range_check": 11, - "step_gas_cost": 207 - }, - "secp256k1_mul": { - "memory_hole_gas_cost": 2, - "range_check": 7045, - "step_gas_cost": 76505 - }, - "secp256k1_new": { - "memory_hole_gas_cost": 40, - "range_check": 35, - "step_gas_cost": 461 - }, - "secp256r1_add": { - "range_check": 57, - "step_gas_cost": 593 - }, - "secp256r1_get_point_from_x": { - "memory_hole_gas_cost": 20, - "range_check": 44, - "step_gas_cost": 514 - }, - "secp256r1_get_xy": { - "memory_hole_gas_cost": 40, - "range_check": 11, - "step_gas_cost": 209 - }, - "secp256r1_mul": { - "memory_hole_gas_cost": 2, - "range_check": 13961, - "step_gas_cost": 125344 - }, - "secp256r1_new": { - "memory_hole_gas_cost": 40, - "range_check": 49, - "step_gas_cost": 580 - }, - "send_message_to_l1": { - "step_gas_cost": 141, - "range_check": 1 - }, - "storage_read": { - "step_gas_cost": 100, - "range_check": 1 - }, - "storage_write": { - "step_gas_cost": 100, - "range_check": 1 - }, - "get_class_hash_at": { - "step_gas_cost": 100, - "range_check": 1 - } - } + "validated": "VALID" }, "os_resources": { "execute_syscalls": { @@ -320,7 +212,12 @@ "n_memory_holes": 0 }, "Keccak": { - "n_steps": 381, + "n_steps": 100, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + }, + "KeccakRound": { + "n_steps": 371, "builtin_instance_counter": { "bitwise_builtin": 6, "keccak_builtin": 1, diff --git a/crates/blockifier/src/execution/deprecated_syscalls/mod.rs b/crates/blockifier/src/execution/deprecated_syscalls/mod.rs index b921789774..bec763cab7 100644 --- a/crates/blockifier/src/execution/deprecated_syscalls/mod.rs +++ b/crates/blockifier/src/execution/deprecated_syscalls/mod.rs @@ -64,6 +64,7 @@ pub enum DeprecatedSyscallSelector { GetTxInfo, GetTxSignature, Keccak, + KeccakRound, Sha256ProcessBlock, LibraryCall, LibraryCallL1Handler, @@ -107,6 +108,7 @@ impl TryFrom for DeprecatedSyscallSelector { b"GetTxInfo" => Ok(Self::GetTxInfo), b"GetTxSignature" => Ok(Self::GetTxSignature), b"Keccak" => Ok(Self::Keccak), + b"KeccakRound" => Ok(Self::KeccakRound), b"Sha256ProcessBlock" => Ok(Self::Sha256ProcessBlock), b"LibraryCall" => Ok(Self::LibraryCall), b"LibraryCallL1Handler" => Ok(Self::LibraryCallL1Handler), diff --git a/crates/blockifier/src/execution/entry_point.rs b/crates/blockifier/src/execution/entry_point.rs index e7fd2e84a7..e3cfc0cdf5 100644 --- a/crates/blockifier/src/execution/entry_point.rs +++ b/crates/blockifier/src/execution/entry_point.rs @@ -157,6 +157,8 @@ impl CallEntryPoint { context.n_sent_messages_to_l1, )); + println!("remaining_gas: {}", remaining_gas); + // This is the last operation of this function. execute_entry_point_call_wrapper(self, compiled_class, state, context, remaining_gas) } diff --git a/crates/blockifier/src/execution/execution_utils.rs b/crates/blockifier/src/execution/execution_utils.rs index 553748930f..f2a309f70d 100644 --- a/crates/blockifier/src/execution/execution_utils.rs +++ b/crates/blockifier/src/execution/execution_utils.rs @@ -85,12 +85,14 @@ pub fn execute_entry_point_call_wrapper( }); } update_remaining_gas(remaining_gas, &call_info); + println!("here with remaining gas: {}", remaining_gas); Ok(call_info) } Err(EntryPointExecutionError::PreExecutionError( PreExecutionError::EntryPointNotFound(_) | PreExecutionError::NoEntryPointOfTypeFound(_), - )) if context.versioned_constants().enable_reverts => Ok(CallInfo { + )) if context.versioned_constants().enable_reverts => { + Ok(CallInfo { call: orig_call, execution: CallExecution { retdata: Retdata(vec![Felt::from_hex(ENTRYPOINT_NOT_FOUND_ERROR).unwrap()]), @@ -100,7 +102,7 @@ pub fn execute_entry_point_call_wrapper( }, tracked_resource: current_tracked_resource, ..CallInfo::default() - }), + })} Err(err) => Err(err), } } diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/constants.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/constants.rs index ff3ebd021d..0ebda85b2d 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/constants.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/constants.rs @@ -1,4 +1,4 @@ -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 = 117970; +pub const REQUIRED_GAS_CALL_CONTRACT_TEST: u64 = 110830; +pub const REQUIRED_GAS_STORAGE_READ_WRITE_TEST: u64 = 16850; +pub const REQUIRED_GAS_GET_CLASS_HASH_AT_TEST: u64 = 7760; +pub const REQUIRED_GAS_LIBRARY_CALL_TEST: u64 = 108430; diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/deploy.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/deploy.rs index c2428bfeaf..d8c9bf216a 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: 155200, ..CallExecution::default() } + CallExecution { retdata: retdata![], gas_consumed: 145600, ..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: 164550, ..CallExecution::default() } + CallExecution { retdata: retdata![], gas_consumed: 154880, ..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: 4610, + gas_consumed: 4540, ..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 f45e9aa257..15675f2b4d 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: 47330, + gas_consumed: 47260, ..Default::default() } ); diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/keccak.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/keccak.rs index 644db1ed87..460547a1e4 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: 254240, ..CallExecution::from_retdata(retdata![]) } + CallExecution { gas_consumed: 254947, ..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 b2d7e38d3f..ff2b87af6d 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/library_call.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/library_call.rs @@ -84,7 +84,7 @@ fn test_library_call_assert_fails(runnable_version: RunnableCairo1) { // 'ENTRYPOINT_FAILED'. felt!("0x454e545259504f494e545f4641494c4544") ]), - gas_consumed: 100980, + gas_consumed: 91580, failed: true, ..Default::default() } @@ -124,7 +124,7 @@ fn test_nested_library_call(runnable_version: RunnableCairo1) { class_hash: Some(test_class_hash), code_address: None, call_type: CallType::Delegate, - initial_gas: 9999085960, + initial_gas: 9999104760, ..trivial_external_entry_point_new(test_contract) }; let library_entry_point = CallEntryPoint { @@ -139,16 +139,16 @@ fn test_nested_library_call(runnable_version: RunnableCairo1) { class_hash: Some(test_class_hash), code_address: None, call_type: CallType::Delegate, - initial_gas: 9999186940, + initial_gas: 9999196340, ..trivial_external_entry_point_new(test_contract) }; let storage_entry_point = CallEntryPoint { calldata: calldata![felt!(key), felt!(value)], - initial_gas: 9998984320, + initial_gas: 9999012660, ..nested_storage_entry_point }; - let storage_entry_point_gas = GasAmount(16990); + let storage_entry_point_gas = GasAmount(16850); // The default VersionedConstants is used in the execute_directly call bellow. let tracked_resource = test_contract.get_runnable_class().tracked_resource( @@ -177,7 +177,7 @@ fn test_nested_library_call(runnable_version: RunnableCairo1) { gas_consumed: REQUIRED_GAS_LIBRARY_CALL_TEST, ..CallExecution::default() }, - charged_resources: ChargedResources::from_gas(GasAmount(117970)), + charged_resources: ChargedResources::from_gas(GasAmount(108430)), inner_calls: vec![nested_storage_call_info], tracked_resource, ..Default::default() @@ -197,7 +197,7 @@ fn test_nested_library_call(runnable_version: RunnableCairo1) { ..Default::default() }; - let main_gas_consumed = 325110; + let main_gas_consumed = 296630; 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 e93e26c6be..39b18889fa 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 @@ -34,7 +34,7 @@ fn test_out_of_gas(runnable_version: RunnableCairo1) { CallExecution { // 'Out of gas' retdata: retdata![felt!["0x4f7574206f6620676173"]], - gas_consumed: REQUIRED_GAS_STORAGE_READ_WRITE_TEST - 70, + gas_consumed: REQUIRED_GAS_STORAGE_READ_WRITE_TEST, 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 a6ff6d624f..6f812cd375 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: 17033486, ..Default::default() } + CallExecution { gas_consumed: 17031553, ..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: 27562930, ..Default::default() } + CallExecution { gas_consumed: 27560090, ..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 bf9b9cd36f..daf6ab8488 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: 881425, ..CallExecution::from_retdata(retdata![]) } + CallExecution { gas_consumed: 872425, ..CallExecution::from_retdata(retdata![]) } ); } diff --git a/crates/blockifier/src/transaction/transactions_test.rs b/crates/blockifier/src/transaction/transactions_test.rs index bd78fb3214..ee476837d3 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -469,7 +469,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: 112080, + execute_gas_consumed: 102610, }, CairoVersion::Cairo1(RunnableCairo1::Casm))] // TODO(Tzahi): Add calls to cairo1 test contracts (where gas flows to and from the inner call). @@ -2344,7 +2344,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(); - let gas_consumed = GasAmount(6120); + let gas_consumed = GasAmount(6050); let expected_call_info = CallInfo { call: CallEntryPoint { class_hash: Some(test_contract.get_class_hash()), @@ -2376,11 +2376,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 { - l1_gas: 17899_u32.into(), + l1_gas: 17898_u32.into(), l1_data_gas: 160_u32.into(), l2_gas: 0_u32.into(), }, - false => GasVector::from_l1_gas(19593_u32.into()), + false => GasVector::from_l1_gas(19592_u32.into()), }; let expected_da_gas = match use_kzg_da { diff --git a/crates/blockifier/src/versioned_constants.rs b/crates/blockifier/src/versioned_constants.rs index 928c9b6940..2d719f6afd 100644 --- a/crates/blockifier/src/versioned_constants.rs +++ b/crates/blockifier/src/versioned_constants.rs @@ -456,7 +456,8 @@ impl<'de> Deserialize<'de> for VersionedConstants { secp256r1_new: versioned_constants .get_syscall_gas_cost(&SyscallSelector::Secp256r1New), keccak: versioned_constants.get_syscall_gas_cost(&SyscallSelector::Keccak), - keccak_round_cost: 180000, + keccak_round_cost: versioned_constants + .get_syscall_gas_cost(&SyscallSelector::KeccakRound), sha256_process_block: versioned_constants .get_syscall_gas_cost(&SyscallSelector::Sha256ProcessBlock), }; @@ -691,6 +692,7 @@ impl SyscallGasCosts { SyscallSelector::GetBlockHash => self.get_block_hash, SyscallSelector::GetExecutionInfo => self.get_execution_info, SyscallSelector::GetClassHashAt => self.get_class_hash_at, + SyscallSelector::KeccakRound => self.keccak_round_cost, SyscallSelector::Keccak => self.keccak, SyscallSelector::Sha256ProcessBlock => self.sha256_process_block, SyscallSelector::LibraryCall => self.library_call,