cairo_lang_sierra/extensions/modules/starknet/
mod.rs1use crate::extensions::lib_func::SignatureSpecializationContext;
2use crate::extensions::{NamedType, SpecializationError};
3use crate::ids::{ConcreteTypeId, UserTypeId};
4use crate::program::GenericArg;
5use crate::{define_libfunc_hierarchy, define_type_hierarchy};
6
7pub mod storage;
8use storage::{
9 GetBlockHashLibfunc, StorageAddressToFelt252Libfunc, StorageBaseAddressConstLibfunc,
10 StorageBaseAddressType, StorageReadLibfunc, StorageWriteLibfunc,
11};
12
13pub mod syscalls;
14use syscalls::{GetClassHashAtLibfunc, ReplaceClassLibfunc, SystemType};
15
16pub mod emit_event;
17use emit_event::EmitEventLibfunc;
18
19pub mod getter;
20
21pub mod secp256;
22use secp256::{Secp256Libfunc, Secp256PointType};
23pub mod secp256k1;
24pub mod secp256r1;
25
26pub mod testing;
27
28pub mod interoperability;
29use interoperability::{CallContractLibfunc, ContractAddressConstLibfunc, ContractAddressType};
30
31use self::getter::{GetExecutionInfoTrait, GetExecutionInfoV2Trait, GetterLibfunc};
32use self::interoperability::{
33 ClassHashConstLibfunc, ClassHashToFelt252Libfunc, ClassHashTryFromFelt252Trait, ClassHashType,
34 ContractAddressToFelt252Libfunc, ContractAddressTryFromFelt252Libfunc, DeployLibfunc,
35 LibraryCallLibfunc, SendMessageToL1Libfunc,
36};
37use self::storage::{
38 StorageAddressFromBaseAndOffsetLibfunc, StorageAddressFromBaseLibfunc,
39 StorageAddressTryFromFelt252Trait, StorageAddressType, StorageBaseAddressFromFelt252Libfunc,
40};
41use self::syscalls::{
42 KeccakLibfunc, Sha256ProcessBlockLibfunc, Sha256StateHandleDigestLibfunc,
43 Sha256StateHandleInitLibfunc, Sha256StateHandleType,
44};
45use self::testing::TestingLibfunc;
46use super::array::ArrayType;
47use super::felt252::Felt252Type;
48use super::int::unsigned::Uint64Type;
49use super::snapshot::snapshot_ty;
50use super::structure::StructType;
51use super::try_from_felt252::TryFromFelt252Libfunc;
52
53define_type_hierarchy! {
54 pub enum StarkNetType {
55 ClassHash(ClassHashType),
56 ContractAddress(ContractAddressType),
57 StorageBaseAddress(StorageBaseAddressType),
58 StorageAddress(StorageAddressType),
59 System(SystemType),
60 Secp256Point(Secp256PointType),
61 Sha256StateHandle(Sha256StateHandleType),
62 }, StarkNetTypeConcrete
63}
64
65define_libfunc_hierarchy! {
66 pub enum StarkNetLibfunc {
67 CallContract(CallContractLibfunc),
68 ClassHashConst(ClassHashConstLibfunc),
69 ClassHashTryFromFelt252(TryFromFelt252Libfunc<ClassHashTryFromFelt252Trait>),
70 ClassHashToFelt252(ClassHashToFelt252Libfunc),
71 ContractAddressConst(ContractAddressConstLibfunc),
72 ContractAddressTryFromFelt252(TryFromFelt252Libfunc<ContractAddressTryFromFelt252Libfunc>),
73 ContractAddressToFelt252(ContractAddressToFelt252Libfunc),
74 StorageRead(StorageReadLibfunc),
75 StorageWrite(StorageWriteLibfunc),
76 StorageBaseAddressConst(StorageBaseAddressConstLibfunc),
77 StorageBaseAddressFromFelt252(StorageBaseAddressFromFelt252Libfunc),
78 StorageAddressFromBase(StorageAddressFromBaseLibfunc),
79 StorageAddressFromBaseAndOffset(StorageAddressFromBaseAndOffsetLibfunc),
80 StorageAddressToFelt252(StorageAddressToFelt252Libfunc),
81 StorageAddressTryFromFelt252(TryFromFelt252Libfunc<StorageAddressTryFromFelt252Trait>),
82 EmitEvent(EmitEventLibfunc),
83 GetBlockHash(GetBlockHashLibfunc),
84 GetExecutionInfo(GetterLibfunc<GetExecutionInfoTrait>),
85 GetExecutionInfoV2(GetterLibfunc<GetExecutionInfoV2Trait>),
86 Deploy(DeployLibfunc),
87 Keccak(KeccakLibfunc),
88 Sha256ProcessBlock(Sha256ProcessBlockLibfunc),
89 Sha256StateHandleInit(Sha256StateHandleInitLibfunc),
90 Sha256StateHandleDigest(Sha256StateHandleDigestLibfunc),
91 LibraryCall(LibraryCallLibfunc),
92 ReplaceClass(ReplaceClassLibfunc),
93 GetClassHashAt(GetClassHashAtLibfunc),
94 SendMessageToL1(SendMessageToL1Libfunc),
95 Testing(TestingLibfunc),
96 Secp256(Secp256Libfunc),
97 }, StarkNetConcreteLibfunc
98}
99
100fn span_ty(
102 context: &dyn SignatureSpecializationContext,
103 wrapped_ty: ConcreteTypeId,
104 wrapped_ty_name: &str,
105) -> Result<ConcreteTypeId, SpecializationError> {
106 context.get_concrete_type(StructType::id(), &[
107 GenericArg::UserType(UserTypeId::from_string(format!(
108 "core::array::Span::<{wrapped_ty_name}>"
109 ))),
110 GenericArg::Type(snapshot_ty(
111 context,
112 context.get_wrapped_concrete_type(ArrayType::id(), wrapped_ty)?,
113 )?),
114 ])
115}
116
117fn felt252_span_ty(
119 context: &dyn SignatureSpecializationContext,
120) -> Result<ConcreteTypeId, SpecializationError> {
121 span_ty(context, context.get_concrete_type(Felt252Type::id(), &[])?, "core::felt252")
122}
123
124fn u64_span_ty(
126 context: &dyn SignatureSpecializationContext,
127) -> Result<ConcreteTypeId, SpecializationError> {
128 span_ty(context, context.get_concrete_type(Uint64Type::id(), &[])?, "core::integer::u64")
129}