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(execution): share enable_reverts check #1494

Merged
merged 1 commit into from
Oct 21, 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
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
Loading