Skip to content

add ContractExecutor dispatch enum (Aot + Emu)#1608

Open
avi-starkware wants to merge 1 commit into
avi/cairo_native/sierra-emu-bridgefrom
avi/cairo_native/contract-executor
Open

add ContractExecutor dispatch enum (Aot + Emu)#1608
avi-starkware wants to merge 1 commit into
avi/cairo_native/sierra-emu-bridgefrom
avi/cairo_native/contract-executor

Conversation

@avi-starkware
Copy link
Copy Markdown
Collaborator

Supersedes #1598 — reopened from starkware-libs/cairo_native so the stack can be expressed via base branches. Stacked on #1607. No code changes.

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 #1607 (SierraEmuSyscallBridge). Merge #1607 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 #1607.
    • 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 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`.
@github-actions
Copy link
Copy Markdown

❌ Code is not formatted! Please run cargo format and push the changes.

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