add ContractExecutor dispatch enum (Aot + Emu)#1612
Open
avi-starkware wants to merge 2 commits into
Open
Conversation
|
✅ Code is now correctly formatted. |
5 tasks
b3a574c to
319a6be
Compare
98ed085 to
64c12b3
Compare
Adds a public dispatch enum so a single call site can pick between the
AOT executor and the sierra-emu interpreter at runtime, without forcing
every caller to maintain its own match.
- ContractExecutor { Aot(AotContractExecutor), Emu(EmuContractInfo) },
with Emu gated on the new sierra-emu cargo feature.
- EmuContractInfo carries Arc<Program> so the program is shared across
invocations rather than cloned per call.
- ContractExecutor::run dispatches: Aot delegates to
AotContractExecutor::run; Emu constructs a sierra_emu::VirtualMachine
and runs it with the caller's syscall handler directly. No adapter is
needed: the trait is shared via the cairo-native-syscalls crate.
- Cargo: new `sierra-emu` feature (= ["dep:sierra-emu"]). The existing
`with-trace-dump` feature now activates `sierra-emu` instead of the
optional dep directly.
Companion to the bridge-free design: with cairo-native and sierra-emu
sharing one trait, the SierraEmuSyscallBridge that PR #1597 / #1607
introduced is no longer necessary.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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>
319a6be to
92ecf03
Compare
64c12b3 to
7e5fcd7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a public dispatch enum so a single call site can pick between cairo-native's AOT executor and the sierra-emu interpreter at runtime, without forcing every caller to maintain its own match.
Replaces #1598 / #1608. The new version drops
SierraEmuSyscallBridgeentirely — the prior PR in this stack (extractingcairo-native-syscalls) made cairo-native's and sierra-emu'sStarknetSyscallHandlerthe same trait, so the handler flows through both paths unchanged.Changes
src/executor/contract_executor.rs(new):pub enum ContractExecutor { Aot(AotContractExecutor), Emu(EmuContractInfo) }, withEmugated on the newsierra-emucargo feature.pub struct EmuContractInfo { program: Arc<Program>, entry_points: …, sierra_version: … }. TheArc<Program>is shared across invocations rather than cloned per call.Fromimpls for both variants.ContractExecutor::rundispatches:Aotarm →AotContractExecutor::run.Emuarm →sierra_emu::VirtualMachine::new_starknet(…).run(&mut syscall_handler). No bridge wrapping the handler.convert_builtin_coststranslatescairo_native::utils::BuiltinCosts→sierra_emu::BuiltinCosts(these types are still separate; only the syscall handler shape converged).src/executor.rs: register the new module and re-exportContractExecutor(+EmuContractInfounder thesierra-emufeature).Cargo.toml:sierra-emu = ["dep:sierra-emu"]feature.with-trace-dumpnow depends onsierra-emurather than the optional dep directly, so the two paths agree.Diff against the original #1608
EmuarmSierraEmuSyscallBridgeconvert_u256/convert_secp_*_point/convert_execution_info{,_v2}Stack
ContractExecutor(supersedes add ContractExecutor dispatch enum (Aot + Emu) #1598 / add ContractExecutor dispatch enum (Aot + Emu) #1608)run_with_libfunc_profile+AotWithProgram(supersedes add run_with_libfunc_profile + AotWithProgram variant for ContractExecutor #1599 / add run_with_libfunc_profile + AotWithProgram variant for ContractExecutor #1609)Test plan
cargo check(default features) cleancargo check --features sierra-emucleancargo check --features with-trace-dumpclean (transitively activates sierra-emu)cargo check --workspace --all-featuresclean