Skip to content

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

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

blockifier: adopt cairo_native::ContractExecutor for AOT + sierra-emu dispatch#13880
avi-starkware wants to merge 4 commits into
mainfrom
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. Sierra-program extraction for profiling moves into apollo_compile_to_native::SierraToNativeCompiler::compile_with_program, so the blockifier no longer touches cairo-lang-sierra at all.

Important

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

The workspace Cargo.toml currently uses a git/rev dep pinned to the tip of #1613 (rev a21f3f57, 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 — switches executor: AotContractExecutorexecutor: ContractExecutor; adds sierra-emu + with-libfunc-profiling features; adds NativeCompiledClassV1::new_with_program(AotWithProgram, _); adds SierraToNativeCompiler::compile_with_program so process_compilation_request does compile + Sierra-program extraction in one call; routes entry_point_execution through run_with_profile via run_dispatch::run_native_executor.
  2. workspace: declare cairo-native version on git dep for version sync test — required for required_cairo_native_version_test to parse the pinned dep.
  3. blockifier: address review feedback on native compilation path — reverts process_compilation_request to a direct match so casm moves into NativeCompiledClassV1::new(_with_program) at zero cost.
  4. blockifier: re-add new_from_emu for out-of-tree benchmarking branch — restores the NativeCompiledClassV1::new_from_emu(EmuContractInfo, _) constructor so the out-of-tree benchmarking / replay feature branch (which is not expected to merge here) can construct sierra-emu-backed compiled classes without patching this file.

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 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
Copy link
Copy Markdown

cursor Bot commented Apr 26, 2026

PR Summary

High Risk
Touches contract execution and native compilation paths and depends on an unreleased git-pinned cairo-native stack; profiling uses unbounded in-process storage intended only for benchmarking.

Overview
Native execution now stores cairo-native’s unified ContractExecutor (AOT or sierra-emu) instead of a bare AotContractExecutor, with optional new_from_emu and new_with_program constructors behind feature flags.

Workspace pins cairo-native to a git revision (unreleased stack with ContractExecutor, profiling, sierra-emu) until a crates.io release; lockfile picks up sierra-emu, cairo-starknet-syscalls, and related deps.

apollo_compile_to_native adds with-libfunc-profiling and compile_with_program, which pairs the AOT artifact with the extracted Sierra Program.

Blockifier wires optional sierra-emu and with-libfunc-profiling features: native class compilation uses compile_with_program / new_with_program when profiling is on; entry points run through run_dispatch::run_native_executor ( run_with_profile vs run ); profiles are keyed by tx/block in profiling::LIBFUNC_PROFILES_MAP.

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

Comment thread Cargo.toml Outdated
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,

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

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
@avi-starkware avi-starkware force-pushed the avi/blockifier/use-cairo-native-executor branch from 8d7bbc6 to bfe58c8 Compare May 17, 2026 12:58
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.

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

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 and others added 4 commits May 28, 2026 18:19
…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>
@avi-starkware avi-starkware force-pushed the avi/blockifier/use-cairo-native-executor branch from f72014c to baa8bad Compare May 28, 2026 15:33
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