Skip to content

add SierraEmuSyscallBridge for cairo-native ↔ sierra-emu interop#1597

Open
avi-starkware wants to merge 1 commit into
starkware-libs:mainfrom
avi-starkware:avi/cairo_native/sierra-emu-bridge
Open

add SierraEmuSyscallBridge for cairo-native ↔ sierra-emu interop#1597
avi-starkware wants to merge 1 commit into
starkware-libs:mainfrom
avi-starkware:avi/cairo_native/sierra-emu-bridge

Conversation

@avi-starkware
Copy link
Copy Markdown
Collaborator

@avi-starkware avi-starkware commented Apr 26, 2026

Summary

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 starkware-libs/sequencer) to maintain their own copy of the conversion glue between the two crates.

Changes

  • Cargo.toml — new sierra-emu feature flag that enables dep:sierra-emu and the new module. with-trace-dump now depends on sierra-emu instead of pulling in dep:sierra-emu directly.
  • src/sierra_emu_bridge.rsSierraEmuSyscallBridge<'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.

Stack

This is the first of two cairo_native PRs:

  1. add SierraEmuSyscallBridge for cairo-native ↔ sierra-emu interop #1597 (this) — SierraEmuSyscallBridge
  2. add ContractExecutor dispatch enum (Aot + Emu) #1598ContractExecutor dispatch enum (consumes the bridge)

Companion sequencer PR that drops the local sierra-emu glue and imports from cairo-native: starkware-libs/sequencer#13880.

Test plan

  • CI passes with default features
  • CI passes with --features sierra-emu
  • CI passes with --features with-trace-dump (which now transitively activates sierra-emu)

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.
avi-starkware added a commit that referenced this pull request May 14, 2026
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>
avi-starkware added a commit that referenced this pull request May 14, 2026
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>
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