extract shared cairo-native-syscalls crate#1611
Open
avi-starkware wants to merge 2 commits into
Open
Conversation
|
✅ Code is now correctly formatted. |
This was referenced May 14, 2026
40ef87d to
7698d47
Compare
b3a574c to
319a6be
Compare
Both cairo-native and sierra-emu now re-export the StarknetSyscallHandler
trait and supporting types (U256, Block/Tx/Execution Info v{1,2,3},
ResourceBounds, Secp256{k1,r1}Point) from the new
`cairo-native-syscalls` crate. The crate is workspace-local at the top
level (sibling to `test_utils/`).
The two crates' types are now nominally identical, so a single handler
impl can drive both runtimes without an adapter / bridge.
sierra-emu's previous inherent into_value/from_value methods (which
depend on sierra-emu's `Value` enum and can't follow the moved types)
become free functions in the new sub-module
`sierra_emu::starknet::value_conv`. Callers updated.
The per-type files under debug_utils/sierra-emu/src/starknet/* are
deleted now that the struct definitions live in the shared crate.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Default impl previously panicked with unimplemented!(). On the sierra-emu path, a contract that invokes the `cheatcode` libfunc against a handler that didn't override the method would unwind through the VM and abort the host. Production handlers (e.g. the blockifier's NativeSyscallHandler) don't implement cheatcode at all, so the default impl is what runs. Soft-fail with a single error felt instead, so misuse manifests as a normal syscall error rather than an unhandled panic. Test handlers that implement cheatcode override the default and are unaffected. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
7698d47 to
a37920a
Compare
319a6be to
92ecf03
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
Extracts the
StarknetSyscallHandlertrait and its supporting types into a new workspace-local crate,cairo-native-syscalls. Bothcairo-nativeandsierra-emure-export from it, so the two crates' types are now nominally identical — a single handler impl can drive both runtimes without an adapter.Replaces the bridge approach from #1597 / #1607: with this PR landed, the bridge file isn't necessary, and #1608's
Emuarm can call the cairo-native handler directly. Those follow-ups land in subsequent PRs in this stack.Layout
Sibling to
test_utils/at workspace root — fits the repo's existing convention for shared, non-binary, non-debug-tool crates.What moved
From
cairo-native/src/starknet.rsandsierra-emu/src/starknet/*into the new crate:U256,BlockInfo,TxInfo,TxV2Info,TxV3Info,ResourceBounds,ExecutionInfo,ExecutionInfoV2,ExecutionInfoV3,Secp256k1Point,Secp256r1Point.StarknetSyscallHandler, including its existing defaultcheatcodeimpl.Secp256k1Point::new/Secp256r1Point::new(pure-data).SyscallResult<T>.Repr / serde / derive layouts preserved exactly (
#[repr(C, align(16))]onU256,Secp256{k1,r1}Point).What stayed put
ArrayAbi,Felt252Abi,DummySyscallHandler, the runtime/codegen vtables (handler::StarknetSyscallHandlerCallbacks,cairo_native__vtable_cheatcode, etc.) — all cairo-native-specific.StubSyscallHandler,StubEvent,ContractLogs, and the VM eval logic.Value-conversion methods
Sierra-emu previously had
impl <Type> { fn into_value(self) -> Value, fn from_value(v: Value) -> Self }on each type. Inherent impls can't follow the type into a foreign crate, so these become free functions in a newsierra_emu::starknet::value_convmodule:U256::from_value(v)u256_from_value(v)u.into_value()u256_into_value(u)Secp256k1Point::from_value(v)secp256k1_point_from_value(v)info.into_value(felt_ty)execution_info_into_value(info, felt_ty)Call sites in
sierra-emu/src/vm/starknet.rsandcairo-native/src/metadata/trace_dump.rsupdated.Backwards compatibility
cairo_native::starknet::U256,…::StarknetSyscallHandler, etc. still resolve viapub use. Existing impls and callers compile unchanged. No semver-breaking change.into_value/from_valuemethods are gone. Sierra-emu is debug-only and not an externally published API surface; callers in this repo are all updated.debug_utils/sierra-emu/src/starknet/*are deleted now that the struct defs live in the shared crate.Stack
ContractExecutordispatch enum without the bridge (replaces add ContractExecutor dispatch enum (Aot + Emu) #1598 / add ContractExecutor dispatch enum (Aot + Emu) #1608)run_with_libfunc_profile+AotWithProgram(rebase of add run_with_libfunc_profile + AotWithProgram variant for ContractExecutor #1599 / add run_with_libfunc_profile + AotWithProgram variant for ContractExecutor #1609)Test plan
cargo check --workspace --all-featurescleancargo check -p sierra-emu --all-targetsclean