Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(starknet_os): integrate compiled_class hints #3685

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/starknet_os/src/hints.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod block_context;
pub mod bls_field;
pub mod builtins;
pub mod compiled_class;
pub mod enum_definition;
pub mod enum_generation;
pub mod error;
Expand Down
49 changes: 49 additions & 0 deletions crates/starknet_os/src/hints/compiled_class.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use std::collections::HashMap;

use cairo_vm::hint_processor::hint_processor_definition::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::HintResult;

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

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

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

pub fn set_ap_to_segment_hash(
_vm: &mut VirtualMachine,
_exec_scopes: &mut ExecutionScopes,
_ids_data: &HashMap<String, HintReference>,
_ap_tracking: &ApTracking,
_constants: &HashMap<String, Felt>,
) -> HintResult {
todo!()
}
45 changes: 45 additions & 0 deletions crates/starknet_os/src/hints/enum_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ use crate::hints::block_context::{
};
use crate::hints::bls_field::compute_ids_low;
use crate::hints::builtins::{select_builtin, selected_builtins, update_builtin_ptrs};
use crate::hints::compiled_class::{
assert_end_of_bytecode_segments,
assign_bytecode_segments,
iter_current_segment_info,
set_ap_to_segment_hash,
};
use crate::hints::error::{HintExtensionResult, HintResult, OsHintError};
use crate::hints::types::{HintEnum, HintExtensionImplementation, HintImplementation};
use crate::{define_hint_enum, define_hint_extension_enum};
Expand Down Expand Up @@ -184,6 +190,45 @@ define_hint_enum!(
),
)"#
}
),
(
AssignBytecodeSegments,
assign_bytecode_segments,
indoc! {r#"
bytecode_segments = iter(bytecode_segment_structure.segments)"#
}
),
(
AssertEndOfBytecodeSegments,
assert_end_of_bytecode_segments,
indoc! {r#"
assert next(bytecode_segments, None) is None"#
}
),
(
IterCurrentSegmentInfo,
iter_current_segment_info,
indoc! {r#"
current_segment_info = next(bytecode_segments)
is_used = current_segment_info.is_used
ids.is_segment_used = 1 if is_used else 0
is_used_leaf = is_used and isinstance(current_segment_info.inner_structure, BytecodeLeaf)
ids.is_used_leaf = 1 if is_used_leaf else 0
ids.segment_length = current_segment_info.segment_length
vm_enter_scope(new_scope_locals={
"bytecode_segment_structure": current_segment_info.inner_structure,
})"#
}
),
(
SetApToSegmentHash,
set_ap_to_segment_hash,
indoc! {r#"
memory[ap] = to_felt_or_relocatable(bytecode_segment_structure.hash())"#
}
)
);

Expand Down