Skip to content

blockifier: adopt cairo-native executors via cfg-resolved NativeContractExecutor#13880

Open
avi-starkware wants to merge 7 commits into
mainfrom
avi/blockifier/use-cairo-native-executor
Open

blockifier: adopt cairo-native executors via cfg-resolved NativeContractExecutor#13880
avi-starkware wants to merge 7 commits into
mainfrom
avi/blockifier/use-cairo-native-executor

Conversation

@avi-starkware

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

Copy link
Copy Markdown
Collaborator

Summary

Replaces the local AotContractExecutor field on NativeCompiledClassV1Inner with a cfg-resolved NativeContractExecutor type alias and adopts cairo-native's new libfunc-profiling APIs. There is no dispatch enum anywhere: the executor backend is always selected at compile time, so production builds store literally AotContractExecutor, and the special backends exist only inside their feature gates.

NativeContractExecutor resolution (all three types expose the same run shape, so call sites are identical across builds):

build executor type
production (cairo_native) AotContractExecutor
sierra-emu (testing / benchmarking; takes precedence) EmuContractExecutor — the class manager skips native compilation entirely and the sierra-emu interpreter consumes the Sierra program directly
with-libfunc-profiling AotWithProgram — AOT executor paired with its Sierra program so libfunc samples can be resolved

The conversion glue between cairo-native and sierra-emu syscall traits, and the libfunc profiling instrumentation — both previously maintained in blockifier — live in cairo-native.

Important

Depends on the unreleased cairo_native PR stack (in order):

The workspace Cargo.toml uses a git/rev dep pinned to the tip of #1613 (rev 6184f7a6, package version 0.9.0-rc.7). Do not merge until that stack lands and a cairo-native release is published, then swap the git/rev dep back to a published version = "...".

Commits

  1. blockifier,apollo_compile_to_native: adopt cairo_native::ContractExecutor + libfunc profiling — the original enum-based adoption; switches executor: AotContractExecutor → cairo-native's ContractExecutor; adds sierra-emu + with-libfunc-profiling features; adds SierraToNativeCompiler::compile_with_program; routes entry_point_execution through run_dispatch::run_native_executor.
  2. workspace: declare cairo-native version on git dep for version sync test.
  3. blockifier: address review feedback on native compilation pathcasm moves into the constructor at zero cost.
  4. blockifier: re-add new_from_emu for out-of-tree benchmarking branch.
  5. apollo_compile_to_native: document instrumented-binary requirement for libfunc profiling.
  6. blockifier: replace ContractExecutor enum with cfg-resolved NativeContractExecutor — removes the enum from production code (revert this commit to restore the enum-based design). Collapses new/new_from_emu/new_with_program into a single new(executor: NativeContractExecutor, _); the class manager and test utils construct the matching backend per build; sierra-emu now actually executes in-tree instead of gating a dead constructor.

Branch is rebased over main (cairo-lang 2.19.0-rc.3), per review.

Replaces

The (still-open) #13542 / #13543 / #13755 stack. The sierra-emu syscall conversions and the libfunc profiling primitive moved to cairo-native (per @Yoni-Starkware's review on #13543); the executor-backend selection is now a compile-time type resolution rather than an enum in production code (per @orizi's review on the cairo-native stack).

Test plan

  • cargo check -p blockifier --features cairo_native,testing
  • cargo check -p blockifier --features cairo_native,sierra-emu,testing
  • cargo check -p blockifier --features cairo_native,with-libfunc-profiling,testing
  • cargo check -p blockifier --features cairo_native,sierra-emu,with-libfunc-profiling,testing
  • CI green
  • Once cairo-native is released, swap the git/rev dep back to a crates.io version = "..." and re-run CI

🤖 Generated with Claude Code

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

@cursor

cursor Bot commented Apr 26, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches core native contract execution and compilation paths with feature-gated behavior; production default remains AOT-only, but the git-pinned cairo-native dependency must land on crates.io before merge.

Overview
Replaces the fixed AotContractExecutor on native compiled classes with a compile-time NativeContractExecutor alias (plain AOT in production, EmuContractExecutor when sierra-emu is on, AotWithProgram when with-libfunc-profiling is on). NativeCompiledClassV1::new takes that executor type directly instead of separate constructors per backend.

cairo-native is temporarily pinned to a git rev for unreleased EmuContractExecutor, AotWithProgram, and libfunc profiling APIs. apollo_compile_to_native adds compile_with_program behind with-libfunc-profiling.

Native entry points go through run_native_executor, which calls run_with_profile and records into LIBFUNC_PROFILES_MAP when profiling is enabled. The class manager skips AOT compilation under sierra-emu and builds an interpreter executor from Sierra; test helpers construct the matching executor per feature set.

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

Comment thread Cargo.toml Outdated

@Yoni-Starkware Yoni-Starkware left a comment

Copy link
Copy Markdown
Collaborator

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,

@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

@Yoni-Starkware Yoni-Starkware left a comment

Copy link
Copy Markdown
Collaborator

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).

@Yoni-Starkware Yoni-Starkware left a comment

Copy link
Copy Markdown
Collaborator

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).

@Yoni-Starkware Yoni-Starkware left a comment

Copy link
Copy Markdown
Collaborator

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).

Comment thread Cargo.toml Outdated
# (starkware-libs/cairo_native#1610 → #1611 → #1612 → #1613) containing
# `ContractExecutor`, `EmuContractInfo`, `AotWithProgram`, and `run_with_profile`.
# Switch back to a crates.io version once those land in a published cairo-native release.
cairo-native = { git = "https://github.com/starkware-libs/cairo_native.git", rev = "78bf3e4b01a085261f61367c29391e98deb98460" }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unpublished git dependency committed for production use

Medium Severity

The cairo-native dependency is pinned to a specific git revision from an unreleased PR stack instead of a published crates.io version. The comment says "TEMP" and the PR description warns not to merge until upstream lands, but this temporary git dep could easily be forgotten and shipped. A production dependency on an unpublished git rev risks reproducibility issues and blocks downstream consumers who can't resolve the git source.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 7f89015. Configure here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Acknowledged — this is the intended merge gate, not a forgotten TEMP. The git rev pins the tip of the cairo_native PR stack (#1610#1611#1607#1612#1613); merge of this PR is blocked on that stack landing in a published cairo-native release. The # TEMP: block above the dep line names the upstream PRs and the planned crates.io swap.

@avi-starkware avi-starkware force-pushed the avi/blockifier/use-cairo-native-executor branch from 7f89015 to 8d7bbc6 Compare May 17, 2026 12:48
Comment thread crates/blockifier/src/execution/native/contract_class.rs Outdated
@avi-starkware avi-starkware force-pushed the avi/blockifier/use-cairo-native-executor branch from 8d7bbc6 to bfe58c8 Compare May 17, 2026 12:58

@Yoni-Starkware Yoni-Starkware left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Rebase over main?

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

@avi-starkware avi-starkware changed the base branch from main-v0.14.2 to graphite-base/13880 May 17, 2026 14:17
@avi-starkware avi-starkware force-pushed the avi/blockifier/use-cairo-native-executor branch from bfe58c8 to c7a3fac Compare May 17, 2026 14:17
@avi-starkware avi-starkware force-pushed the graphite-base/13880 branch from a962748 to 441098f Compare May 17, 2026 14:17
@avi-starkware avi-starkware changed the base branch from graphite-base/13880 to main May 17, 2026 14:17

Copy link
Copy Markdown
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@avi-starkware

Copy link
Copy Markdown
Collaborator Author

Rebase over main?

@avi-starkware

Copy link
Copy Markdown
Collaborator Author

Done.

@avi-starkware avi-starkware force-pushed the avi/blockifier/use-cairo-native-executor branch from c7a3fac to 52cfdf6 Compare May 17, 2026 18:18

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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.

There are 3 total unresolved issues (including 2 from previous reviews).

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 c8cca67. Configure here.

Comment thread crates/blockifier/src/state/native_class_manager.rs Outdated
@avi-starkware avi-starkware force-pushed the avi/blockifier/use-cairo-native-executor branch 2 times, most recently from baa8bad to a184916 Compare June 1, 2026 14:17
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

There hasn't been any activity on this pull request recently, and in order to prioritize active work, it has been marked as stale.
This PR will be closed and locked in 7 days if no further activity occurs.
Thank you for your contributions!

@github-actions github-actions Bot added the stale label Jul 2, 2026
avi-starkware and others added 6 commits July 6, 2026 15:17
…utor + libfunc profiling

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Cargo accepts both git+rev and a version field together; the field is a
SemVer constraint on the package at the git rev. The rev's Cargo.toml
already pins 0.9.0-rc.6, matching native_compiler_version.txt, so the
constants test required_cairo_native_version_test parses the version and
succeeds.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Drop unused `NativeCompiledClassV1::new_from_emu`; it had no in-tree
  callers, and the sierra-emu construction path will be re-added when
  the benchmarking/replay tool that needs it lands.
- Revert `process_compilation_request`'s `.map(...)` shape to a direct
  `match`, moving `casm` into `NativeCompiledClassV1::new(_with_program)`
  in the `Ok` arm at zero cost instead of cloning it.
- Bump pinned cairo-native rev to pick up `cargo fmt` fix on
  starkware-libs/cairo_native#1613.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
`new_from_emu` was deleted in 88b68af after Cursor flagged it as
unused. Restore it (with a doc comment naming the planned consumer)
so the benchmarking / replay tooling — which will live as a feature
branch and is not expected to merge here — can reach it without
patching this file. No `#[expect(dead_code)]` needed: `dead_code`
doesn't fire on `pub fn` in a library crate.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…r libfunc profiling

The with-libfunc-profiling feature only enables profiling in the linked cairo-native
library; the profiler symbol that run_with_libfunc_profile resolves is emitted by the
compiler binary. Document that starknet-native-compile must itself be built with
with-libfunc-profiling (and that compiler_binary_path can point at such a binary),
otherwise every profiled native call fails on a missing symbol.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…tractExecutor

The enum dispatched between executor backends that are always selected
at compile time, never at runtime. NativeCompiledClassV1 now stores a
NativeContractExecutor type alias resolved per build: AotContractExecutor
in production, EmuContractExecutor under sierra-emu (which now skips
native compilation in the class manager and runs the interpreter),
AotWithProgram under with-libfunc-profiling. All three expose the same
run() shape, so call sites are unchanged across builds; sierra-emu takes
precedence over profiling in the resolution.

Pulls the reworked cairo-native stack (no ContractExecutor enum;
EmuContractExecutor + AotWithProgram with inherent run methods).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@avi-starkware avi-starkware force-pushed the avi/blockifier/use-cairo-native-executor branch from a184916 to 536db23 Compare July 6, 2026 12:26
@avi-starkware avi-starkware changed the title blockifier: adopt cairo_native::ContractExecutor for AOT + sierra-emu dispatch blockifier: adopt cairo-native executors via cfg-resolved NativeContractExecutor (AOT / sierra-emu / libfunc-profiling) Jul 6, 2026
@avi-starkware avi-starkware changed the title blockifier: adopt cairo-native executors via cfg-resolved NativeContractExecutor (AOT / sierra-emu / libfunc-profiling) blockifier: adopt cairo-native executors via cfg-resolved NativeContractExecutor Jul 8, 2026
The previous head SHA carried a permanently-completed
check-run (failure) from before that job was removed from main's
workflow. merge-gatekeeper-new no longer ignores that context, so it
polls forever waiting on a check that will never update, until it
times out. A new SHA has no such stale check-run.

Co-Authored-By: Claude Fable 5 <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.

3 participants