From 55e0f857c3a85dcce78efcda0966d4323a5865a6 Mon Sep 17 00:00:00 2001 From: Bohdan Ohorodnii Date: Tue, 29 Oct 2024 17:44:55 +0200 Subject: [PATCH] fix: problems after rebase --- .../execution/native/entry_point_execution.rs | 2 +- .../src/execution/native/syscall_handler.rs | 15 ++++--------- .../syscalls/syscall_tests/deploy.rs | 21 +++++++++++++++---- .../syscall_tests/storage_read_write.rs | 5 ++++- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/crates/blockifier/src/execution/native/entry_point_execution.rs b/crates/blockifier/src/execution/native/entry_point_execution.rs index 17659abfca..161045fac1 100644 --- a/crates/blockifier/src/execution/native/entry_point_execution.rs +++ b/crates/blockifier/src/execution/native/entry_point_execution.rs @@ -44,7 +44,7 @@ pub fn execute_entry_point_call( Ok(res) => Ok(res), }?; - create_call_info(call, call_result, syscall_handler) + create_callinfo(call_result, syscall_handler) } fn create_callinfo( diff --git a/crates/blockifier/src/execution/native/syscall_handler.rs b/crates/blockifier/src/execution/native/syscall_handler.rs index c7c28b74c3..04fb091ad0 100644 --- a/crates/blockifier/src/execution/native/syscall_handler.rs +++ b/crates/blockifier/src/execution/native/syscall_handler.rs @@ -12,12 +12,7 @@ use cairo_native::starknet::{ U256, }; use cairo_vm::vm::runners::cairo_runner::ExecutionResources; -use starknet_api::core::{ - calculate_contract_address, - ClassHash, - ContractAddress, - EntryPointSelector, -}; +use starknet_api::core::{calculate_contract_address, ClassHash, ContractAddress}; use starknet_api::state::StorageKey; use starknet_api::transaction::{Calldata, ContractAddressSalt}; use starknet_types_core::felt::Felt; @@ -47,8 +42,6 @@ pub struct NativeSyscallHandler<'state> { pub l2_to_l1_messages: Vec, pub inner_calls: Vec, - pub syscall_counter: SyscallCounter, - // Additional information gathered during execution. pub read_values: Vec, pub accessed_keys: HashSet, @@ -174,7 +167,7 @@ impl<'state> StarknetSyscallHandler for &mut NativeSyscallHandler<'state> { self.context.gas_costs().deploy_gas_cost, )?; - let deployer_address = self.contract_address; + let deployer_address = self.call.storage_address; let deployer_address_for_calculation = if deploy_from_zero { ContractAddress::default() } else { deployer_address }; @@ -268,7 +261,7 @@ impl<'state> StarknetSyscallHandler for &mut NativeSyscallHandler<'state> { let key = StorageKey::try_from(address).map_err(|e| encode_str_as_felts(&e.to_string()))?; - let read_result = self.state.get_storage_at(self.contract_address, key); + let read_result = self.state.get_storage_at(self.call.storage_address, key); let value = read_result.map_err(|e| encode_str_as_felts(&e.to_string()))?; self.accessed_keys.insert(key); @@ -293,7 +286,7 @@ impl<'state> StarknetSyscallHandler for &mut NativeSyscallHandler<'state> { let key = StorageKey::try_from(address).map_err(|e| encode_str_as_felts(&e.to_string()))?; self.accessed_keys.insert(key); - let write_result = self.state.set_storage_at(self.contract_address, key, value); + let write_result = self.state.set_storage_at(self.call.storage_address, key, value); write_result.map_err(|e| encode_str_as_felts(&e.to_string()))?; Ok(()) diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/deploy.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/deploy.rs index b4b6105f09..c729dd4f5c 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/deploy.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/deploy.rs @@ -15,7 +15,10 @@ use crate::test_utils::initial_test_state::test_state; use crate::test_utils::{calldata_for_deploy_test, trivial_external_entry_point_new, CairoVersion}; #[test_case(FeatureContract::TestContract(CairoVersion::Cairo1), 206800;"VM")] -#[test_case(FeatureContract::TestContract(CairoVersion::Native), 216800;"Native")] +#[cfg_attr( + feature = "cairo_native", + test_case(FeatureContract::TestContract(CairoVersion::Native), 216800;"Native") +)] fn no_constructor(deployer_contract: FeatureContract, expected_gas: u64) { // TODO(Yoni): share the init code of the tests in this file. @@ -64,7 +67,10 @@ fn no_constructor(deployer_contract: FeatureContract, expected_gas: u64) { } #[test_case(FeatureContract::TestContract(CairoVersion::Cairo1);"VM")] -#[test_case(FeatureContract::TestContract(CairoVersion::Native);"Native")] +#[cfg_attr( + feature = "cairo_native", + test_case(FeatureContract::TestContract(CairoVersion::Native);"Native") +)] fn no_constructor_nonempty_calldata(deployer_contract: FeatureContract) { let empty_contract = FeatureContract::Empty(CairoVersion::Cairo1); let class_hash = empty_contract.get_class_hash(); @@ -89,8 +95,12 @@ fn no_constructor_nonempty_calldata(deployer_contract: FeatureContract) { constructor." )); } -#[test_case(FeatureContract::TestContract(CairoVersion::Native),236750, 15210;"Native")] + #[test_case(FeatureContract::TestContract(CairoVersion::Cairo1),216750, 5210;"VM")] +#[cfg_attr( + feature = "cairo_native", + test_case(FeatureContract::TestContract(CairoVersion::Native),236750, 15210;"Native") +)] fn with_constructor( deployer_contract: FeatureContract, expected_gas: u64, @@ -153,7 +163,10 @@ fn with_constructor( } #[test_case(FeatureContract::TestContract(CairoVersion::Cairo1);"VM")] -#[test_case(FeatureContract::TestContract(CairoVersion::Native);"Native")] +#[cfg_attr( + feature = "cairo_native", + test_case(FeatureContract::TestContract(CairoVersion::Native);"Native") +)] fn to_unavailable_address(deployer_contract: FeatureContract) { let empty_contract = FeatureContract::Empty(CairoVersion::Cairo1); let mut state = test_state( diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/storage_read_write.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/storage_read_write.rs index cd3e8354f8..bebde966a4 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/storage_read_write.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/storage_read_write.rs @@ -13,7 +13,10 @@ use crate::test_utils::contracts::FeatureContract; use crate::test_utils::initial_test_state::test_state; use crate::test_utils::{trivial_external_entry_point_new, CairoVersion, BALANCE}; -#[test_case(FeatureContract::TestContract(CairoVersion::Native), 27290; "Native")] +#[cfg_attr( + feature = "cairo_native", + test_case(FeatureContract::TestContract(CairoVersion::Native), 27290; "Native") +)] #[test_case(FeatureContract::TestContract(CairoVersion::Cairo1), REQUIRED_GAS_STORAGE_READ_WRITE_TEST; "VM")] fn test_storage_read_write(test_contract: FeatureContract, expected_gas: u64) { let chain_info = &ChainInfo::create_for_testing();