Skip to content

add ContractExecutor dispatch enum (Aot + Emu)#1598

Open
avi-starkware wants to merge 2 commits into
starkware-libs:mainfrom
avi-starkware:avi/cairo_native/contract-executor
Open

add ContractExecutor dispatch enum (Aot + Emu)#1598
avi-starkware wants to merge 2 commits into
starkware-libs:mainfrom
avi-starkware:avi/cairo_native/contract-executor

Conversation

@avi-starkware
Copy link
Copy Markdown
Collaborator

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_executor module.

Changes

  • src/executor/contract_executor.rs — new module:
    • pub enum ContractExecutor { Aot(AotContractExecutor), Emu(EmuContractInfo) }, with Emu gated on the sierra-emu feature added in add SierraEmuSyscallBridge for cairo-native ↔ sierra-emu interop #1597.
    • 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.

Test plan

  • CI passes with default features
  • CI passes with --features sierra-emu

Context

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 import cairo_native::ContractExecutor.

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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant