Skip to content

Commit

Permalink
refactor(execution): share enable_reverts check (#1494)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoni-Starkware authored and guy-starkware committed Oct 22, 2024
1 parent 0f9a9d7 commit 254ba3d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
12 changes: 2 additions & 10 deletions crates/blockifier/src/execution/entry_point_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use crate::execution::execution_utils::{
ReadOnlySegments,
SEGMENT_ARENA_BUILTIN_SIZE,
};
use crate::execution::stack_trace::extract_trailing_cairo1_revert_trace;
use crate::execution::syscalls::hint_processor::SyscallHintProcessor;
use crate::state::state_api::State;
use crate::versioned_constants::GasCosts;
Expand Down Expand Up @@ -99,21 +98,14 @@ pub fn execute_entry_point_call(
bytecode_length,
)?;

let call_info = finalize_execution(
Ok(finalize_execution(
runner,
syscall_handler,
previous_resources,
n_total_args,
program_extra_data_length,
tracked_resource,
)?;
if call_info.execution.failed && !context.versioned_constants().enable_reverts {
return Err(EntryPointExecutionError::ExecutionFailed {
error_trace: extract_trailing_cairo1_revert_trace(&call_info),
});
}

Ok(call_info)
)?)
}

// Collects the set PC values that were visited during the entry point execution.
Expand Down
14 changes: 13 additions & 1 deletion crates/blockifier/src/execution/execution_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ use crate::execution::entry_point::{
EntryPointExecutionContext,
EntryPointExecutionResult,
};
use crate::execution::errors::{ConstructorEntryPointExecutionError, PostExecutionError};
use crate::execution::errors::{
ConstructorEntryPointExecutionError,
EntryPointExecutionError,
PostExecutionError,
};
use crate::execution::native::entry_point_execution as native_entry_point_execution;
use crate::execution::stack_trace::extract_trailing_cairo1_revert_trace;
use crate::execution::{deprecated_entry_point_execution, entry_point_execution};
use crate::state::errors::StateError;
use crate::state::state_api::State;
Expand Down Expand Up @@ -76,6 +81,13 @@ pub fn execute_entry_point_call_wrapper(
context.tracked_resource_stack.pop();

if let Ok(call_info) = &res {
if call_info.execution.failed && !context.versioned_constants().enable_reverts {
// Reverts are disabled.
return Err(EntryPointExecutionError::ExecutionFailed {
error_trace: extract_trailing_cairo1_revert_trace(call_info),
});
}

update_remaining_gas(remaining_gas, call_info);
}

Expand Down
19 changes: 3 additions & 16 deletions crates/blockifier/src/execution/native/entry_point_execution.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use cairo_native::execution_result::ContractExecutionResult;
use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use num_traits::ToPrimitive;
use starknet_api::execution_utils::format_panic_data;

use crate::execution::call_info::{CallExecution, CallInfo, Retdata};
use crate::execution::contract_class::{NativeContractClassV1, TrackedResource};
Expand Down Expand Up @@ -39,23 +38,11 @@ pub fn execute_entry_point_call(
&mut syscall_handler,
);

let call_result = match execution_result {
Err(runner_err) => Err(EntryPointExecutionError::NativeUnexpectedError(runner_err)),
Ok(res)
if res.failure_flag
&& !syscall_handler.context.versioned_constants().enable_reverts =>
{
Err(EntryPointExecutionError::ExecutionFailed {
error_trace: format_panic_data(&res.return_values),
})
}
Ok(res) => Ok(res),
}?;

create_callinfo(call, call_result, syscall_handler)
let call_result = execution_result.map_err(EntryPointExecutionError::NativeUnexpectedError)?;
create_call_info(call, call_result, syscall_handler)
}

fn create_callinfo(
fn create_call_info(
call: CallEntryPoint,
call_result: ContractExecutionResult,
syscall_handler: NativeSyscallHandler<'_>,
Expand Down

0 comments on commit 254ba3d

Please sign in to comment.