diff --git a/crates/blockifier/src/execution/native/syscall_handler.rs b/crates/blockifier/src/execution/native/syscall_handler.rs index 5fcfeb95de5..c691d0e5d6b 100644 --- a/crates/blockifier/src/execution/native/syscall_handler.rs +++ b/crates/blockifier/src/execution/native/syscall_handler.rs @@ -3,12 +3,17 @@ use std::hash::RandomState; use std::sync::Arc; use cairo_native::starknet::{ - ExecutionInfo, ExecutionInfoV2, Secp256k1Point, Secp256r1Point, StarknetSyscallHandler, - SyscallResult, U256, + ExecutionInfo, + ExecutionInfoV2, + Secp256k1Point, + Secp256r1Point, + StarknetSyscallHandler, + SyscallResult, + U256, }; use cairo_vm::vm::runners::cairo_runner::ExecutionResources; use starknet_api::contract_class::EntryPointType; -use starknet_api::core::{ClassHash, ContractAddress, EntryPointSelector}; +use starknet_api::core::{ClassHash, EntryPointSelector}; use starknet_api::state::StorageKey; use starknet_api::transaction::Calldata; use starknet_types_core::felt::Felt; @@ -111,8 +116,10 @@ impl<'state> NativeSyscallHandler<'state> { if *remaining_gas < required_gas { // Out of gas failure. - return Err(vec![Felt::from_hex(OUT_OF_GAS_ERROR) - .expect("Failed to parse OUT_OF_GAS_ERROR hex string")]); + return Err(vec![ + Felt::from_hex(OUT_OF_GAS_ERROR) + .expect("Failed to parse OUT_OF_GAS_ERROR hex string"), + ]); } *remaining_gas -= required_gas; @@ -180,8 +187,8 @@ impl<'state> StarknetSyscallHandler for &mut NativeSyscallHandler<'state> { entry_point_selector: EntryPointSelector(function_selector), calldata: wrapper_calldata, // The call context remains the same in a library call. - storage_address: self.contract_address, - caller_address: self.caller_address, + storage_address: self.call.storage_address, + caller_address: self.call.caller_address, call_type: CallType::Delegate, initial_gas: u64::try_from(*remaining_gas) .expect("Failed to convert gas (u128 -> u64)"), 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 2027ebd7efb..4e2a5d08722 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/library_call.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/library_call.rs @@ -29,7 +29,10 @@ use crate::test_utils::{ }; use crate::versioned_constants::VersionedConstants; -#[test_case(FeatureContract::TestContract(CairoVersion::Native), 189470; "Native")] +#[cfg_attr( + feature = "cairo_native", + test_case(FeatureContract::TestContract(CairoVersion::Native), 189470; "Native") +)] #[test_case(FeatureContract::TestContract(CairoVersion::Cairo1), REQUIRED_GAS_LIBRARY_CALL_TEST; "VM")] fn test_library_call(test_contract: FeatureContract, expected_gas: u64) { let chain_info = &ChainInfo::create_for_testing(); @@ -61,7 +64,10 @@ fn test_library_call(test_contract: FeatureContract, expected_gas: u64) { ); } -#[test_case(FeatureContract::TestContract(CairoVersion::Native); "Native")] +#[cfg_attr( + feature = "cairo_native", + test_case(FeatureContract::TestContract(CairoVersion::Native); "Native") +)] #[test_case(FeatureContract::TestContract(CairoVersion::Cairo1); "VM")] fn test_library_call_assert_fails(test_contract: FeatureContract) { let chain_info = &ChainInfo::create_for_testing(); @@ -89,22 +95,34 @@ fn test_library_call_assert_fails(test_contract: FeatureContract) { "(0x7820213d2079 ('x != y'), 0x454e545259504f494e545f4641494c4544 \ ('ENTRYPOINT_FAILED'))" } + #[cfg(feature = "cairo_native")] CairoVersion::Native => "0x7820213d2079 ('x != y')", }; assert_eq!(format_panic_data(&call_info.execution.retdata.0), expected_err); } -#[test_case(FeatureContract::TestContract(CairoVersion::Native), 518110; "Native")] +#[cfg_attr( + feature = "cairo_native", + test_case(FeatureContract::TestContract(CairoVersion::Native), 518110; "Native") +)] #[test_case(FeatureContract::TestContract(CairoVersion::Cairo1), 478110; "VM")] fn test_nested_library_call(test_contract: FeatureContract, expected_gas: u64) { // Todo(pwhite) 2024/10/28: Execution resources from the VM & Native are mesaured differently // helper function to change the expected resource values from both of executions // When gas is changed to be the same between VM and Native this should be removed. + #[cfg_attr(not(feature = "cairo_native"), allow(unused_variables))] fn if_native(test_contract: &FeatureContract) -> impl Fn(T, T) -> T + '_ { move |native: T, non_native: T| { - if matches!(test_contract, FeatureContract::TestContract(CairoVersion::Native)) { - native - } else { + #[cfg(feature = "cairo_native")] + { + if matches!(test_contract, FeatureContract::TestContract(CairoVersion::Native)) { + native + } else { + non_native + } + } + #[cfg(not(feature = "cairo_native"))] + { non_native } }