Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(blockifier): native syscall handler new method params #1380

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions crates/blockifier/src/execution/native/entry_point_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,21 @@ pub fn execute_entry_point_call(
) -> EntryPointExecutionResult<CallInfo> {
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<CallInfo, EntryPointExecutionError> {
Expand All @@ -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,
Expand Down
15 changes: 3 additions & 12 deletions crates/blockifier/src/execution/native/syscall_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<OrderedEvent>,
Expand All @@ -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(),
Expand Down
Loading