Skip to content

Commit

Permalink
syscall prep
Browse files Browse the repository at this point in the history
  • Loading branch information
drspacemn committed Oct 19, 2023
1 parent b190949 commit cc6ebe1
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/hints/hints_raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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})";
72 changes: 72 additions & 0 deletions src/hints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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<String, HintReference>,
_ap_tracking: &ApTracking,
_constants: &HashMap<String, Felt252>,
) -> 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<String, HintReference>,
_ap_tracking: &ApTracking,
_constants: &HashMap<String, Felt252>,
) -> 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<String, HintReference>,
_ap_tracking: &ApTracking,
_constants: &HashMap<String, Felt252>,
) -> Result<(), HintError> {
let os_input = exec_scopes.get::<StarknetOsInput>("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<String, HintReference>,
_ap_tracking: &ApTracking,
_constants: &HashMap<String, Felt252>,
) -> Result<(), HintError> {
Ok(())
}

0 comments on commit cc6ebe1

Please sign in to comment.