add ContractExecutor dispatch enum (Aot + Emu)#1598
Open
avi-starkware wants to merge 2 commits into
Open
Conversation
Adds an adapter type and feature flag that lets a cairo-native
StarknetSyscallHandler drive the sierra-emu virtual machine, removing
the need for downstream consumers (e.g. blockifier in starknet-libs/sequencer)
to maintain their own copy of the conversion glue between the two crates.
- New `sierra-emu` feature flag in Cargo.toml that enables `dep:sierra-emu`
and the new `sierra_emu_bridge` module. `with-trace-dump` now depends on
the new feature instead of pulling in `dep:sierra-emu` directly.
- `SierraEmuSyscallBridge<'a, H>` wraps any `&mut H` where
`H: cairo_native::starknet::StarknetSyscallHandler` and implements
`sierra_emu::starknet::StarknetSyscallHandler` for it.
- Conversion helpers (`convert_u256`, `convert_secp_*_point`,
`convert_execution_info{,_v2}`, etc.) handle the type-level translation
between the two crates' overlapping but distinct syscall surfaces.
- The Secp256k1 / Secp256r1 conversion treats `(0, 0)` as the point at
infinity when going from sierra-emu (which has no `is_infinity` flag)
to cairo-native — sierra-emu represents the identity element as `(0, 0)`
but cairo-native expects an explicit flag.
Adds a public dispatch enum that lets a single call site choose between
the AOT executor and the sierra-emu interpreter at runtime, without
forcing every caller to maintain its own match.
- `pub enum ContractExecutor { Aot(AotContractExecutor), Emu(EmuContractInfo) }`,
with `Emu` gated on the `sierra-emu` feature added in the previous PR.
- `From` impls for both variants.
- `ContractExecutor::run` dispatches: the `Aot` arm calls
`AotContractExecutor::run` directly; the `Emu` arm constructs a
`sierra_emu::VirtualMachine`, wraps the cairo-native syscall handler in
`SierraEmuSyscallBridge`, and converts the result.
- `EmuContractInfo` carries `Arc<Program>` so the program is shared across
invocations rather than cloned per call.
This is the same dispatch shape that downstream consumers (e.g. the
blockifier in starkware-libs/sequencer) currently maintain locally; with
this PR they can drop their copy and import `cairo_native::ContractExecutor`.
This was referenced Apr 26, 2026
This was referenced May 10, 2026
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 that lets a single call site choose between the AOT executor and the sierra-emu interpreter at runtime, without forcing every caller to maintain its own match.
Important
Stacked on top of #1597 (SierraEmuSyscallBridge). Merge #1597 first; the diff for this PR will then narrow to just the new
contract_executormodule.Changes
src/executor/contract_executor.rs— new module:pub enum ContractExecutor { Aot(AotContractExecutor), Emu(EmuContractInfo) }, withEmugated on thesierra-emufeature added in add SierraEmuSyscallBridge for cairo-native ↔ sierra-emu interop #1597.Fromimpls for both variants.ContractExecutor::rundispatches: theAotarm callsAotContractExecutor::rundirectly; theEmuarm constructs asierra_emu::VirtualMachine, wraps the cairo-native syscall handler inSierraEmuSyscallBridge, and converts the result.EmuContractInfocarriesArc<Program>so the program is shared across invocations rather than cloned per call.Test plan
--features sierra-emuContext
This is the dispatch shape that downstream consumers (e.g. the blockifier in
starkware-libs/sequencer) currently maintain locally; with this PR they can drop their copy and importcairo_native::ContractExecutor.