Skip to content

blockifier: adopt cairo_native::ContractExecutor for AOT + sierra-emu dispatch#13880

Open
avi-starkware wants to merge 2 commits into
main-v0.14.2from
avi/blockifier/use-cairo-native-executor
Open

blockifier: adopt cairo_native::ContractExecutor for AOT + sierra-emu dispatch#13880
avi-starkware wants to merge 2 commits into
main-v0.14.2from
avi/blockifier/use-cairo-native-executor

Conversation

@avi-starkware
Copy link
Copy Markdown
Collaborator

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

Summary

Replaces the local AotContractExecutor field on NativeCompiledClassV1Inner with cairo-native's new ContractExecutor enum and adopts cairo-native's new libfunc-profiling APIs. The conversion glue between cairo-native and sierra-emu syscall traits, and the libfunc profiling instrumentation — both previously maintained in blockifier — now live in cairo-native.

Important

Depends on:

The workspace Cargo.toml currently uses a path dep on a local cairo_native checkout. Do not merge until those land and a cairo-native release is published, then swap the path dep back to the published version.

Commits

  1. blockifier: adopt cairo_native::ContractExecutor for AOT + sierra-emu dispatch — switches executor: AotContractExecutorexecutor: ContractExecutor, adds sierra-emu feature + new_from_emu(EmuContractInfo, _) constructor.
  2. blockifier: wire libfunc profiling through cairo_native::run_with_profile — adds with-libfunc-profiling feature, profiling.rs storage module, new_with_program(_, _, Arc<Program>) constructor, and routes entry_point_execution through run_with_profile for the AotWithProgram variant.

Replaces

The (still-open) #13542 / #13543 / #13755 stack. The ContractExecutor enum, the ~340 lines of sierra-emu syscall conversions, and the libfunc profiling primitive (ProfilerGuard, Arc<Program> plumbing, trace_id mutation) all move out of blockifier and into cairo-native, where they belong (per @Yoni-Starkware's review on #13543).

Test plan

  • CI passes with --features cairo_native
  • CI passes with --features cairo_native,sierra-emu
  • CI passes with --features cairo_native,with-libfunc-profiling
  • CI passes with --features cairo_native,sierra-emu,with-libfunc-profiling
  • Once cairo-native is released, swap the path dep back to a crates.io version and re-run CI

🤖 Generated with Claude Code

… dispatch

Replaces the local AotContractExecutor field on NativeCompiledClassV1Inner with
cairo-native's new ContractExecutor enum, which dispatches between AOT execution
and the sierra-emu interpreter. The conversion glue between cairo-native and
sierra-emu syscall traits — previously maintained in blockifier — now lives in
cairo-native's SierraEmuSyscallBridge.

- crates/blockifier/src/execution/native/contract_class.rs:
    - executor: AotContractExecutor → executor: ContractExecutor.
    - Public new(AotContractExecutor, _) goes through `.into()` so all current
      callers (native_class_manager.rs, tests) keep working unchanged.
    - Adds new_from_emu(EmuContractInfo, _) under the new `sierra-emu` feature
      for callers that want to drive the sierra-emu interpreter through the
      same NativeCompiledClassV1 wrapper.

- crates/blockifier/Cargo.toml: adds the `sierra-emu` feature, which forwards
  to cairo-native/sierra-emu.

- workspace Cargo.toml: switches `cairo-native` to a path dep on a local
  checkout of cairo_native so the unreleased ContractExecutor + bridge APIs
  are visible. Switch back to a published version once cairo-native ships them.

Replaces the (still-open) #13542 + #13543 stack: the ContractExecutor enum
and the ~340 lines of sierra-emu syscall conversions move out of blockifier
and into cairo-native, where they belong.
@reviewable-StarkWare
Copy link
Copy Markdown

This change is Reviewable

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 26, 2026

@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 26, 2026

PR Summary

Medium Risk
Touches the native contract execution path and introduces new feature-gated dispatch/profiling logic, so misconfiguration or upstream cairo-native API changes could affect correctness/perf. Additional risk comes from the temporary local path dependency on cairo-native, which can break reproducible builds until a published release is used.

Overview
Switches blockifier’s native compiled class to store cairo_native::executor::ContractExecutor (instead of a single AOT executor), enabling both AOT and feature-gated sierra-emu-backed execution via a new new_from_emu constructor.

Adds a new run_dispatch layer so entry-point execution routes through ContractExecutor::run_with_profile when with-libfunc-profiling is enabled, and introduces profiling.rs to collect per-transaction libfunc profiles keyed by tx hash/block/selector.

Updates the native class compilation flow to optionally extract and cache the Sierra Program for profiling, adds sierra-emu and with-libfunc-profiling crate features, and temporarily pins cairo-native to a local path dependency; lockfile updates pull in new transitive crates (e.g., sierra-emu, p256).

Reviewed by Cursor Bugbot for commit 88f60d0. Bugbot is set up for automated code reviews on this repo. Configure here.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 781301f. Configure here.

Comment thread Cargo.toml
# TEMP: path dep on a local cairo_native checkout that contains the unreleased
# `ContractExecutor` enum and `SierraEmuSyscallBridge`. Switch back to a crates.io version
# once those land in a published cairo-native release.
cairo-native = { path = "/home/avi/workspace/cairo_native", version = "0.9.0-rc.6" }
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Local filesystem path dependency will break all builds

High Severity

The cairo-native dependency uses a hardcoded local filesystem path (/home/avi/workspace/cairo_native). This will cause a build failure for every other developer and CI runner that doesn't have this exact directory. While the PR description acknowledges this and says "Do not merge until those land," the path dep is committed and could accidentally be merged, breaking the entire workspace.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 781301f. Configure here.

Copy link
Copy Markdown
Collaborator

@Yoni-Starkware Yoni-Starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Yoni-Starkware made 1 comment.
Reviewable status: 0 of 8 files reviewed, 2 unresolved discussions (waiting on avi-starkware and TomerStarkware).


crates/blockifier/src/execution/native/entry_point_execution.rs line 104 at r2 (raw file):

    #[cfg(not(feature = "with-libfunc-profiling"))]
    let execution_result = compiled_class.executor.run(
        selector,

Suggestion:

    let selector = entry_point.selector.0;
    let calldata = syscall_handler.base.call.calldata.0.clone();

    #[cfg(feature = "with-libfunc-profiling")]
    let execution_result = run_with_profile(
                    selector,
                    &calldata,
                    call_initial_gas,
                    Some(builtin_costs),
                    &mut syscall_handler,
                    on_profile
                )
            }
    #[cfg(not(feature = "with-libfunc-profiling"))]
    let execution_result = compiled_class.executor.run(
        selector,

…file

Adds the blockifier-side glue that consumes the AotWithProgram variant /
run_with_profile API introduced in cairo-native. Profile collection
orchestration now lives in cairo-native; this commit only provides the
blockifier-domain key (transaction hash + block number + class hash + selector)
via a callback.

- crates/blockifier/Cargo.toml: new `with-libfunc-profiling` feature
  forwarding to cairo-native's matching feature, plus an optional
  `cairo-lang-sierra` dep (needed to name `Arc<Program>` at the
  NativeCompiledClassV1 boundary).

- crates/blockifier/src/execution/native/profiling.rs (new): storage
  types (`EntrypointProfile`, `TransactionProfile`, `LIBFUNC_PROFILES_MAP`)
  and `record_profile_for(...)` which builds an
  `impl FnOnce(Profile) + 'static` that captures the keying data up
  front, so the closure doesn't re-borrow the syscall handler.

- contract_class.rs: adds `NativeCompiledClassV1::new_with_program(..)`
  under the new feature; constructs the `ContractExecutor::AotWithProgram`
  variant from cairo-native.

- native_class_manager.rs: extracts the Sierra program (Arc-wrapped) from
  the contract class before compile() consumes it, and routes through
  `new_with_program` when the feature is on.

- entry_point_execution.rs: when the executor is the AotWithProgram
  variant, invoke `run_with_profile` with the per-call recording closure;
  otherwise call `run` as before.
@avi-starkware avi-starkware force-pushed the avi/blockifier/use-cairo-native-executor branch from 9630be2 to 88f60d0 Compare April 27, 2026 13:41
@avi-starkware
Copy link
Copy Markdown
Collaborator Author

crates/blockifier/src/execution/native/entry_point_execution.rs line 104 at r2 (raw file):

    #[cfg(not(feature = "with-libfunc-profiling"))]
    let execution_result = compiled_class.executor.run(
        selector,

I extracted the entire logic (including the feature gate) into run_dispatch.rs

Copy link
Copy Markdown
Collaborator

@Yoni-Starkware Yoni-Starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@Yoni-Starkware partially reviewed 5 files, made 1 comment, and resolved 1 discussion.
Reviewable status: 2 of 9 files reviewed, 1 unresolved discussion (waiting on avi-starkware and TomerStarkware).

Copy link
Copy Markdown
Collaborator

@Yoni-Starkware Yoni-Starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@Yoni-Starkware partially reviewed 7 files and made 1 comment.
Reviewable status: 8 of 9 files reviewed, 1 unresolved discussion (waiting on avi-starkware and TomerStarkware).

Copy link
Copy Markdown
Collaborator

@Yoni-Starkware Yoni-Starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Yoni-Starkware reviewed 1 file and all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on avi-starkware and TomerStarkware).

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.

3 participants