Skip to content

Commit 07c1313

Browse files
chore(starknet_os): iterate classes in ascending order (#6386)
1 parent 737666a commit 07c1313

4 files changed

Lines changed: 17 additions & 16 deletions

File tree

crates/starknet_os/src/hint_processor/snos_hint_processor.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::collections::BTreeMap;
12
#[cfg(feature = "testing")]
23
use std::collections::HashSet;
34

@@ -97,8 +98,8 @@ pub struct SnosHintProcessor<'a, S: StateReader> {
9798
pub(crate) execution_helpers_manager: ExecutionHelpersManager<'a, S>,
9899
pub(crate) os_hints_config: OsHintsConfig,
99100
pub syscall_hint_processor: SyscallHintProcessor,
100-
pub(crate) deprecated_compiled_classes: HashMap<ClassHash, ContractClass>,
101-
pub(crate) compiled_classes: HashMap<ClassHash, CasmContractClass>,
101+
pub(crate) deprecated_compiled_classes: BTreeMap<ClassHash, ContractClass>,
102+
pub(crate) compiled_classes: BTreeMap<ClassHash, CasmContractClass>,
102103
pub(crate) state_update_pointers: Option<StateUpdatePointers>,
103104
pub(crate) deprecated_syscall_hint_processor: DeprecatedSyscallHintProcessor,
104105
builtin_hint_processor: BuiltinHintProcessor,
@@ -121,8 +122,8 @@ impl<'a, S: StateReader> SnosHintProcessor<'a, S> {
121122
os_hints_config: OsHintsConfig,
122123
os_block_inputs: Vec<&'a OsBlockInput>,
123124
cached_state_inputs: Vec<CachedStateInput>,
124-
deprecated_compiled_classes: HashMap<ClassHash, ContractClass>,
125-
compiled_classes: HashMap<ClassHash, CasmContractClass>,
125+
deprecated_compiled_classes: BTreeMap<ClassHash, ContractClass>,
126+
compiled_classes: BTreeMap<ClassHash, CasmContractClass>,
126127
state_readers: Vec<S>,
127128
syscall_hint_processor: SyscallHintProcessor,
128129
deprecated_syscall_hint_processor: DeprecatedSyscallHintProcessor,
@@ -289,8 +290,8 @@ impl<'a> SnosHintProcessor<'a, DictStateReader> {
289290
os_hints_config,
290291
block_inputs,
291292
state_inputs,
292-
HashMap::new(), // deprecated_compiled_classes.
293-
HashMap::new(), // compiled_classes.
293+
BTreeMap::new(),
294+
BTreeMap::new(),
294295
vec![state_reader],
295296
syscall_handler,
296297
deprecated_syscall_handler,

crates/starknet_os/src/hints/enum_definition.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ define_hint_enum!(
577577
compiled_hash: create_bytecode_segment_structure(
578578
bytecode=compiled_class.bytecode,
579579
bytecode_segment_lengths=compiled_class.bytecode_segment_lengths,
580-
) for compiled_hash, compiled_class in os_input.compiled_classes.items()
580+
) for compiled_hash, compiled_class in sorted(os_input.compiled_classes.items())
581581
}
582582
bytecode_segment_access_oracle = BytecodeAccessOracle(is_pc_accessed_callback=is_accessed)
583583
vm_enter_scope({
@@ -760,7 +760,7 @@ else:
760760
__deprecated_class_hashes=set(os_input.deprecated_compiled_classes.keys())
761761
ids.n_compiled_class_facts = len(os_input.deprecated_compiled_classes)
762762
vm_enter_scope({
763-
'compiled_class_facts': iter(os_input.deprecated_compiled_classes.items()),
763+
'compiled_class_facts': iter(sorted(os_input.deprecated_compiled_classes.items())),
764764
})"##
765765
}
766766
),
@@ -1849,9 +1849,9 @@ define_hint_extension_enum!(
18491849
)
18501850
18511851
ids.n_compiled_class_facts = len(os_input.compiled_classes)
1852-
ids.compiled_class_facts = (compiled_class_facts_end := segments.add())
1852+
ids.compiled_class_facts = segments.add()
18531853
for i, (compiled_class_hash, compiled_class) in enumerate(
1854-
os_input.compiled_classes.items()
1854+
sorted(os_input.compiled_classes.items())
18551855
):
18561856
# Load the compiled class.
18571857
cairo_contract = get_compiled_class_struct(

crates/starknet_os/src/hints/hint_implementation/compiled_class/implementation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::HashMap;
1+
use std::collections::{BTreeMap, HashMap};
22

33
use blockifier::state::state_api::StateReader;
44
use cairo_vm::any_box;
@@ -52,7 +52,7 @@ pub(crate) fn assert_end_of_bytecode_segments<S: StateReader>(
5252
pub(crate) fn bytecode_segment_structure<S: StateReader>(
5353
HintArgs { hint_processor, exec_scopes, ids_data, ap_tracking, vm, .. }: HintArgs<'_, '_, S>,
5454
) -> OsHintResult {
55-
let bytecode_segment_structures: &HashMap<ClassHash, BytecodeSegmentNode> =
55+
let bytecode_segment_structures: &BTreeMap<ClassHash, BytecodeSegmentNode> =
5656
exec_scopes.get_ref(Scope::BytecodeSegmentStructures.into())?;
5757

5858
let class_hash_address = get_address_of_nested_fields(
@@ -148,7 +148,7 @@ pub(crate) fn set_ap_to_segment_hash<S: StateReader>(
148148
pub(crate) fn validate_compiled_class_facts_post_execution<S: StateReader>(
149149
HintArgs { hint_processor, exec_scopes, .. }: HintArgs<'_, '_, S>,
150150
) -> OsHintResult {
151-
let mut bytecode_segment_structures = HashMap::new();
151+
let mut bytecode_segment_structures = BTreeMap::new();
152152
for (compiled_hash, compiled_class) in hint_processor.compiled_classes.iter() {
153153
bytecode_segment_structures.insert(
154154
*compiled_hash,

crates/starknet_os/src/io/os_input.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::HashMap;
1+
use std::collections::{BTreeMap, HashMap};
22

33
use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
44
use serde::Serialize;
@@ -79,8 +79,8 @@ pub struct OsHints {
7979
pub struct StarknetOsInput {
8080
pub os_block_inputs: Vec<OsBlockInput>,
8181
pub cached_state_inputs: Vec<CachedStateInput>,
82-
pub(crate) deprecated_compiled_classes: HashMap<ClassHash, ContractClass>,
83-
pub(crate) compiled_classes: HashMap<ClassHash, CasmContractClass>,
82+
pub(crate) deprecated_compiled_classes: BTreeMap<ClassHash, ContractClass>,
83+
pub(crate) compiled_classes: BTreeMap<ClassHash, CasmContractClass>,
8484
}
8585

8686
// TODO(Meshi): Remove Once the blockifier ChainInfo do not support deprecated fee token.

0 commit comments

Comments
 (0)