align sierra-emu StarknetSyscallHandler trait/types with cairo-native#1610
Open
avi-starkware wants to merge 2 commits into
Open
align sierra-emu StarknetSyscallHandler trait/types with cairo-native#1610avi-starkware wants to merge 2 commits into
avi-starkware wants to merge 2 commits into
Conversation
|
✅ Code is now correctly formatted. |
Benchmarking resultsBenchmark for program
|
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
11.570 ± 0.020 | 11.539 | 11.611 | 6.22 ± 0.07 |
cairo-native (embedded AOT) |
1.859 ± 0.021 | 1.818 | 1.886 | 1.00 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
1.920 ± 0.018 | 1.896 | 1.950 | 1.03 ± 0.02 |
Benchmark for program dict_snapshot
Open benchmarks
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
547.4 ± 5.5 | 540.3 | 558.6 | 1.00 |
cairo-native (embedded AOT) |
1693.5 ± 23.2 | 1648.1 | 1730.6 | 3.09 ± 0.05 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
1804.8 ± 19.0 | 1769.8 | 1835.1 | 3.30 ± 0.05 |
Benchmark for program factorial_2M
Open benchmarks
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
4.970 ± 0.016 | 4.941 | 4.988 | 2.31 ± 0.02 |
cairo-native (embedded AOT) |
2.148 ± 0.020 | 2.124 | 2.181 | 1.00 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
2.198 ± 0.018 | 2.177 | 2.232 | 1.02 ± 0.01 |
Benchmark for program fib_2M
Open benchmarks
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
4.862 ± 0.022 | 4.832 | 4.901 | 2.88 ± 0.03 |
cairo-native (embedded AOT) |
1.689 ± 0.016 | 1.662 | 1.718 | 1.00 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
1.759 ± 0.017 | 1.734 | 1.782 | 1.04 ± 0.01 |
Benchmark for program linear_search
Open benchmarks
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
589.8 ± 8.6 | 581.6 | 604.5 | 1.00 |
cairo-native (embedded AOT) |
1733.7 ± 12.1 | 1709.4 | 1745.5 | 2.94 ± 0.05 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
1876.3 ± 15.1 | 1852.2 | 1897.6 | 3.18 ± 0.05 |
Benchmark for program logistic_map
Open benchmarks
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
500.2 ± 6.4 | 495.0 | 515.8 | 1.00 |
cairo-native (embedded AOT) |
1859.5 ± 11.0 | 1841.7 | 1876.2 | 3.72 ± 0.05 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
2039.4 ± 20.1 | 2002.4 | 2061.8 | 4.08 ± 0.07 |
Benchmark results Main vs HEAD.Base
Head
Base
Head
Base
Head
Base
Head
Base
Head
Base
Head
|
This was referenced May 14, 2026
Sierra-emu adopts cairo-native's syscall surface so the two traits/types
match name-for-name. This is a prerequisite for extracting them into a
shared crate.
- Slice signatures: deploy/library_call/call_contract/emit_event/
send_message_to_l1/keccak/meta_tx_v0/cheatcode now take &[Felt] / &[u64]
rather than owned Vec.
- Secp256{k1,r1}Point gain an explicit is_infinity flag. The Sierra
Value encoding canonicalizes (0, 0) for the identity element so the
round-trip via from_value/into_value is lossless: into_value forces
(x, y) = (0, 0) when is_infinity is set; from_value recovers the flag
from the sentinel. (0, 0) is not a real curve point, so this is
unambiguous.
- sha256_process_block matches cairo-native's mutating signature
(&mut [u32; 8], &[u32; 16]) -> SyscallResult<()>.
- Add ExecutionInfoV3 / TxV3Info types and a get_execution_info_v3 trait
method (no default impl). The Sierra-level Value lowering for v3 is
not yet wired in the VM — eval_get_execution_info_v3 currently soft-
fails with a descriptive felt rather than panicking with todo!(), so
any contract calling the v3 syscall sees a graceful syscall error.
Full v3 wiring is a separate effort.
- cairo-native: cheatcode trait method becomes unconditional (was gated
behind with-cheatcode). The default impl is unimplemented!(), so this
is backwards-compatible for existing impls; only the runtime/codegen
side stays feature-gated.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
40ef87d to
7698d47
Compare
The secp256k1_add / secp256k1_mul / secp256r1_add / secp256r1_mul stub implementations called `p.to_encoded_point(false)` and then assumed the result was Coordinates::Uncompressed. The identity element returns Coordinates::Identity instead, so P + (-P) and k * P (mod ord) panicked with unreachable!(). Pre-existing bug in sierra-emu, surfaced more visibly by the trait alignment in this PR (which added is_infinity to the surface). Add an explicit Coordinates::Identity arm to all four sites, returning the canonical (0, 0) + is_infinity: true point. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
7698d47 to
a37920a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Aligns
sierra-emu'sStarknetSyscallHandlertrait and supporting types withcairo-native's shape, so the two surfaces match name-for-name. This is a prerequisite for extracting them into a shared crate (next PR in the stack), which in turn lets us delete the bridge code that PR #1597 / #1607 introduced.Changes
sierra-emuadoptscairo-native's shapedeploy,library_call,call_contract,emit_event,send_message_to_l1,keccak,meta_tx_v0,cheatcodenow take&[Felt]/&[u64]rather than ownedVec. VM call sites invm/starknet.rsupdated to pass borrows.is_infinity: boolflag. The Sierra-level encoding insidesierra-emustill uses(0, 0)to represent the identity element —from_valuerecovers the flag from that sentinel;into_valuedrops it (callers that materialize the point at infinity already produce(0, 0), so round-tripping is preserved).sha256_process_blockmatches cairo-native:(&mut [u32; 8], &[u32; 16]) -> SyscallResult<()>(mutates in place, returns unit).ExecutionInfoV3/TxV3Infotypes + aget_execution_info_v3trait method (defaulted tounimplemented!()). The VM-level Sierra value lowering for v3 staystodo!()— wiring it is out of scope for this PR.cairo-nativecheatcodetrait method becomes unconditional. The runtime/codegen plumbing for cheatcode (vtable entry,wrap_cheatcode,cairo_native__vtable_cheatcode, thewith-cheatcodecargo feature) stays feature-gated as before — only the trait method comes out from behind thecfg. The default impl isunimplemented!().Trace dump
metadata::trace_dumppopulatesis_infinitywhen constructing the sierra-emu secp points (it was already reading the field from cairo-native'sSecp256Point).Backwards compatibility
cairo-native: backwards-compatible. The only public change is unconditionally exposingcheatcodeon the trait, with a defaultunimplemented!()impl — existing impls compile unchanged, callers compile unchanged, the trait stays object-safe. Cargo featurewith-cheatcodestill controls the runtime/codegen side.sierra-emu: breaking — slice-vs-Vec, the newis_infinityfield, sha256 sig change.sierra-emulives in this repo and isn't published as an external API surface, so the blast radius is contained.Stack
This is the first of three PRs replacing the bridge approach in #1597 / #1607:
cairo-native-syscallscrate; both crates re-export from it; the bridge (added in add SierraEmuSyscallBridge for cairo-native ↔ sierra-emu interop #1607) becomes unnecessary and is deleted.ContractExecutordispatch enum (replaces add ContractExecutor dispatch enum (Aot + Emu) #1598 / add ContractExecutor dispatch enum (Aot + Emu) #1608) — theEmuarm calls cairo-native's syscall handler directly, no bridge needed.Test plan
cargo checkclean forcairo-native(default features,with-cheatcode,with-trace-dump)cargo check -p sierra-emuclean (lib + bins + tests)cargo check --workspace --all-featuresclean