Skip to content

Commit 11647d9

Browse files
apollo_starknet_os_program: add OsGlobalContext as a flat member of BlockContext (#10674)
1 parent 479fd39 commit 11647d9

File tree

6 files changed

+30
-53
lines changed

6 files changed

+30
-53
lines changed

crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/block_context.cairo

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,43 +22,14 @@ struct CompiledClassFactsBundle {
2222
deprecated_compiled_class_facts: DeprecatedCompiledClassFact*,
2323
}
2424

25-
// Represents information that is the same throughout the block.
26-
struct BlockContext {
27-
// Parameters for select_builtins.
28-
builtin_params: BuiltinParams*,
29-
30-
// A list of (compiled_class_hash, compiled_class) with the classes that are executed
31-
// in this block.
32-
n_compiled_class_facts: felt,
33-
compiled_class_facts: CompiledClassFact*,
34-
35-
// A list of (deprecated_compiled_class_hash, deprecated_compiled_class) with
36-
// the classes that are executed in this block.
37-
n_deprecated_compiled_class_facts: felt,
38-
deprecated_compiled_class_facts: DeprecatedCompiledClassFact*,
39-
40-
// Information about the block.
41-
block_info_for_execute: BlockInfo*,
42-
// A version of `block_info` that will be returned by the 'get_execution_info'
43-
// syscall during '__validate__'.
44-
// Some of the fields, which cannot be used in validate mode, are zeroed out.
45-
block_info_for_validate: BlockInfo*,
46-
// StarknetOsConfig instance.
47-
starknet_os_config: StarknetOsConfig,
48-
// A function pointer to the 'execute_syscalls' function.
49-
execute_syscalls_ptr: felt*,
50-
// A function pointer to the 'execute_deprecated_syscalls' function.
51-
execute_deprecated_syscalls_ptr: felt*,
52-
}
53-
5425
// Holds global context for the OS execution.
5526
struct OsGlobalContext {
5627
// OS config available globally for all blocks.
57-
starknet_os_config: StarknetOsConfig*,
28+
starknet_os_config: StarknetOsConfig,
5829
starknet_os_config_hash: felt,
5930
6031
// Compiled class facts available globally for all blocks.
61-
compiled_class_facts_bundle: CompiledClassFactsBundle*,
32+
compiled_class_facts_bundle: CompiledClassFactsBundle,
6233
6334
// Parameters for select_builtins.
6435
builtin_params: BuiltinParams*,
@@ -68,6 +39,17 @@ struct OsGlobalContext {
6839
execute_deprecated_syscalls_ptr: felt*,
6940
}
7041

42+
// Represents information that is the same throughout the block.
43+
struct BlockContext {
44+
os_global_context: OsGlobalContext,
45+
// Information about the block.
46+
block_info_for_execute: BlockInfo*,
47+
// A version of `block_info` that will be returned by the 'get_execution_info'
48+
// syscall during '__validate__'.
49+
// Some of the fields, which cannot be used in validate mode, are zeroed out.
50+
block_info_for_validate: BlockInfo*,
51+
}
52+
7153
// Returns a BlockContext instance.
7254
//
7355
// 'syscall_handler' should be passed as a hint variable.
@@ -85,11 +67,7 @@ func get_block_context{range_check_ptr}(os_global_context: OsGlobalContext*) ->
8567
tempvar block_timestamp_for_validate = divided_block_timestamp * VALIDATE_TIMESTAMP_ROUNDING;
8668
let compiled_class_facts_bundle = os_global_context.compiled_class_facts_bundle;
8769
local block_context: BlockContext = BlockContext(
88-
builtin_params=os_global_context.builtin_params,
89-
n_compiled_class_facts=compiled_class_facts_bundle.n_compiled_class_facts,
90-
compiled_class_facts=compiled_class_facts_bundle.compiled_class_facts,
91-
n_deprecated_compiled_class_facts=compiled_class_facts_bundle.n_deprecated_compiled_class_facts,
92-
deprecated_compiled_class_facts=compiled_class_facts_bundle.deprecated_compiled_class_facts,
70+
os_global_context=[os_global_context],
9371
block_info_for_execute=new BlockInfo(
9472
block_number=block_number,
9573
block_timestamp=block_timestamp,
@@ -100,9 +78,6 @@ func get_block_context{range_check_ptr}(os_global_context: OsGlobalContext*) ->
10078
block_timestamp=block_timestamp_for_validate,
10179
sequencer_address=0,
10280
),
103-
starknet_os_config=[os_global_context.starknet_os_config],
104-
execute_syscalls_ptr=os_global_context.execute_syscalls_ptr,
105-
execute_deprecated_syscalls_ptr=os_global_context.execute_deprecated_syscalls_ptr,
10681
);
10782

10883
let (__fp__, _) = get_fp_and_pc();

crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/execution/deprecated_execute_entry_point.cairo

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func call_execute_deprecated_syscalls{
9696
syscall_size,
9797
syscall_ptr: felt*,
9898
) {
99-
jmp abs block_context.execute_deprecated_syscalls_ptr;
99+
jmp abs block_context.os_global_context.execute_deprecated_syscalls_ptr;
100100
}
101101

102102
// Executes an entry point in a contract.
@@ -120,10 +120,11 @@ func deprecated_execute_entry_point{
120120

121121
// The key must be at offset 0.
122122
static_assert DeprecatedCompiledClassFact.hash == 0;
123+
let compiled_class_facts_bundle = block_context.os_global_context.compiled_class_facts_bundle;
123124
let (compiled_class_fact: DeprecatedCompiledClassFact*) = find_element(
124-
array_ptr=block_context.deprecated_compiled_class_facts,
125+
array_ptr=compiled_class_facts_bundle.deprecated_compiled_class_facts,
125126
elm_size=DeprecatedCompiledClassFact.SIZE,
126-
n_elms=block_context.n_deprecated_compiled_class_facts,
127+
n_elms=compiled_class_facts_bundle.n_deprecated_compiled_class_facts,
127128
key=execution_context.class_hash,
128129
);
129130
local compiled_class: DeprecatedCompiledClass* = compiled_class_fact.compiled_class;
@@ -155,7 +156,7 @@ func deprecated_execute_entry_point{
155156
assert [os_context] = cast(syscall_ptr, felt);
156157

157158
let n_builtins = BuiltinEncodings.SIZE;
158-
local builtin_params: BuiltinParams* = block_context.builtin_params;
159+
local builtin_params: BuiltinParams* = block_context.os_global_context.builtin_params;
159160
select_builtins(
160161
n_builtins=n_builtins,
161162
all_encodings=builtin_params.builtin_encodings,

crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/execution/execute_entry_point.cairo

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func call_execute_syscalls{
9090
revert_log: RevertLogEntry*,
9191
outputs: OsCarriedOutputs*,
9292
}(block_context: BlockContext*, execution_context: ExecutionContext*, syscall_ptr_end: felt*) {
93-
jmp abs block_context.execute_syscalls_ptr;
93+
jmp abs block_context.os_global_context.execute_syscalls_ptr;
9494
}
9595

9696
// Returns the CompiledClassEntryPoint, based on 'compiled_class' and 'execution_context'.
@@ -163,10 +163,11 @@ func execute_entry_point{
163163

164164
// The key must be at offset 0.
165165
static_assert CompiledClassFact.hash == 0;
166+
let compiled_class_facts_bundle = block_context.os_global_context.compiled_class_facts_bundle;
166167
let (compiled_class_fact: CompiledClassFact*) = find_element(
167-
array_ptr=block_context.compiled_class_facts,
168+
array_ptr=compiled_class_facts_bundle.compiled_class_facts,
168169
elm_size=CompiledClassFact.SIZE,
169-
n_elms=block_context.n_compiled_class_facts,
170+
n_elms=compiled_class_facts_bundle.n_compiled_class_facts,
170171
key=compiled_class_hash,
171172
);
172173
local compiled_class: CompiledClass* = compiled_class_fact.compiled_class;
@@ -213,7 +214,7 @@ func execute_entry_point{
213214
let builtin_ptrs: BuiltinPointers* = prepare_builtin_ptrs_for_execute(builtin_ptrs);
214215

215216
let n_builtins = BuiltinEncodings.SIZE;
216-
local builtin_params: BuiltinParams* = block_context.builtin_params;
217+
local builtin_params: BuiltinParams* = block_context.os_global_context.builtin_params;
217218
local calldata_size: felt = execution_context.calldata_size;
218219
local calldata_start: felt* = execution_context.calldata;
219220
local calldata_end: felt* = calldata_start + calldata_size;

crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/execution/execute_transactions.cairo

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ func charge_fee{
337337
assert_nn_le(calldata.amount.low, max_fee);
338338

339339
// TODO(ilya, 01/01/2026): Consider caching the fee_token_class_hash.
340-
local fee_token_address = block_context.starknet_os_config.fee_token_address;
340+
local fee_token_address = block_context.os_global_context.starknet_os_config.fee_token_address;
341341
let (fee_state_entry: StateEntry*) = dict_read{dict_ptr=contract_state_changes}(
342342
key=fee_token_address
343343
);
@@ -387,7 +387,7 @@ func get_account_tx_common_fields(
387387
tx_hash_prefix=tx_hash_prefix,
388388
version=3,
389389
sender_address=sender_address,
390-
chain_id=block_context.starknet_os_config.chain_id,
390+
chain_id=block_context.os_global_context.starknet_os_config.chain_id,
391391
nonce=nondet %{ tx.nonce %},
392392
tip=nondet %{ tx.tip %},
393393
n_resource_bounds=3,
@@ -593,7 +593,7 @@ func execute_l1_handler_transaction{
593593
local tx_execution_info: ExecutionInfo* = tx_execution_context.execution_info;
594594

595595
local nonce = nondet %{ tx.nonce %};
596-
local chain_id = block_context.starknet_os_config.chain_id;
596+
local chain_id = block_context.os_global_context.starknet_os_config.chain_id;
597597

598598
let pedersen_ptr = builtin_ptrs.selectable.pedersen;
599599
with pedersen_ptr {

crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/os.cairo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,9 +497,9 @@ func get_os_global_context{
497497
label_value=execute_deprecated_syscalls
498498
);
499499
tempvar os_global_context: OsGlobalContext* = new OsGlobalContext(
500-
starknet_os_config=starknet_os_config,
500+
starknet_os_config=[starknet_os_config],
501501
starknet_os_config_hash=starknet_os_config_hash,
502-
compiled_class_facts_bundle=new CompiledClassFactsBundle(
502+
compiled_class_facts_bundle=CompiledClassFactsBundle(
503503
n_compiled_class_facts=n_compiled_class_facts,
504504
compiled_class_facts=compiled_class_facts,
505505
builtin_costs=builtin_costs,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"os": "0x49bd34ac72e2a7287a8acd58abc80f0fd200b15fc98b87a083b34132e9ac4e6",
2+
"os": "0x4e96973924663401010103d46b585b71995195402b671b43e8ab21c8bd08105",
33
"aggregator": "0x48f2eacd9ca42f9ec5ed541c48c5b4450abee50df44e9cbb5ebf7f61e87d0cc",
44
"aggregator_with_prefix": "0x683eebd5b16190d5f9c73cc8b17d1498172494fa7d7bd0dc889378e01f15a98"
55
}

0 commit comments

Comments
 (0)