From e203e9fc7ba309a55181a24cc44ba4e1a9651566 Mon Sep 17 00:00:00 2001 From: Rodrigo Date: Sun, 13 Oct 2024 22:34:20 -0400 Subject: [PATCH] refactor: native syscall handler `new` method --- .../execution/native/entry_point_execution.rs | 28 ++++++++----------- .../src/execution/native/syscall_handler.rs | 15 ++-------- 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/crates/blockifier/src/execution/native/entry_point_execution.rs b/crates/blockifier/src/execution/native/entry_point_execution.rs index 2c9646d72a..118ee1e84c 100644 --- a/crates/blockifier/src/execution/native/entry_point_execution.rs +++ b/crates/blockifier/src/execution/native/entry_point_execution.rs @@ -22,28 +22,21 @@ pub fn execute_entry_point_call( ) -> EntryPointExecutionResult { let function_id = contract_class.get_entry_point(&call)?; - let mut syscall_handler: NativeSyscallHandler<'_> = NativeSyscallHandler::new( - state, - call.caller_address, - call.storage_address, - call.entry_point_selector, - resources, - context, - ); + let mut syscall_handler: NativeSyscallHandler<'_> = + NativeSyscallHandler::new(call, state, resources, context); let execution_result = contract_class.executor.invoke_contract_dynamic( &function_id, - &call.calldata.0, - Some(call.initial_gas.into()), + &syscall_handler.call.calldata.0.clone(), + Some(syscall_handler.call.initial_gas.into()), &mut syscall_handler, ); let call_result = execution_result.map_err(EntryPointExecutionError::NativeUnexpectedError)?; - create_call_info(call, call_result, syscall_handler) + create_callinfo(call_result, syscall_handler) } -fn create_call_info( - call: CallEntryPoint, +fn create_callinfo( call_result: ContractExecutionResult, syscall_handler: NativeSyscallHandler<'_>, ) -> Result { @@ -54,20 +47,21 @@ fn create_call_info( call_result.remaining_gas ), })?; - if remaining_gas > call.initial_gas { + + if remaining_gas > syscall_handler.call.initial_gas { return Err(PostExecutionError::MalformedReturnData { error_message: format!( "Unexpected remaining gas. Used gas is greater than initial gas: {} > {}", - remaining_gas, call.initial_gas + remaining_gas, syscall_handler.call.initial_gas ), } .into()); } - let gas_consumed = call.initial_gas - remaining_gas; + let gas_consumed = syscall_handler.call.initial_gas - remaining_gas; Ok(CallInfo { - call, + call: syscall_handler.call, execution: CallExecution { retdata: Retdata(call_result.return_values), events: syscall_handler.events, diff --git a/crates/blockifier/src/execution/native/syscall_handler.rs b/crates/blockifier/src/execution/native/syscall_handler.rs index a4ed00e23d..d0798b58a4 100644 --- a/crates/blockifier/src/execution/native/syscall_handler.rs +++ b/crates/blockifier/src/execution/native/syscall_handler.rs @@ -11,7 +11,6 @@ use cairo_native::starknet::{ U256, }; use cairo_vm::vm::runners::cairo_runner::ExecutionResources; -use starknet_api::core::{ContractAddress, EntryPointSelector}; use starknet_api::state::StorageKey; use starknet_types_core::felt::Felt; @@ -26,11 +25,7 @@ pub struct NativeSyscallHandler<'state> { pub state: &'state mut dyn State, pub resources: &'state mut ExecutionResources, pub context: &'state mut EntryPointExecutionContext, - - // Call information. - pub caller_address: ContractAddress, - pub contract_address: ContractAddress, - pub entry_point_selector: Felt, + pub call: CallEntryPoint, // Execution results. pub events: Vec, @@ -44,18 +39,14 @@ pub struct NativeSyscallHandler<'state> { impl<'state> NativeSyscallHandler<'state> { pub fn new( + call: CallEntryPoint, state: &'state mut dyn State, - caller_address: ContractAddress, - contract_address: ContractAddress, - entry_point_selector: EntryPointSelector, resources: &'state mut ExecutionResources, context: &'state mut EntryPointExecutionContext, ) -> NativeSyscallHandler<'state> { NativeSyscallHandler { state, - caller_address, - contract_address, - entry_point_selector: entry_point_selector.0, + call, resources, context, events: Vec::new(),