|
| 1 | +use crate::hint_processor::hint_processor_definition::HintReference; |
| 2 | +use crate::stdlib::collections::HashMap; |
| 3 | +use crate::types::relocatable::Relocatable; |
| 4 | +use crate::Felt252; |
| 5 | +use crate::{ |
| 6 | + serde::deserialize_program::ApTracking, |
| 7 | + types::exec_scope::ExecutionScopes, |
| 8 | + vm::{errors::hint_errors::HintError, vm_core::VirtualMachine}, |
| 9 | +}; |
| 10 | +use num_traits::ToPrimitive; |
| 11 | + |
| 12 | +use super::hint_utils::{get_integer_from_var_name, insert_value_from_var_name}; |
| 13 | + |
| 14 | +pub const GET_SIMULATED_BUILTIN_BASE: &str = |
| 15 | + "ids.new_ptr = get_simulated_builtin_base(ids.builtin_idx)"; |
| 16 | + |
| 17 | +/// Obtains the simulated builtin runner base, at the given index. The simulated |
| 18 | +/// builtin runner must be initialized before the execution. |
| 19 | +/// |
| 20 | +/// This hint is not defined in the original VM, and its declared for testing |
| 21 | +/// purposes only. |
| 22 | +pub fn get_simulated_builtin_base( |
| 23 | + vm: &mut VirtualMachine, |
| 24 | + _exec_scopes: &mut ExecutionScopes, |
| 25 | + ids_data: &HashMap<String, HintReference>, |
| 26 | + ap_tracking: &ApTracking, |
| 27 | + _constants: &HashMap<String, Felt252>, |
| 28 | +) -> Result<(), HintError> { |
| 29 | + // Obtain the simulated builtin runner from the builtin_idx variable. |
| 30 | + let builtin_idx = get_integer_from_var_name("builtin_idx", vm, ids_data, ap_tracking)? |
| 31 | + .to_usize() |
| 32 | + .ok_or(HintError::BigintToUsizeFail)?; |
| 33 | + let builtin_runner = &vm.simulated_builtin_runners[builtin_idx]; |
| 34 | + |
| 35 | + // Set new_ptr with the value of the builtin runner base. |
| 36 | + insert_value_from_var_name( |
| 37 | + "new_ptr", |
| 38 | + Relocatable { |
| 39 | + segment_index: builtin_runner.base() as isize, |
| 40 | + offset: 0, |
| 41 | + }, |
| 42 | + vm, |
| 43 | + ids_data, |
| 44 | + ap_tracking, |
| 45 | + ) |
| 46 | +} |
0 commit comments