-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
97 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use std::collections::HashMap; | ||
|
||
use cairo_vm::{ | ||
hint_processor::builtin_hint_processor::{ | ||
builtin_hint_processor_definition::HintProcessorData, hint_utils::insert_value_into_ap, | ||
}, | ||
types::exec_scope::ExecutionScopes, | ||
vm::{errors::hint_errors::HintError, vm_core::VirtualMachine}, | ||
Felt252, | ||
}; | ||
|
||
pub const SEGMENTS_ADD: &str = "memory[ap] = segments.add()"; | ||
pub const SEGMENTS_ADD_TO_FELT_OR_RELOCATABLE: &str = | ||
"memory[ap] = to_felt_or_relocatable(segments.add())"; | ||
|
||
pub fn segments_add( | ||
vm: &mut VirtualMachine, | ||
_exec_scope: &mut ExecutionScopes, | ||
_hint_data: &HintProcessorData, | ||
_constants: &HashMap<String, Felt252>, | ||
) -> Result<(), HintError> { | ||
let segment = vm.add_memory_segment(); | ||
insert_value_into_ap(vm, segment) | ||
} | ||
|
||
pub const SET_FP_PLUS_8_SEGMENTS_ADD: &str = | ||
"memory[fp + 8] = to_felt_or_relocatable(segments.add())"; | ||
|
||
pub fn set_fp_plus_8_segments_add( | ||
vm: &mut VirtualMachine, | ||
_exec_scope: &mut ExecutionScopes, | ||
_hint_data: &HintProcessorData, | ||
_constants: &HashMap<String, Felt252>, | ||
) -> Result<(), HintError> { | ||
let segment = vm.add_memory_segment(); | ||
Ok(vm.insert_value((vm.get_fp() + 8)?, segment)?) | ||
} | ||
|
||
pub const SET_FP_PLUS_9_SEGMENTS_ADD: &str = | ||
"memory[fp + 9] = to_felt_or_relocatable(segments.add())"; | ||
|
||
pub fn set_fp_plus_9_segments_add( | ||
vm: &mut VirtualMachine, | ||
_exec_scope: &mut ExecutionScopes, | ||
_hint_data: &HintProcessorData, | ||
_constants: &HashMap<String, Felt252>, | ||
) -> Result<(), HintError> { | ||
let segment = vm.add_memory_segment(); | ||
Ok(vm.insert_value((vm.get_fp() + 9)?, segment)?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use std::collections::HashMap; | ||
|
||
use cairo_vm::{ | ||
hint_processor::builtin_hint_processor::builtin_hint_processor_definition::HintProcessorData, | ||
types::exec_scope::ExecutionScopes, | ||
vm::{errors::hint_errors::HintError, vm_core::VirtualMachine}, | ||
Felt252, | ||
}; | ||
|
||
mod add_segments; | ||
|
||
pub fn run_hint( | ||
vm: &mut VirtualMachine, | ||
exec_scope: &mut ExecutionScopes, | ||
hint_data: &HintProcessorData, | ||
constants: &HashMap<String, Felt252>, | ||
) -> Result<(), HintError> { | ||
match hint_data.code.as_str() { | ||
add_segments::SEGMENTS_ADD | add_segments::SEGMENTS_ADD_TO_FELT_OR_RELOCATABLE => { | ||
add_segments::segments_add(vm, exec_scope, hint_data, constants) | ||
} | ||
add_segments::SET_FP_PLUS_8_SEGMENTS_ADD => { | ||
add_segments::set_fp_plus_8_segments_add(vm, exec_scope, hint_data, constants) | ||
} | ||
add_segments::SET_FP_PLUS_9_SEGMENTS_ADD => { | ||
add_segments::set_fp_plus_9_segments_add(vm, exec_scope, hint_data, constants) | ||
} | ||
_ => Err(HintError::UnknownHint( | ||
hint_data.code.to_string().into_boxed_str(), | ||
)), | ||
} | ||
} |