add EmuContractExecutor (sierra-emu backend, interchangeable with AotContractExecutor)#1612
add EmuContractExecutor (sierra-emu backend, interchangeable with AotContractExecutor)#1612avi-starkware wants to merge 3 commits into
Conversation
|
✅ Code is now correctly formatted. |
b3a574c to
319a6be
Compare
98ed085 to
64c12b3
Compare
319a6be to
92ecf03
Compare
64c12b3 to
7e5fcd7
Compare
92ecf03 to
3b3e5af
Compare
7e5fcd7 to
4176352
Compare
3b3e5af to
24f61ba
Compare
4176352 to
7af0508
Compare
24f61ba to
0ae0d06
Compare
7af0508 to
38c5f2f
Compare
0ae0d06 to
0791b36
Compare
38c5f2f to
81093b3
Compare
0791b36 to
4e80562
Compare
4f53f27 to
6f77130
Compare
4e80562 to
34f9e15
Compare
34f9e15 to
eec22ef
Compare
aa4bf47 to
e6a4ad9
Compare
eec22ef to
487deb9
Compare
538f655 to
c8ed1f7
Compare
701a87c to
61059c1
Compare
orizi
left a comment
There was a problem hiding this comment.
@orizi made 1 comment.
Reviewable status: 0 of 23 files reviewed, 1 unresolved discussion (waiting on avi-starkware, TomerStarkware, and Yoni-Starkware).
-- commits line 1 at r2:
is this missing a rebase?
c8ed1f7 to
90cd01f
Compare
Benchmarking resultsBenchmark for program
|
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
5.785 ± 0.055 | 5.727 | 5.875 | 5.57 ± 0.06 |
cairo-native (embedded AOT) |
1.039 ± 0.003 | 1.035 | 1.045 | 1.00 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
1.045 ± 0.005 | 1.037 | 1.055 | 1.01 ± 0.01 |
Benchmark for program dict_snapshot
Open benchmarks
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
306.6 ± 3.4 | 301.8 | 313.1 | 1.00 |
cairo-native (embedded AOT) |
928.7 ± 3.9 | 923.2 | 934.4 | 3.03 ± 0.04 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
945.4 ± 5.1 | 936.7 | 951.3 | 3.08 ± 0.04 |
Benchmark for program factorial_2M
Open benchmarks
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
2.501 ± 0.025 | 2.476 | 2.565 | 2.58 ± 0.03 |
cairo-native (embedded AOT) |
0.970 ± 0.003 | 0.966 | 0.974 | 1.00 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
0.977 ± 0.003 | 0.972 | 0.982 | 1.01 ± 0.00 |
Benchmark for program fib_2M
Open benchmarks
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
2.432 ± 0.018 | 2.404 | 2.457 | 2.59 ± 0.02 |
cairo-native (embedded AOT) |
0.937 ± 0.004 | 0.933 | 0.945 | 1.00 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
0.957 ± 0.017 | 0.945 | 1.003 | 1.02 ± 0.02 |
Benchmark for program linear_search
Open benchmarks
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
330.0 ± 3.9 | 325.4 | 336.2 | 1.00 |
cairo-native (embedded AOT) |
945.7 ± 3.2 | 939.0 | 951.5 | 2.87 ± 0.04 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
962.7 ± 3.5 | 955.7 | 967.6 | 2.92 ± 0.04 |
Benchmark for program logistic_map
Open benchmarks
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
282.6 ± 2.2 | 279.5 | 286.7 | 1.00 |
cairo-native (embedded AOT) |
940.8 ± 3.8 | 935.3 | 946.1 | 3.33 ± 0.03 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
965.9 ± 15.1 | 957.1 | 1007.1 | 3.42 ± 0.06 |
Benchmark results Main vs HEAD.Base
Head
Base
Head
Base
Head
Base
Head
Base
Head
Base
Head
|
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-starknet-syscalls crate.
VirtualMachine::run's `Option` return is propagated as
Error::UnexpectedValue rather than `.expect()`-aborted, matching the
Aot arm's error-handling style.
- 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>
90cd01f to
a1e3635
Compare
Previously, orizi wrote…
Done. |
orizi
left a comment
There was a problem hiding this comment.
@orizi reviewed 22 files and all commit messages, and made 1 comment.
Reviewable status: 22 of 23 files reviewed, 2 unresolved discussions (waiting on avi-starkware, TomerStarkware, and Yoni-Starkware).
src/executor/contract_executor.rs line 107 at r3 (raw file):
builtin_stats: Default::default(), }) }
any reason to not just add this into sierra-emu and not need this entire new execute file?
Code quote:
let mut virtual_machine = sierra_emu::VirtualMachine::new_starknet(
Arc::clone(program),
entry_points,
*sierra_version,
);
let emu_builtin_costs = builtin_costs.map(convert_builtin_costs);
virtual_machine.call_contract(selector, gas, args.to_vec(), emu_builtin_costs);
// `VirtualMachine::run` returns `None` when the VM never produced a
// final state -- propagate as an error rather than aborting the host.
let result = virtual_machine.run(&mut syscall_handler).ok_or_else(|| {
Error::UnexpectedValue("sierra-emu VM produced no final state".to_string())
})?;
Ok(ContractExecutionResult {
remaining_gas: result.remaining_gas,
failure_flag: result.failure_flag,
return_values: result.return_values,
error_msg: result.error_msg,
builtin_stats: Default::default(),
})
}Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The dispatch enum is gone: consumers pick an executor type per build (feature flags) rather than per value. EmuContractInfo becomes EmuContractExecutor with an inherent run() that mirrors AotContractExecutor::run, so the two are interchangeable at call sites. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Previously, orizi wrote…
I removed the ContractExecutor enum and replaced it with a type alias (also removed this file). I looked at the code and at how lambdaclass used it for replay, and there is no dynamic dispatch of Contract executor types. The type used is determined at compile time. So I think we can safely remove this. |
Summary
Makes the sierra-emu interpreter usable as a drop-in alternative to
AotContractExecutorat contract call sites — without a dispatch enum. No consumer selects a backend at runtime (the choice is always made per build by feature flags), so consumers pick an executor type per build instead of wrapping every executor in an enum on the production path.Earlier revisions of this PR introduced a
ContractExecutordispatch enum (Aot+Emu); per review it is gone. Each step is its own commit so it can be reverted independently.Changes
debug_utils/sierra-emu: newVirtualMachine::run_contract(...)— one-shot convenience overnew_starknet+call_contract+run. ReturnsNonewhen the VM never produced a final state.src/executor/emu_contract_executor.rs(new, gated on the newsierra-emucargo feature):EmuContractExecutor { program, entry_points, sierra_version }with an inherentrun()that mirrorsAotContractExecutor::run— same parameter shape, sameStarknetSyscallHandlertrait (shared viacairo-native-syscalls, so the handler flows through unchanged). ConvertsBuiltinCostsand the emu result into cairo-native'sContractExecutionResult(with defaultbuiltin_stats).Cargo.toml: newsierra-emu = ["dep:sierra-emu"]feature;with-trace-dumpnow depends on the feature rather than the optional dep directly.Commits (revert points)
add ContractExecutor dispatch enum (Aot + Emu)— original version.move Emu-arm VM setup into sierra_emu::VirtualMachine::run_contract— sierra-emu owns the VM lifecycle.replace ContractExecutor enum with standalone EmuContractExecutor— drops the enum; reverting this commit restores it.Stack
run_with_libfunc_profile+AotWithProgramTest plan
cargo check(default features) cleancargo check --features sierra-emucleancargo check --workspace --all-featuresclean (on stack tip)This change is