Skip to content

Commit

Permalink
feat(starknet_os): integrate deprecated_compiled_class hints
Browse files Browse the repository at this point in the history
  • Loading branch information
dorimedini-starkware committed Jan 26, 2025
1 parent 5a62199 commit aa6c88a
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/starknet_os/src/hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub mod block_context;
pub mod bls_field;
pub mod builtins;
pub mod compiled_class;
pub mod deprecated_compiled_class;
pub mod enum_definition;
pub mod enum_generation;
pub mod error;
Expand Down
39 changes: 39 additions & 0 deletions crates/starknet_os/src/hints/deprecated_compiled_class.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use std::collections::HashMap;

use cairo_vm::hint_processor::hint_processor_definition::{HintProcessor, HintReference};
use cairo_vm::serde::deserialize_program::ApTracking;
use cairo_vm::types::exec_scope::ExecutionScopes;
use cairo_vm::vm::vm_core::VirtualMachine;
use starknet_types_core::felt::Felt;

use crate::hints::error::{HintExtensionResult, HintResult};

pub fn load_deprecated_class_facts(
_vm: &mut VirtualMachine,
_exec_scopes: &mut ExecutionScopes,
_ids_data: &HashMap<String, HintReference>,
_ap_tracking: &ApTracking,
_constants: &HashMap<String, Felt>,
) -> HintResult {
todo!()
}

pub fn load_deprecated_class_inner(
_vm: &mut VirtualMachine,
_exec_scopes: &mut ExecutionScopes,
_ids_data: &HashMap<String, HintReference>,
_ap_tracking: &ApTracking,
_constants: &HashMap<String, Felt>,
) -> HintResult {
todo!()
}

pub fn load_deprecated_class(
_hint_processor: &dyn HintProcessor,
_vm: &mut VirtualMachine,
_exec_scopes: &mut ExecutionScopes,
_ids_data: &HashMap<String, HintReference>,
_ap_tracking: &ApTracking,
) -> HintExtensionResult {
todo!()
}
48 changes: 48 additions & 0 deletions crates/starknet_os/src/hints/enum_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ use crate::hints::compiled_class::{
iter_current_segment_info,
set_ap_to_segment_hash,
};
use crate::hints::deprecated_compiled_class::{
load_deprecated_class,
load_deprecated_class_facts,
load_deprecated_class_inner,
};
use crate::hints::error::{HintExtensionResult, HintResult, OsHintError};
use crate::hints::stateless_compression::{
compression_hint,
Expand Down Expand Up @@ -263,6 +268,34 @@ define_hint_enum!(
indoc! {r#"memory[ids.decompressed_dst] = ids.packed_felt % ids.elm_bound"#
}
),
(
LoadDeprecatedClassFacts,
load_deprecated_class_facts,
indoc! {r##"
# Creates a set of deprecated class hashes to distinguish calls to deprecated entry points.
__deprecated_class_hashes=set(os_input.deprecated_compiled_classes.keys())
ids.compiled_class_facts = segments.add()
ids.n_compiled_class_facts = len(os_input.deprecated_compiled_classes)
vm_enter_scope({
'compiled_class_facts': iter(os_input.deprecated_compiled_classes.items()),
})"##
}
),
(
LoadDeprecatedClassInner,
load_deprecated_class_inner,
indoc! {r#"
from starkware.starknet.core.os.contract_class.deprecated_class_hash import (
get_deprecated_contract_class_struct,
)
compiled_class_hash, compiled_class = next(compiled_class_facts)
cairo_contract = get_deprecated_contract_class_struct(
identifiers=ids._context.identifiers, contract_class=compiled_class)
ids.compiled_class = segments.gen_arg(cairo_contract)"#
}
),
);

define_hint_extension_enum!(
Expand All @@ -283,4 +316,19 @@ define_hint_extension_enum!(
)"#
}
),
(
LoadDeprecatedClass,
load_deprecated_class,
indoc! {r#"
from starkware.python.utils import from_bytes
computed_hash = ids.compiled_class_fact.hash
expected_hash = compiled_class_hash
assert computed_hash == expected_hash, (
"Computed compiled_class_hash is inconsistent with the hash in the os_input. "
f"Computed hash = {computed_hash}, Expected hash = {expected_hash}.")
vm_load_program(compiled_class.program, ids.compiled_class.bytecode_ptr)"#
}
)
);

0 comments on commit aa6c88a

Please sign in to comment.