1
- use core :: starknet :: {EthAddress , secp256_trait :: Signature };
1
+ use core :: starknet :: {EthAddress , secp256_trait :: Signature , ContractAddress };
2
2
3
3
#[starknet:: interface]
4
4
pub trait IPrecompiles <T > {
@@ -88,7 +88,7 @@ pub trait IHelpers<T> {
88
88
/// * The recovered Ethereum address.
89
89
fn recover_eth_address (self : @ T , msg_hash : u256 , signature : Signature ) -> (bool , EthAddress );
90
90
91
- /// Performs signature verification in the secp256r1 ellipitic curve.
91
+ /// Performs signature verification in the secp256r1 elliptic curve.
92
92
///
93
93
/// # Arguments
94
94
///
@@ -103,20 +103,41 @@ pub trait IHelpers<T> {
103
103
fn verify_signature_secp256r1 (
104
104
self : @ T , msg_hash : u256 , r : u256 , s : u256 , x : u256 , y : u256
105
105
) -> bool ;
106
+
107
+
108
+ /// Calls a contract using the new Cairo call_contract_syscall.
109
+ ///
110
+ /// Meant to be used from Cairo Zero classes that want to be able to manage the return value of
111
+ /// the call.
112
+ /// Only applicable from Starknet v0.13.4 and onwwards.
113
+ ///
114
+ /// # Arguments
115
+ ///
116
+ /// * `to` - The address of the contract to call.
117
+ /// * `selector` - The selector of the function to call.
118
+ /// * `calldata` - The calldata to pass to the function.
119
+ ///
120
+ /// # Returns
121
+ /// A tuple containing:
122
+ /// * A boolean indicating whether the call was successful.
123
+ /// * The output of the call.
124
+ fn new_call_contract_syscall (
125
+ ref self : T , to : ContractAddress , selector : felt252 , calldata : Span <felt252 >
126
+ ) -> (bool , Span <felt252 >);
106
127
}
107
128
108
129
109
130
pub mod embeddable_impls {
110
131
use core :: keccak :: {cairo_keccak, keccak_u256s_be_inputs};
111
132
use core :: num :: traits :: Zero ;
112
- use core :: starknet :: EthAddress ;
113
133
use core :: starknet :: eth_signature :: {verify_eth_signature};
114
134
use core :: starknet :: secp256_trait :: {
115
135
Signature , recover_public_key, Secp256PointTrait , is_valid_signature
116
136
};
117
137
use core :: starknet :: secp256_trait :: {Secp256Trait };
118
138
use core :: starknet :: secp256k1 :: Secp256k1Point ;
119
139
use core :: starknet :: secp256r1 :: {Secp256r1Point };
140
+ use core :: starknet :: {ContractAddress , EthAddress };
120
141
use core :: traits :: Into ;
121
142
use core :: {starknet, starknet :: SyscallResultTrait };
122
143
use evm :: errors :: EVMError ;
@@ -149,7 +170,7 @@ pub mod embeddable_impls {
149
170
}
150
171
151
172
#[starknet:: embeddable]
152
- pub impl Helpers <TContractState > of super :: IHelpers <TContractState > {
173
+ pub impl Helpers <TContractState , + Drop < TContractState > > of super :: IHelpers <TContractState > {
153
174
fn get_block_hash (self : @ TContractState , block_number : u64 ) -> felt252 {
154
175
starknet :: syscalls :: get_block_hash_syscall (block_number ). unwrap_syscall ()
155
176
}
@@ -217,6 +238,22 @@ pub mod embeddable_impls {
217
238
218
239
return is_valid_signature (msg_hash , r , s , public_key );
219
240
}
241
+
242
+ fn new_call_contract_syscall (
243
+ ref self : TContractState ,
244
+ to : ContractAddress ,
245
+ selector : felt252 ,
246
+ calldata : Span <felt252 >
247
+ ) -> (bool , Span <felt252 >) {
248
+ // Note: until Starknet v0.13.4, the transaction will fail if the call reverted.
249
+ let result = starknet :: syscalls :: call_contract_syscall (to , selector , calldata );
250
+ match result {
251
+ Result :: Ok (output ) => { return (true , output ); },
252
+ // This will need to be manually tested and enabled once contract calls can be
253
+ // handled.
254
+ Result :: Err (error ) => { return panic (error ); }
255
+ }
256
+ }
220
257
}
221
258
}
222
259
0 commit comments