Skip to content

add ContractExecutor dispatch enum (Aot + Emu)#1612

Open
avi-starkware wants to merge 1 commit into
avi/cairo_native/syscall-types-cratefrom
avi/cairo_native/contract-executor-2
Open

add ContractExecutor dispatch enum (Aot + Emu)#1612
avi-starkware wants to merge 1 commit into
avi/cairo_native/syscall-types-cratefrom
avi/cairo_native/contract-executor-2

Conversation

@avi-starkware
Copy link
Copy Markdown
Collaborator

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 SierraEmuSyscallBridge entirely — the prior PR in this stack (extracting cairo-native-syscalls) made cairo-native's and sierra-emu's StarknetSyscallHandler the same trait, so the handler flows through both paths unchanged.

Changes

  • src/executor/contract_executor.rs (new):
    • pub enum ContractExecutor { Aot(AotContractExecutor), Emu(EmuContractInfo) }, with Emu gated on the new sierra-emu cargo feature.
    • pub struct EmuContractInfo { program: Arc<Program>, entry_points: …, sierra_version: … }. The Arc<Program> is shared across invocations rather than cloned per call.
    • From impls for both variants.
    • ContractExecutor::run dispatches:
      • Aot arm → AotContractExecutor::run.
      • Emu arm → sierra_emu::VirtualMachine::new_starknet(…).run(&mut syscall_handler). No bridge wrapping the handler.
    • convert_builtin_costs translates cairo_native::utils::BuiltinCostssierra_emu::BuiltinCosts (these types are still separate; only the syscall handler shape converged).
  • src/executor.rs: register the new module and re-export ContractExecutor (+ EmuContractInfo under the sierra-emu feature).
  • Cargo.toml:
    • new sierra-emu = ["dep:sierra-emu"] feature.
    • with-trace-dump now depends on sierra-emu rather than the optional dep directly, so the two paths agree.

Diff against the original #1608

Aspect #1608 (closed) this PR
Handler in Emu arm wrapped in SierraEmuSyscallBridge passed directly
Bridge file required doesn't exist
Type conversions convert_u256 / convert_secp_*_point / convert_execution_info{,_v2} none (types are identical via re-export)

Stack

  1. align sierra-emu StarknetSyscallHandler trait/types with cairo-native #1610 — trait alignment
  2. extract shared cairo-native-syscalls crate #1611 — extract shared crate
  3. this PRContractExecutor (supersedes add ContractExecutor dispatch enum (Aot + Emu) #1598 / add ContractExecutor dispatch enum (Aot + Emu) #1608)
  4. (next) 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) clean
  • cargo check --features sierra-emu clean
  • cargo check --features with-trace-dump clean (transitively activates sierra-emu)
  • cargo check --workspace --all-features clean
  • CI green

@github-actions
Copy link
Copy Markdown

ghost commented May 14, 2026

✅ Code is now correctly formatted.

@avi-starkware avi-starkware force-pushed the avi/cairo_native/syscall-types-crate branch from b3a574c to 319a6be Compare May 14, 2026 12:26
@avi-starkware avi-starkware force-pushed the avi/cairo_native/contract-executor-2 branch from 98ed085 to 64c12b3 Compare May 14, 2026 12:26
@avi-starkware avi-starkware force-pushed the avi/cairo_native/syscall-types-crate branch from 319a6be to 92ecf03 Compare May 14, 2026 12:33
@avi-starkware avi-starkware force-pushed the avi/cairo_native/contract-executor-2 branch from 64c12b3 to 7e5fcd7 Compare May 14, 2026 12:33
@avi-starkware avi-starkware force-pushed the avi/cairo_native/syscall-types-crate branch from 92ecf03 to 3b3e5af Compare May 17, 2026 11:57
@avi-starkware avi-starkware force-pushed the avi/cairo_native/contract-executor-2 branch from 7e5fcd7 to 4176352 Compare May 17, 2026 11:57
@avi-starkware avi-starkware force-pushed the avi/cairo_native/syscall-types-crate branch from 3b3e5af to 24f61ba Compare May 17, 2026 12:08
@avi-starkware avi-starkware force-pushed the avi/cairo_native/contract-executor-2 branch from 4176352 to 7af0508 Compare May 17, 2026 12:08
@avi-starkware avi-starkware force-pushed the avi/cairo_native/syscall-types-crate branch from 24f61ba to 0ae0d06 Compare May 17, 2026 13:24
@avi-starkware avi-starkware force-pushed the avi/cairo_native/contract-executor-2 branch from 7af0508 to 38c5f2f Compare May 17, 2026 13:24
@avi-starkware avi-starkware force-pushed the avi/cairo_native/syscall-types-crate branch from 0ae0d06 to 0791b36 Compare May 17, 2026 13:27
@avi-starkware avi-starkware force-pushed the avi/cairo_native/contract-executor-2 branch from 38c5f2f to 81093b3 Compare May 17, 2026 13:27
@avi-starkware avi-starkware force-pushed the avi/cairo_native/syscall-types-crate branch from 0791b36 to 4e80562 Compare May 17, 2026 13:58
@avi-starkware avi-starkware force-pushed the avi/cairo_native/contract-executor-2 branch from 81093b3 to 4f53f27 Compare May 17, 2026 13:58
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-starknet-syscalls crate.
  VirtualMachine::run's `Option` return is propagated as
  Error::UnexpectedValue rather than `.expect()`-aborted, matching the
  Aot arm's error-handling style.
- 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>
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