Skip to content

Commit cdffde4

Browse files
committed
Added basic sierra-support for get_execution_info_v3_syscall.
1 parent 7451cdc commit cdffde4

File tree

8 files changed

+200
-2
lines changed

8 files changed

+200
-2
lines changed

corelib/src/starknet/syscalls.cairo

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,17 @@ pub extern fn get_execution_info_v2_syscall() -> SyscallResult<
100100
Box<starknet::info::v2::ExecutionInfo>,
101101
> implicits(GasBuiltin, System) nopanic;
102102

103+
/// Gets information about the current execution, version 3.
104+
/// This syscall should not be called directly. Instead, use
105+
/// `starknet::info::get_execution_info`.
106+
///
107+
/// # Returns
108+
///
109+
/// * A box containing the current V3 execution information.
110+
pub extern fn get_execution_info_v3_syscall() -> SyscallResult<
111+
Box<starknet::info::v3::ExecutionInfo>,
112+
> implicits(GasBuiltin, System) nopanic;
113+
103114
/// Calls the requested function in any previously declared class.
104115
///
105116
/// # Arguments

crates/cairo-lang-runner/src/casm_run/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ struct TxInfo {
212212
nonce_data_availability_mode: Felt252,
213213
fee_data_availability_mode: Felt252,
214214
account_deployment_data: Vec<Felt252>,
215+
proof_facts: Vec<Felt252>,
215216
}
216217

217218
/// Copy of the Cairo `ResourceBounds` struct.
@@ -935,6 +936,9 @@ impl CairoHintProcessor<'_> {
935936
let account_deployment_data_start = res_segment.ptr;
936937
res_segment.write_data(tx_info.account_deployment_data.iter().cloned())?;
937938
let account_deployment_data_end = res_segment.ptr;
939+
let proof_facts_start = res_segment.ptr;
940+
res_segment.write_data(tx_info.proof_facts.iter().cloned())?;
941+
let proof_facts_end = res_segment.ptr;
938942
let tx_info_ptr = res_segment.ptr;
939943
res_segment.write(tx_info.version)?;
940944
res_segment.write(tx_info.account_contract_address)?;
@@ -953,6 +957,8 @@ impl CairoHintProcessor<'_> {
953957
res_segment.write(tx_info.fee_data_availability_mode)?;
954958
res_segment.write(account_deployment_data_start)?;
955959
res_segment.write(account_deployment_data_end)?;
960+
res_segment.write(proof_facts_start)?;
961+
res_segment.write(proof_facts_end)?;
956962
let block_info_ptr = res_segment.ptr;
957963
res_segment.write(block_info.block_number)?;
958964
res_segment.write(block_info.block_timestamp)?;

crates/cairo-lang-sierra-ap-change/src/core_libfunc_ap_change.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ pub fn core_libfunc_ap_change<InfoProvider: InvocationApChangeInfoProvider>(
340340
| StarknetConcreteLibfunc::GetBlockHash(_)
341341
| StarknetConcreteLibfunc::GetExecutionInfo(_)
342342
| StarknetConcreteLibfunc::GetExecutionInfoV2(_)
343+
| StarknetConcreteLibfunc::GetExecutionInfoV3(_)
343344
| StarknetConcreteLibfunc::Deploy(_)
344345
| StarknetConcreteLibfunc::Keccak(_)
345346
| StarknetConcreteLibfunc::Sha256ProcessBlock(_)

crates/cairo-lang-sierra-gas/src/starknet_libfunc_cost_base.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ pub fn starknet_libfunc_cost_base(libfunc: &StarknetConcreteLibfunc) -> Vec<Cons
4242
StarknetConcreteLibfunc::EmitEvent(_) => syscall_cost(4),
4343
StarknetConcreteLibfunc::GetBlockHash(_) => syscall_cost(1),
4444
StarknetConcreteLibfunc::GetExecutionInfo(_)
45-
| StarknetConcreteLibfunc::GetExecutionInfoV2(_) => syscall_cost(0),
45+
| StarknetConcreteLibfunc::GetExecutionInfoV2(_)
46+
| StarknetConcreteLibfunc::GetExecutionInfoV3(_) => syscall_cost(0),
4647
StarknetConcreteLibfunc::Deploy(_) => syscall_cost(5),
4748
StarknetConcreteLibfunc::Keccak(_) => syscall_cost(2),
4849
StarknetConcreteLibfunc::Sha256ProcessBlock(_) => syscall_cost(2),

crates/cairo-lang-sierra-to-casm/src/invocations/starknet/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ pub fn build(
6060
build_syscalls(builder, "GetBlockHash", [1], [1])
6161
}
6262
StarknetConcreteLibfunc::GetExecutionInfo(_)
63-
| StarknetConcreteLibfunc::GetExecutionInfoV2(_) => {
63+
| StarknetConcreteLibfunc::GetExecutionInfoV2(_)
64+
| StarknetConcreteLibfunc::GetExecutionInfoV3(_) => {
6465
build_syscalls(builder, "GetExecutionInfo", [], [1])
6566
}
6667
StarknetConcreteLibfunc::Deploy(_) => {

crates/cairo-lang-sierra/src/extensions/modules/starknet/getter.rs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,32 @@ fn get_execution_info_v2_type(
111111
)
112112
}
113113

114+
/// Helper for v3::ExecutionInfo type.
115+
fn get_execution_info_v3_type(
116+
context: &dyn SignatureSpecializationContext,
117+
) -> Result<ConcreteTypeId, SpecializationError> {
118+
let felt252_ty = context.get_concrete_type(Felt252Type::id(), &[])?;
119+
let contract_address_ty = context.get_concrete_type(ContractAddressType::id(), &[])?;
120+
context.get_concrete_type(
121+
StructType::id(),
122+
&[
123+
GenericArg::UserType(UserTypeId::from_string(
124+
"core::starknet::info::v3::ExecutionInfo",
125+
)),
126+
// block_info
127+
GenericArg::Type(box_ty(context, get_block_info_type(context)?)?),
128+
// tx_info
129+
GenericArg::Type(box_ty(context, get_tx_info_v3_type(context)?)?),
130+
// caller_address
131+
GenericArg::Type(contract_address_ty.clone()),
132+
// contract_address
133+
GenericArg::Type(contract_address_ty),
134+
// entry_point_selector
135+
GenericArg::Type(felt252_ty),
136+
],
137+
)
138+
}
139+
114140
/// Helper for BlockInfo type.
115141
fn get_block_info_type(
116142
context: &dyn SignatureSpecializationContext,
@@ -234,6 +260,51 @@ fn get_tx_info_v2_type(
234260
)
235261
}
236262

263+
/// Helper for v3::TxInfo type.
264+
fn get_tx_info_v3_type(
265+
context: &dyn SignatureSpecializationContext,
266+
) -> Result<ConcreteTypeId, SpecializationError> {
267+
let felt252_ty = context.get_concrete_type(Felt252Type::id(), &[])?;
268+
let felt252_span_ty = felt252_span_ty(context)?;
269+
let contract_address_ty = context.get_concrete_type(ContractAddressType::id(), &[])?;
270+
let u32_ty = context.get_concrete_type(Uint32Type::id(), &[])?;
271+
let u128_ty = context.get_concrete_type(Uint128Type::id(), &[])?;
272+
context.get_concrete_type(
273+
StructType::id(),
274+
&[
275+
GenericArg::UserType(UserTypeId::from_string("core::starknet::info::v3::TxInfo")),
276+
// version
277+
GenericArg::Type(felt252_ty.clone()),
278+
// account_contract_address
279+
GenericArg::Type(contract_address_ty),
280+
// max_fee
281+
GenericArg::Type(u128_ty.clone()),
282+
// signature
283+
GenericArg::Type(felt252_span_ty.clone()),
284+
// transaction_hash
285+
GenericArg::Type(felt252_ty.clone()),
286+
// chain_id
287+
GenericArg::Type(felt252_ty.clone()),
288+
// nonce
289+
GenericArg::Type(felt252_ty),
290+
// resource_bounds
291+
GenericArg::Type(resource_bounds_span_ty(context)?),
292+
// tip
293+
GenericArg::Type(u128_ty),
294+
// paymaster_data
295+
GenericArg::Type(felt252_span_ty.clone()),
296+
// nonce_data_availability_mode
297+
GenericArg::Type(u32_ty.clone()),
298+
// fee_data_availability_mode
299+
GenericArg::Type(u32_ty),
300+
// account_deployment_data
301+
GenericArg::Type(felt252_span_ty.clone()),
302+
// proof_facts
303+
GenericArg::Type(felt252_span_ty),
304+
],
305+
)
306+
}
307+
237308
#[derive(Default)]
238309
pub struct GetExecutionInfoTrait {}
239310
impl GetterTraitsEx for GetExecutionInfoTrait {
@@ -257,3 +328,15 @@ impl GetterTraitsEx for GetExecutionInfoV2Trait {
257328
box_ty(context, get_execution_info_v2_type(context)?)
258329
}
259330
}
331+
332+
#[derive(Default)]
333+
pub struct GetExecutionInfoV3Trait {}
334+
impl GetterTraitsEx for GetExecutionInfoV3Trait {
335+
const STR_ID: &'static str = "get_execution_info_v3_syscall";
336+
337+
fn info_type_id(
338+
context: &dyn SignatureSpecializationContext,
339+
) -> Result<ConcreteTypeId, SpecializationError> {
340+
box_ty(context, get_execution_info_v3_type(context)?)
341+
}
342+
}

crates/cairo-lang-sierra/src/extensions/modules/starknet/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::extensions::lib_func::SignatureSpecializationContext;
2+
use crate::extensions::starknet::getter::GetExecutionInfoV3Trait;
23
use crate::extensions::{NamedType, SpecializationError};
34
use crate::ids::{ConcreteTypeId, UserTypeId};
45
use crate::program::GenericArg;
@@ -85,6 +86,7 @@ define_libfunc_hierarchy! {
8586
GetBlockHash(GetBlockHashLibfunc),
8687
GetExecutionInfo(GetterLibfunc<GetExecutionInfoTrait>),
8788
GetExecutionInfoV2(GetterLibfunc<GetExecutionInfoV2Trait>),
89+
GetExecutionInfoV3(GetterLibfunc<GetExecutionInfoV3Trait>),
8890
Deploy(DeployLibfunc),
8991
Keccak(KeccakLibfunc),
9092
Sha256ProcessBlock(Sha256ProcessBlockLibfunc),

tests/e2e_test_data/libfuncs/starknet/syscalls

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,99 @@ test::foo@F0([0]: GasBuiltin, [1]: System) -> (GasBuiltin, System, core::result:
344344

345345
//! > ==========================================================================
346346

347+
//! > get_execution_info_v3_syscall libfunc
348+
349+
//! > test_comments
350+
351+
//! > test_runner_name
352+
SmallE2ETestRunner
353+
354+
//! > cairo_code
355+
fn foo() -> starknet::SyscallResult<Box<starknet::info::v3::ExecutionInfo>> {
356+
starknet::syscalls::get_execution_info_v3_syscall()
357+
}
358+
359+
//! > casm
360+
[ap + 0] = 94901967946959054011942058057773508207, ap++;
361+
[ap + -1] = [[fp + -3] + 0];
362+
[fp + -4] = [[fp + -3] + 1];
363+
%{ syscall_handler.syscall(syscall_ptr=memory[fp + -3]) %}
364+
[ap + 0] = [[fp + -3] + 3], ap++;
365+
jmp rel 12 if [ap + -1] != 0;
366+
[ap + 0] = [[fp + -3] + 2], ap++;
367+
[ap + 0] = [ap + -1], ap++;
368+
[ap + 0] = [fp + -3] + 5, ap++;
369+
[ap + 0] = 0, ap++;
370+
[ap + 0] = 0, ap++;
371+
[ap + 0] = [[fp + -3] + 4], ap++;
372+
ret;
373+
[ap + 0] = [[fp + -3] + 2], ap++;
374+
[ap + 0] = [ap + -1], ap++;
375+
[ap + 0] = [fp + -3] + 6, ap++;
376+
[ap + 0] = 1, ap++;
377+
[ap + 0] = [[fp + -3] + 4], ap++;
378+
[ap + 0] = [[fp + -3] + 5], ap++;
379+
ret;
380+
381+
//! > function_costs
382+
test::foo: SmallOrderedMap({Const: 11100})
383+
384+
//! > sierra_code
385+
type GasBuiltin = GasBuiltin [storable: true, drop: false, dup: false, zero_sized: false];
386+
type Box<core::starknet::info::v3::ExecutionInfo> = Box<core::starknet::info::v3::ExecutionInfo> [storable: true, drop: true, dup: true, zero_sized: false];
387+
type Array<felt252> = Array<felt252> [storable: true, drop: true, dup: false, zero_sized: false];
388+
type core::result::Result::<core::box::Box::<core::starknet::info::v3::ExecutionInfo>, core::array::Array::<core::felt252>> = Enum<ut@core::result::Result::<core::box::Box::<core::starknet::info::v3::ExecutionInfo>, core::array::Array::<core::felt252>>, Box<core::starknet::info::v3::ExecutionInfo>, Array<felt252>> [storable: true, drop: true, dup: false, zero_sized: false];
389+
type felt252 = felt252 [storable: true, drop: true, dup: true, zero_sized: false];
390+
type Box<core::starknet::info::BlockInfo> = Box<core::starknet::info::BlockInfo> [storable: true, drop: true, dup: true, zero_sized: false];
391+
type Box<core::starknet::info::v3::TxInfo> = Box<core::starknet::info::v3::TxInfo> [storable: true, drop: true, dup: true, zero_sized: false];
392+
type ContractAddress = ContractAddress [storable: true, drop: true, dup: true, zero_sized: false];
393+
type core::starknet::info::v3::ExecutionInfo = Struct<ut@core::starknet::info::v3::ExecutionInfo, Box<core::starknet::info::BlockInfo>, Box<core::starknet::info::v3::TxInfo>, ContractAddress, ContractAddress, felt252> [storable: true, drop: true, dup: true, zero_sized: false];
394+
type u128 = u128 [storable: true, drop: true, dup: true, zero_sized: false];
395+
type Snapshot<Array<felt252>> = Snapshot<Array<felt252>> [storable: true, drop: true, dup: true, zero_sized: false];
396+
type core::array::Span::<core::felt252> = Struct<ut@core::array::Span::<core::felt252>, Snapshot<Array<felt252>>> [storable: true, drop: true, dup: true, zero_sized: false];
397+
type Array<core::starknet::info::v2::ResourceBounds> = Array<core::starknet::info::v2::ResourceBounds> [storable: true, drop: true, dup: false, zero_sized: false];
398+
type Snapshot<Array<core::starknet::info::v2::ResourceBounds>> = Snapshot<Array<core::starknet::info::v2::ResourceBounds>> [storable: true, drop: true, dup: true, zero_sized: false];
399+
type core::array::Span::<core::starknet::info::v2::ResourceBounds> = Struct<ut@core::array::Span::<core::starknet::info::v2::ResourceBounds>, Snapshot<Array<core::starknet::info::v2::ResourceBounds>>> [storable: true, drop: true, dup: true, zero_sized: false];
400+
type u32 = u32 [storable: true, drop: true, dup: true, zero_sized: false];
401+
type core::starknet::info::v3::TxInfo = Struct<ut@core::starknet::info::v3::TxInfo, felt252, ContractAddress, u128, core::array::Span::<core::felt252>, felt252, felt252, felt252, core::array::Span::<core::starknet::info::v2::ResourceBounds>, u128, core::array::Span::<core::felt252>, u32, u32, core::array::Span::<core::felt252>, core::array::Span::<core::felt252>> [storable: true, drop: true, dup: true, zero_sized: false];
402+
type u64 = u64 [storable: true, drop: true, dup: true, zero_sized: false];
403+
type core::starknet::info::BlockInfo = Struct<ut@core::starknet::info::BlockInfo, u64, u64, ContractAddress> [storable: true, drop: true, dup: true, zero_sized: false];
404+
type core::starknet::info::v2::ResourceBounds = Struct<ut@core::starknet::info::v2::ResourceBounds, felt252, u64, u128> [storable: true, drop: true, dup: true, zero_sized: false];
405+
type System = System [storable: true, drop: false, dup: false, zero_sized: false];
406+
407+
libfunc get_execution_info_v3_syscall = get_execution_info_v3_syscall;
408+
libfunc branch_align = branch_align;
409+
libfunc store_temp<GasBuiltin> = store_temp<GasBuiltin>;
410+
libfunc redeposit_gas = redeposit_gas;
411+
libfunc enum_init<core::result::Result::<core::box::Box::<core::starknet::info::v3::ExecutionInfo>, core::array::Array::<core::felt252>>, 0> = enum_init<core::result::Result::<core::box::Box::<core::starknet::info::v3::ExecutionInfo>, core::array::Array::<core::felt252>>, 0>;
412+
libfunc store_temp<System> = store_temp<System>;
413+
libfunc store_temp<core::result::Result::<core::box::Box::<core::starknet::info::v3::ExecutionInfo>, core::array::Array::<core::felt252>>> = store_temp<core::result::Result::<core::box::Box::<core::starknet::info::v3::ExecutionInfo>, core::array::Array::<core::felt252>>>;
414+
libfunc enum_init<core::result::Result::<core::box::Box::<core::starknet::info::v3::ExecutionInfo>, core::array::Array::<core::felt252>>, 1> = enum_init<core::result::Result::<core::box::Box::<core::starknet::info::v3::ExecutionInfo>, core::array::Array::<core::felt252>>, 1>;
415+
416+
F0:
417+
get_execution_info_v3_syscall([0], [1]) { fallthrough([2], [3], [4]) F0_B0([5], [6], [7]) };
418+
branch_align() -> ();
419+
store_temp<GasBuiltin>([2]) -> ([2]);
420+
redeposit_gas([2]) -> ([8]);
421+
enum_init<core::result::Result::<core::box::Box::<core::starknet::info::v3::ExecutionInfo>, core::array::Array::<core::felt252>>, 0>([4]) -> ([9]);
422+
store_temp<GasBuiltin>([8]) -> ([8]);
423+
store_temp<System>([3]) -> ([3]);
424+
store_temp<core::result::Result::<core::box::Box::<core::starknet::info::v3::ExecutionInfo>, core::array::Array::<core::felt252>>>([9]) -> ([9]);
425+
return([8], [3], [9]);
426+
F0_B0:
427+
branch_align() -> ();
428+
store_temp<GasBuiltin>([5]) -> ([5]);
429+
redeposit_gas([5]) -> ([10]);
430+
enum_init<core::result::Result::<core::box::Box::<core::starknet::info::v3::ExecutionInfo>, core::array::Array::<core::felt252>>, 1>([7]) -> ([11]);
431+
store_temp<GasBuiltin>([10]) -> ([10]);
432+
store_temp<System>([6]) -> ([6]);
433+
store_temp<core::result::Result::<core::box::Box::<core::starknet::info::v3::ExecutionInfo>, core::array::Array::<core::felt252>>>([11]) -> ([11]);
434+
return([10], [6], [11]);
435+
436+
test::foo@F0([0]: GasBuiltin, [1]: System) -> (GasBuiltin, System, core::result::Result::<core::box::Box::<core::starknet::info::v3::ExecutionInfo>, core::array::Array::<core::felt252>>);
437+
438+
//! > ==========================================================================
439+
347440
//! > call_contract_syscall libfunc
348441

349442
//! > test_comments

0 commit comments

Comments
 (0)