blockifier: adopt cairo_native::ContractExecutor for AOT + sierra-emu dispatch#13880
blockifier: adopt cairo_native::ContractExecutor for AOT + sierra-emu dispatch#13880avi-starkware wants to merge 2 commits into
Conversation
… 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.
|
Artifacts upload workflows: |
PR SummaryMedium Risk Overview Adds a new Updates the native class compilation flow to optionally extract and cache the Sierra Reviewed by Cursor Bugbot for commit 88f60d0. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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.
| # 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" } |
There was a problem hiding this comment.
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.
Reviewed by Cursor Bugbot for commit 781301f. Configure here.
Yoni-Starkware
left a comment
There was a problem hiding this comment.
@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.
9630be2 to
88f60d0
Compare
|
I extracted the entire logic (including the feature gate) into |
Yoni-Starkware
left a comment
There was a problem hiding this comment.
@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
left a comment
There was a problem hiding this comment.
@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
left a comment
There was a problem hiding this comment.
@Yoni-Starkware reviewed 1 file and all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on avi-starkware and TomerStarkware).


Summary
Replaces the local
AotContractExecutorfield onNativeCompiledClassV1Innerwith cairo-native's newContractExecutorenum 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:
SierraEmuSyscallBridge)ContractExecutorenum)run_with_libfunc_profile+AotWithProgram)The workspace
Cargo.tomlcurrently 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
blockifier: adopt cairo_native::ContractExecutor for AOT + sierra-emu dispatch— switchesexecutor: AotContractExecutor→executor: ContractExecutor, addssierra-emufeature +new_from_emu(EmuContractInfo, _)constructor.blockifier: wire libfunc profiling through cairo_native::run_with_profile— addswith-libfunc-profilingfeature,profiling.rsstorage module,new_with_program(_, _, Arc<Program>)constructor, and routesentry_point_executionthroughrun_with_profilefor theAotWithProgramvariant.Replaces
The (still-open) #13542 / #13543 / #13755 stack. The
ContractExecutorenum, 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
--features cairo_native--features cairo_native,sierra-emu--features cairo_native,with-libfunc-profiling--features cairo_native,sierra-emu,with-libfunc-profiling🤖 Generated with Claude Code