diff --git a/crates/blockifier/src/execution/syscalls/hint_processor.rs b/crates/blockifier/src/execution/syscalls/hint_processor.rs index 81d91cf1b4..86d4cf3d25 100644 --- a/crates/blockifier/src/execution/syscalls/hint_processor.rs +++ b/crates/blockifier/src/execution/syscalls/hint_processor.rs @@ -26,7 +26,6 @@ use starknet_types_core::felt::{Felt, FromStrError}; use thiserror::Error; use crate::abi::sierra_types::SierraTypeError; -use crate::execution::call_info::CallInfo; use crate::execution::common_hints::{ExecutionMode, HintExecutionResult}; use crate::execution::entry_point::{CallEntryPoint, EntryPointExecutionContext}; use crate::execution::errors::{ConstructorEntryPointExecutionError, EntryPointExecutionError}; @@ -750,35 +749,7 @@ pub fn execute_inner_call( syscall_handler: &mut SyscallHintProcessor<'_>, remaining_gas: &mut u64, ) -> SyscallResult { - let revert_idx = syscall_handler.base.context.revert_infos.0.len(); - - let call_info = - call.execute(syscall_handler.base.state, syscall_handler.base.context, remaining_gas)?; - - let mut raw_retdata = call_info.execution.retdata.0.clone(); - let failed = call_info.execution.failed; - syscall_handler.base.inner_calls.push(call_info); - if failed { - syscall_handler.base.context.revert(revert_idx, syscall_handler.base.state)?; - - // Delete events and l2_to_l1_messages from the reverted call. - let reverted_call = &mut syscall_handler.base.inner_calls.last_mut().unwrap(); - let mut stack: Vec<&mut CallInfo> = vec![reverted_call]; - while let Some(call_info) = stack.pop() { - call_info.execution.events.clear(); - call_info.execution.l2_to_l1_messages.clear(); - // Add inner calls that did not fail to the stack. - // The events and l2_to_l1_messages of the failed calls were already cleared. - stack.extend( - call_info.inner_calls.iter_mut().filter(|call_info| !call_info.execution.failed), - ); - } - - raw_retdata - .push(Felt::from_hex(ENTRYPOINT_FAILED_ERROR).map_err(SyscallExecutionError::from)?); - return Err(SyscallExecutionError::SyscallError { error_data: raw_retdata }); - } - + let raw_retdata = syscall_handler.base.execute_inner_call(call, remaining_gas)?; create_retdata_segment(vm, syscall_handler, &raw_retdata) } diff --git a/crates/blockifier/src/execution/syscalls/syscall_base.rs b/crates/blockifier/src/execution/syscalls/syscall_base.rs index 8781b507a6..c4b049da00 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_base.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_base.rs @@ -12,6 +12,7 @@ use crate::execution::entry_point::{CallEntryPoint, EntryPointExecutionContext}; use crate::execution::syscalls::hint_processor::{ SyscallExecutionError, BLOCK_NUMBER_OUT_OF_RANGE_ERROR, + ENTRYPOINT_FAILED_ERROR, }; use crate::state::state_api::State; @@ -97,4 +98,44 @@ impl<'state> SyscallHandlerBase<'state> { ContractAddress::try_from(Felt::from(constants::BLOCK_HASH_CONTRACT_ADDRESS))?; Ok(self.state.get_storage_at(block_hash_contract_address, key)?) } + + pub fn execute_inner_call( + &mut self, + call: CallEntryPoint, + remaining_gas: &mut u64, + ) -> SyscallResult> { + let revert_idx = self.context.revert_infos.0.len(); + + let call_info = call.execute(self.state, self.context, remaining_gas)?; + + let mut raw_retdata = call_info.execution.retdata.0.clone(); + let failed = call_info.execution.failed; + self.inner_calls.push(call_info); + if failed { + self.context.revert(revert_idx, self.state)?; + + // Delete events and l2_to_l1_messages from the reverted call. + let reverted_call = &mut self.inner_calls.last_mut().unwrap(); + let mut stack: Vec<&mut CallInfo> = vec![reverted_call]; + while let Some(call_info) = stack.pop() { + call_info.execution.events.clear(); + call_info.execution.l2_to_l1_messages.clear(); + // Add inner calls that did not fail to the stack. + // The events and l2_to_l1_messages of the failed calls were already cleared. + stack.extend( + call_info + .inner_calls + .iter_mut() + .filter(|call_info| !call_info.execution.failed), + ); + } + + raw_retdata.push( + Felt::from_hex(ENTRYPOINT_FAILED_ERROR).map_err(SyscallExecutionError::from)?, + ); + return Err(SyscallExecutionError::SyscallError { error_data: raw_retdata }); + } + + Ok(raw_retdata) + } }