Skip to content

Commit c0965f5

Browse files
chore(starknet_os): fix enum definitions to make the block input an array pr pass CI
1 parent afc29df commit c0965f5

File tree

3 files changed

+98
-64
lines changed

3 files changed

+98
-64
lines changed

crates/starknet_os/src/hints/enum_definition.rs

Lines changed: 84 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ use crate::hints::hint_implementation::kzg::implementation::store_da_segment;
127127
use crate::hints::hint_implementation::math::log2_ceil;
128128
use crate::hints::hint_implementation::os::{
129129
configure_kzg_manager,
130+
create_block_additional_hints,
131+
get_n_blocks,
130132
init_state_update_pointer,
131133
initialize_class_hashes,
132134
initialize_state_changes,
@@ -399,15 +401,17 @@ define_hint_enum!(
399401
block_timestamp,
400402
"memory[ap] = to_felt_or_relocatable(syscall_handler.block_info.block_timestamp)"
401403
),
404+
// TODO(Meshi): Fix hint implantation.
402405
(
403406
ChainId,
404407
chain_id,
405-
"memory[ap] = to_felt_or_relocatable(os_input.general_config.chain_id.value)"
408+
"memory[ap] = to_felt_or_relocatable(block_input.general_config.chain_id.value)"
406409
),
410+
// TODO(Meshi): Fix hint implantation.
407411
(
408412
FeeTokenAddress,
409413
fee_token_address,
410-
"memory[ap] = to_felt_or_relocatable(os_input.general_config.fee_token_address)"
414+
"memory[ap] = to_felt_or_relocatable(block_input.general_config.fee_token_address)"
411415
),
412416
(
413417
SequencerAddress,
@@ -431,13 +435,13 @@ define_hint_enum!(
431435
)
432436
ids.is_leaf = 1 if isinstance(bytecode_segment_structure, BytecodeLeaf) else 0"#}
433437
),
438+
// TODO(Meshi): Fix hint implantation.
434439
(
435440
WriteUseKzgDaToMemory,
436441
write_use_kzg_da_to_memory,
437-
indoc! {r#"
438-
memory[fp + 18] = to_felt_or_relocatable(syscall_handler.block_info.use_kzg_da and (
439-
not os_input.full_output
440-
))"#}
442+
indoc! {r#"memory[fp + 19] = to_felt_or_relocatable(syscall_handler.block_info.use_kzg_da and (
443+
not block_input.full_output
444+
))"#}
441445
),
442446
(
443447
ComputeIdsLow,
@@ -578,6 +582,7 @@ define_hint_enum!(
578582
"is_segment_used_callback": bytecode_segment_access_oracle.is_segment_used
579583
})"#}
580584
),
585+
// TODO(Meshi): Fix hint implantation.
581586
(
582587
EnterScopeWithAliases,
583588
enter_scope_with_aliases,
@@ -589,7 +594,7 @@ vm_enter_scope(dict(
589594
aliases=execution_helper.storage_by_address[ALIAS_CONTRACT_ADDRESS],
590595
execution_helper=execution_helper,
591596
__dict_manager=__dict_manager,
592-
os_input=os_input,
597+
block_input=block_input,
593598
))"#}
594599
),
595600
(
@@ -765,14 +770,15 @@ else:
765770
(
766771
SegmentsAddTemp,
767772
segments_add_temp,
768-
indoc! {r#"memory[fp + 6] = to_felt_or_relocatable(segments.add_temp_segment())"#
773+
indoc! {r#"memory[fp + 7] = to_felt_or_relocatable(segments.add_temp_segment())"#
769774
}
770775
),
771776
(StartTx, start_tx, indoc! {r#"execution_helper.start_tx()"# }),
777+
// TODO(Meshi): Fix hint implantation.
772778
(
773779
OsInputTransactions,
774780
os_input_transactions,
775-
indoc! {r#"memory[fp + 12] = to_felt_or_relocatable(len(os_input.transactions))"#
781+
indoc! {r#"memory[fp + 12] = to_felt_or_relocatable(len(block_input.transactions))"#
776782
}
777783
),
778784
(
@@ -966,13 +972,14 @@ segments.write_arg(ids.sha256_ptr_end, padding)"#}
966972
"is_deprecated = 1 if ids.execution_context.class_hash in __deprecated_class_hashes else 0"
967973
),
968974
(IsDeprecated, is_deprecated, "memory[ap] = to_felt_or_relocatable(is_deprecated)"),
975+
// TODO(Meshi): Fix hint implantation.
969976
(
970977
EnterSyscallScopes,
971978
enter_syscall_scopes,
972979
indoc! {r#"vm_enter_scope({
973980
'__deprecated_class_hashes': __deprecated_class_hashes,
974-
'transactions': iter(os_input.transactions),
975-
'component_hashes': os_input.declared_class_hash_to_component_hashes,
981+
'transactions': iter(block_input.transactions),
982+
'component_hashes': block_input.declared_class_hash_to_component_hashes,
976983
'execution_helper': execution_helper,
977984
'deprecated_syscall_handler': deprecated_syscall_handler,
978985
'syscall_handler': syscall_handler,
@@ -1269,11 +1276,12 @@ segments.write_arg(ids.sha256_ptr_end, padding)"#}
12691276
assert ids.value == value, "Inconsistent storage value.""#
12701277
}
12711278
),
1279+
// TODO(Meshi): Fix hint implantation.
12721280
(
12731281
GetOldBlockNumberAndHash,
12741282
get_old_block_number_and_hash,
12751283
indoc! {r#"
1276-
old_block_number_and_hash = program_input['old_block_number_and_hash']
1284+
old_block_number_and_hash = block_input.old_block_number_and_hash
12771285
assert (
12781286
old_block_number_and_hash is not None
12791287
), f"Block number is probably < {ids.STORED_BLOCK_HASH_BUFFER}."
@@ -1324,6 +1332,12 @@ segments.write_arg(ids.sha256_ptr_end, padding)"#}
13241332
ids.index = n_elms
13251333
ids.exists = 0"#}
13261334
),
1335+
// TODO(Meshi): Fix hint implantation.
1336+
(
1337+
GetBlocksNumber,
1338+
get_n_blocks,
1339+
r#"memory[fp + 0] = to_felt_or_relocatable(len(os_input.block_inputs))"#
1340+
),
13271341
(
13281342
StoreDaSegment,
13291343
store_da_segment,
@@ -1352,26 +1366,29 @@ segments.write_arg(ids.sha256_ptr_end, padding)"#}
13521366
ids.res = log2_ceil(ids.value)"#
13531367
}
13541368
),
1369+
// TODO(Meshi): Fix hint implantation.
13551370
(
13561371
WriteFullOutputToMemory,
13571372
write_full_output_to_memory,
1358-
indoc! {r#"memory[fp + 19] = to_felt_or_relocatable(os_input.full_output)"#}
1373+
indoc! {r#"memory[fp + 20] = to_felt_or_relocatable(block_input.full_output)"#}
13591374
),
13601375
(
13611376
ConfigureKzgManager,
13621377
configure_kzg_manager,
13631378
indoc! {r#"__serialize_data_availability_create_pages__ = True
1364-
kzg_manager = execution_helper.kzg_manager"#}
1379+
kzg_manager = global_hints.kzg_manager"#}
13651380
),
1381+
// TODO(Meshi): Fix hint implantation.
13661382
(
13671383
SetApToPrevBlockHash,
13681384
set_ap_to_prev_block_hash,
1369-
indoc! {r#"memory[ap] = to_felt_or_relocatable(os_input.prev_block_hash)"#}
1385+
indoc! {r#"memory[ap] = to_felt_or_relocatable(block_input.prev_block_hash)"#}
13701386
),
1387+
// TODO(Meshi): Fix hint implantation.
13711388
(
13721389
SetApToNewBlockHash,
13731390
set_ap_to_new_block_hash,
1374-
"memory[ap] = to_felt_or_relocatable(os_input.new_block_hash)"
1391+
"memory[ap] = to_felt_or_relocatable(block_input.new_block_hash)"
13751392
),
13761393
(
13771394
SetTreeStructure,
@@ -1538,44 +1555,45 @@ else:
15381555
read_ec_point_from_address,
15391556
r#"memory[ap] = to_felt_or_relocatable(ids.response.ec_point.address_ if ids.not_on_curve == 0 else segments.add())"#
15401557
),
1558+
// TODO(Meshi): Fix hint implantation.
15411559
(
15421560
SetPreimageForStateCommitments,
15431561
set_preimage_for_state_commitments,
1544-
indoc! {r#"
1545-
ids.initial_root = os_input.contract_state_commitment_info.previous_root
1546-
ids.final_root = os_input.contract_state_commitment_info.updated_root
1547-
preimage = {
1548-
int(root): children
1549-
for root, children in os_input.contract_state_commitment_info.commitment_facts.items()
1550-
}
1551-
assert os_input.contract_state_commitment_info.tree_height == ids.MERKLE_HEIGHT"#
1562+
indoc! {r#"ids.initial_root = block_input.contract_state_commitment_info.previous_root
1563+
ids.final_root = block_input.contract_state_commitment_info.updated_root
1564+
commitment_facts = block_input.contract_state_commitment_info.commitment_facts.items()
1565+
preimage = {
1566+
int(root): children
1567+
for root, children in commitment_facts
1568+
}
1569+
assert block_input.contract_state_commitment_info.tree_height == ids.MERKLE_HEIGHT"#
15521570
}
15531571
),
1572+
// TODO(Meshi): Fix hint implantation.
15541573
(
15551574
SetPreimageForClassCommitments,
15561575
set_preimage_for_class_commitments,
1557-
indoc! {r#"
1558-
ids.initial_root = os_input.contract_class_commitment_info.previous_root
1559-
ids.final_root = os_input.contract_class_commitment_info.updated_root
1560-
preimage = {
1561-
int(root): children
1562-
for root, children in os_input.contract_class_commitment_info.commitment_facts.items()
1563-
}
1564-
assert os_input.contract_class_commitment_info.tree_height == ids.MERKLE_HEIGHT"#
1576+
indoc! {r#"ids.initial_root = block_input.contract_class_commitment_info.previous_root
1577+
ids.final_root = block_input.contract_class_commitment_info.updated_root
1578+
commitment_facts = block_input.contract_class_commitment_info.commitment_facts.items()
1579+
preimage = {
1580+
int(root): children
1581+
for root, children in commitment_facts
1582+
}
1583+
assert block_input.contract_class_commitment_info.tree_height == ids.MERKLE_HEIGHT"#
15651584
}
15661585
),
15671586
(
15681587
SetPreimageForCurrentCommitmentInfo,
15691588
set_preimage_for_current_commitment_info,
1570-
indoc! {r#"
1571-
commitment_info = commitment_info_by_address[ids.contract_address]
1572-
ids.initial_contract_state_root = commitment_info.previous_root
1573-
ids.final_contract_state_root = commitment_info.updated_root
1574-
preimage = {
1575-
int(root): children
1576-
for root, children in commitment_info.commitment_facts.items()
1577-
}
1578-
assert commitment_info.tree_height == ids.MERKLE_HEIGHT"#
1589+
indoc! {r#"ids.initial_contract_state_root = commitment_info.previous_root
1590+
ids.final_contract_state_root = commitment_info.updated_root
1591+
commitment_info = commitment_info_by_address[ids.contract_address]
1592+
preimage = {
1593+
int(root): children
1594+
for root, children in commitment_info.commitment_facts.items()
1595+
}
1596+
assert commitment_info.tree_height == ids.MERKLE_HEIGHT"#
15791597
}
15801598
),
15811599
(
@@ -1661,22 +1679,14 @@ memory[ap] = 1 if case != 'both' else 0"#
16611679
),
16621680
(OsLoggerExitSyscall, os_logger_exit_syscall, "exit_syscall()"),
16631681
(IsOnCurve, is_on_curve, "ids.is_on_curve = (y * y) % SECP_P == y_square_int"),
1682+
// TODO(Meshi): Fix hint implantation.
16641683
(
16651684
StarknetOsInput,
16661685
starknet_os_input,
1667-
indoc! {r#"
1668-
from starkware.starknet.core.os.os_hints import get_execution_helper_and_syscall_handlers
1669-
from starkware.starknet.core.os.os_input import StarknetOsInput
1670-
1671-
os_input = StarknetOsInput.load(data=program_input)
1686+
indoc! {r#"from starkware.starknet.core.os.os_input import StarknetOsInput
16721687
1673-
(
1674-
execution_helper,
1675-
syscall_handler,
1676-
deprecated_syscall_handler
1677-
) = get_execution_helper_and_syscall_handlers(
1678-
os_input=os_input, global_hints=global_hints
1679-
)"#
1688+
os_input = StarknetOsInput.load(data=program_input)
1689+
block_input_iterator = iter(os_input.block_inputs)"#
16801690
}
16811691
),
16821692
(
@@ -1689,20 +1699,33 @@ memory[ap] = 1 if case != 'both' else 0"#
16891699
(
16901700
InitializeStateChanges,
16911701
initialize_state_changes,
1692-
indoc! {r#"
1693-
from starkware.python.utils import from_bytes
1702+
indoc! {r#"from starkware.python.utils import from_bytes
16941703
1695-
initial_dict = {
1696-
address: segments.gen_arg(
1697-
(from_bytes(contract.contract_hash), segments.add(), contract.nonce))
1698-
for address, contract in os_input.contracts.items()
1699-
}"#
1704+
initial_dict = {
1705+
address: segments.gen_arg(
1706+
(from_bytes(contract.contract_hash), segments.add(), contract.nonce))
1707+
for address, contract in block_input.contracts.items()
1708+
}"#
17001709
}
17011710
),
1711+
// TODO(Meshi): Fix hint implantation.
17021712
(
17031713
InitializeClassHashes,
17041714
initialize_class_hashes,
1705-
"initial_dict = os_input.class_hash_to_compiled_class_hash"
1715+
"initial_dict = block_input.class_hash_to_compiled_class_hash"
1716+
),
1717+
(
1718+
CreateBlockAdditionalHints,
1719+
create_block_additional_hints,
1720+
indoc! {r#"from starkware.starknet.core.os.os_hints import get_execution_helper_and_syscall_handlers
1721+
block_input = next(block_input_iterator)
1722+
(
1723+
execution_helper,
1724+
syscall_handler,
1725+
deprecated_syscall_handler
1726+
) = get_execution_helper_and_syscall_handlers(
1727+
block_input=block_input, global_hints=global_hints
1728+
)"#}
17061729
)
17071730
);
17081731

crates/starknet_os/src/hints/hint_implementation/os.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,13 @@ pub(crate) fn init_state_update_pointer<S: StateReader>(
6464
) -> OsHintResult {
6565
todo!()
6666
}
67+
68+
pub(crate) fn get_n_blocks<S: StateReader>(HintArgs { .. }: HintArgs<'_, S>) -> OsHintResult {
69+
todo!()
70+
}
71+
72+
pub(crate) fn create_block_additional_hints<S: StateReader>(
73+
HintArgs { .. }: HintArgs<'_, S>,
74+
) -> OsHintResult {
75+
todo!()
76+
}

crates/starknet_os/src/hints/nondet_offsets.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ pub(crate) static NONDET_FP_OFFSETS: LazyLock<HashMap<AllHints, usize>> = LazyLo
2121
HashMap::from([
2222
(AllHints::OsHint(OsHint::OsInputTransactions), 12),
2323
(AllHints::OsHint(OsHint::ReadAliasFromKey), 0),
24-
(AllHints::OsHint(OsHint::SegmentsAddTemp), 6),
24+
(AllHints::OsHint(OsHint::SegmentsAddTemp), 7),
2525
(AllHints::OsHint(OsHint::SetFpPlus4ToTxNonce), 4),
26+
(AllHints::OsHint(OsHint::GetBlocksNumber), 0),
2627
(AllHints::OsHint(OsHint::TxAccountDeploymentDataLen), 4),
27-
(AllHints::OsHint(OsHint::WriteFullOutputToMemory), 19),
28-
(AllHints::OsHint(OsHint::WriteUseKzgDaToMemory), 18),
28+
(AllHints::OsHint(OsHint::WriteFullOutputToMemory), 20),
29+
(AllHints::OsHint(OsHint::WriteUseKzgDaToMemory), 19),
2930
])
3031
});
3132

0 commit comments

Comments
 (0)