diff --git a/src/hints/hints_raw.rs b/src/hints/hints_raw.rs index 6fc99b42..c0c36527 100644 --- a/src/hints/hints_raw.rs +++ b/src/hints/hints_raw.rs @@ -48,3 +48,14 @@ pub const INITIALIZE_CLASS_HASHES: &str = "initial_dict = os_input.class_hash_to pub const GET_BLOCK_MAPPING: &str = "ids.state_entry = __dict_manager.get_dict(ids.contract_state_changes)[\n ids.BLOCK_HASH_CONTRACT_ADDRESS\n]"; + +pub const SEGMENTS_ADD: &str = "memory[ap] = to_felt_or_relocatable(segments.add())"; + +pub const SEGMENTS_ADD_TEMP: &str = "memory[ap] = to_felt_or_relocatable(segments.add_temp_segment())"; + +pub const TRANSACTIONS_LEN: &str = "memory[ap] = to_felt_or_relocatable(len(os_input.transactions))"; + +pub const ENTER_SYSCALL_SCOPES: &str = + "vm_enter_scope({\n '__deprecated_class_hashes': __deprecated_class_hashes,\n 'transactions': \ + iter(os_input.transactions),\n 'execution_helper': execution_helper,\n 'deprecated_syscall_handler': \ + deprecated_syscall_handler,\n 'syscall_handler': syscall_handler,\n '__dict_manager': __dict_manager,\n})"; diff --git a/src/hints/mod.rs b/src/hints/mod.rs index 5a948d94..125cce70 100644 --- a/src/hints/mod.rs +++ b/src/hints/mod.rs @@ -59,6 +59,15 @@ pub fn sn_hint_processor() -> BuiltinHintProcessor { let initialize_class_hashes_hint = HintFunc(Box::new(initialize_class_hashes)); hint_processor.add_hint(String::from(hints_raw::INITIALIZE_CLASS_HASHES), Rc::new(initialize_class_hashes_hint)); + let segments_add_hint = HintFunc(Box::new(segments_add)); + hint_processor.add_hint(String::from(hints_raw::SEGMENTS_ADD), Rc::new(segments_add_hint)); + + let segments_add_temp_hint = HintFunc(Box::new(segments_add_temp)); + hint_processor.add_hint(String::from(hints_raw::SEGMENTS_ADD_TEMP), Rc::new(segments_add_temp_hint)); + + let transactions_len_hint = HintFunc(Box::new(transactions_len)); + hint_processor.add_hint(String::from(hints_raw::TRANSACTIONS_LEN), Rc::new(transactions_len_hint)); + hint_processor } @@ -168,3 +177,66 @@ pub fn initialize_class_hashes( exec_scopes.insert_box("initial_dict", Box::new(class_dict)); Ok(()) } + +/// Implements hint: +/// +/// memory[ap] = to_felt_or_relocatable(segments.add()) +pub fn segments_add( + vm: &mut VirtualMachine, + _exec_scopes: &mut ExecutionScopes, + _ids_data: &HashMap, + _ap_tracking: &ApTracking, + _constants: &HashMap, +) -> Result<(), HintError> { + let segment = vm.add_memory_segment(); + insert_value_into_ap(vm, segment) +} + +/// Implements hint: +/// +/// memory[ap] = to_felt_or_relocatable(segments.add_temp_segment()) +pub fn segments_add_temp( + vm: &mut VirtualMachine, + _exec_scopes: &mut ExecutionScopes, + _ids_data: &HashMap, + _ap_tracking: &ApTracking, + _constants: &HashMap, +) -> Result<(), HintError> { + let temp_segment = vm.add_temporary_segment(); + insert_value_into_ap(vm, temp_segment) +} + +/// Implements hint: +/// +/// memory[ap] = to_felt_or_relocatable(len(os_input.transactions)) +pub fn transactions_len( + vm: &mut VirtualMachine, + exec_scopes: &mut ExecutionScopes, + _ids_data: &HashMap, + _ap_tracking: &ApTracking, + _constants: &HashMap, +) -> Result<(), HintError> { + let os_input = exec_scopes.get::("os_input")?; + + insert_value_into_ap(vm, os_input.transactions.len()) +} + +/// Implements hint: +/// +/// vm_enter_scope({ +/// '__deprecated_class_hashes': __deprecated_class_hashes, +/// 'transactions': iter(os_input.transactions), +/// 'execution_helper': execution_helper, +/// 'deprecated_syscall_handler': deprecated_syscall_handler, +/// 'syscall_handler': syscall_handler, +/// '__dict_manager': __dict_manager, +/// }) +pub fn enter_syscall_scopes( + vm: &mut VirtualMachine, + exec_scopes: &mut ExecutionScopes, + _ids_data: &HashMap, + _ap_tracking: &ApTracking, + _constants: &HashMap, +) -> Result<(), HintError> { + Ok(()) +}