Skip to content

Commit 38c5f2f

Browse files
avi-starkwareclaude
andcommitted
propagate sierra-emu VM failure as Error from ContractExecutor::Emu
The Emu arm previously called .expect() on VirtualMachine::run, which aborts the host on any internal VM failure. The Aot arm propagates errors via Result; align the Emu arm with it. VirtualMachine::run returns Option<ContractExecutionResult> (None means "VM never produced a final state"). Convert None to Error::UnexpectedValue with a descriptive message so callers can decide how to handle. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 761c5f6 commit 38c5f2f

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/executor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
//! This module provides methods to execute the programs, either via JIT or compiled ahead
44
//! of time. It also provides a cache to avoid recompiling previously compiled programs.
55
6+
#[cfg(feature = "sierra-emu")]
7+
pub use self::contract_executor::EmuContractInfo;
68
pub use self::{
79
aot::AotNativeExecutor, contract::AotContractExecutor, contract_executor::ContractExecutor,
810
jit::JitNativeExecutor,
911
};
10-
#[cfg(feature = "sierra-emu")]
11-
pub use self::contract_executor::EmuContractInfo;
1212
use crate::{
1313
arch::{AbiArgument, ValueWithInfoWrapper},
1414
error::{panic::ToNativeAssertError, Error},

src/executor/contract_executor.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use starknet_types_core::felt::Felt;
1515
#[cfg(feature = "sierra-emu")]
1616
use std::sync::Arc;
1717

18+
#[cfg(feature = "sierra-emu")]
19+
use crate::error::Error;
1820
use crate::error::Result;
1921
use crate::execution_result::ContractExecutionResult;
2022
use crate::executor::AotContractExecutor;
@@ -89,9 +91,11 @@ impl ContractExecutor {
8991

9092
virtual_machine.call_contract(selector, gas, args.to_vec(), emu_builtin_costs);
9193

92-
let result = virtual_machine
93-
.run(&mut syscall_handler)
94-
.expect("sierra-emu VM run failed");
94+
// `VirtualMachine::run` returns `None` when the VM never produced a
95+
// final state — propagate as an error rather than aborting the host.
96+
let result = virtual_machine.run(&mut syscall_handler).ok_or_else(|| {
97+
Error::UnexpectedValue("sierra-emu VM produced no final state".to_string())
98+
})?;
9599

96100
Ok(ContractExecutionResult {
97101
remaining_gas: result.remaining_gas,

0 commit comments

Comments
 (0)