|
1 | | -use p3_field::{BasedVectorSpace, Field, PrimeCharacteristicRing, PrimeField64}; |
| 1 | +use p3_field::{BasedVectorSpace, Field, PrimeField64}; |
2 | 2 | use p3_symmetric::Permutation; |
3 | 3 |
|
4 | 4 | use crate::{ |
5 | 5 | bytecode::{ |
6 | | - hint::Hint, |
7 | 6 | instruction::Instruction, |
8 | 7 | operand::{MemOrConstant, MemOrFp, MemOrFpOrConstant}, |
9 | 8 | operation::Operation, |
@@ -32,88 +31,6 @@ impl<PERM16, PERM24> VirtualMachine<PERM16, PERM24> { |
32 | 31 | } |
33 | 32 | } |
34 | 33 |
|
35 | | - /// Executes a single hint emitted by the compiler during bytecode interpretation. |
36 | | - /// |
37 | | - /// Hints are runtime-only helper directives used for: |
38 | | - /// - Allocating memory dynamically (`RequestMemory`) |
39 | | - /// - Decomposing a field element into bits (`DecomposeBits`) |
40 | | - /// - (Eventually) printing debug information (`Print`) |
41 | | - /// |
42 | | - /// These are not part of the trace or AIR and are only used by the prover for state setup or inspection. |
43 | | - /// The verifier does not need to observe these effects. |
44 | | - fn execute_hint(&mut self, hint: &Hint) -> Result<(), VirtualMachineError> { |
45 | | - match hint { |
46 | | - Hint::RequestMemory { |
47 | | - offset, |
48 | | - size, |
49 | | - vectorized, |
50 | | - } => { |
51 | | - // Resolve the `size` operand to a concrete field element. |
52 | | - let size: F = self |
53 | | - .run_context |
54 | | - .value_from_mem_or_constant(size, &self.memory_manager)? |
55 | | - .try_into()?; |
56 | | - // Convert the field element to a canonical `usize`. |
57 | | - let size = size.as_canonical_u64() as usize; |
58 | | - |
59 | | - // Compute the address where the allocated pointer will be stored: `fp + offset`. |
60 | | - let addr = (self.run_context.fp + *offset)?; |
61 | | - |
62 | | - if *vectorized { |
63 | | - // Store the current vectorized allocation pointer (`ap_vectorized`) at `addr`. |
64 | | - self.memory_manager |
65 | | - .memory |
66 | | - .insert(addr, F::from_usize(self.run_context.ap_vectorized))?; |
67 | | - |
68 | | - // Increase the vectorized allocation pointer by `size` (number of vectors). |
69 | | - self.run_context.ap_vectorized += size; |
70 | | - } else { |
71 | | - // Store the current scalar allocation pointer (`ap`) at `addr`. |
72 | | - self.memory_manager |
73 | | - .memory |
74 | | - .insert(addr, F::from_usize(self.run_context.ap))?; |
75 | | - |
76 | | - // Increase the scalar allocation pointer by `size` (number of scalars). |
77 | | - self.run_context.ap += size; |
78 | | - } |
79 | | - } |
80 | | - Hint::DecomposeBits { |
81 | | - res_offset, |
82 | | - to_decompose, |
83 | | - } => { |
84 | | - // Resolve the operand to be decomposed into a concrete field element. |
85 | | - let to_decompose: F = self |
86 | | - .run_context |
87 | | - .value_from_mem_or_constant(to_decompose, &self.memory_manager)? |
88 | | - .try_into()?; |
89 | | - |
90 | | - // Convert the field element to a native `u64` for bit-level manipulation. |
91 | | - let to_decompose = to_decompose.as_canonical_u64(); |
92 | | - |
93 | | - // For each bit position (up to the number of bits supported by the field): |
94 | | - for i in 0..F::bits() { |
95 | | - // - Extract the i-th bit from the value using bit masking. |
96 | | - let bit = if to_decompose & (1 << i) != 0 { |
97 | | - F::ONE |
98 | | - } else { |
99 | | - F::ZERO |
100 | | - }; |
101 | | - |
102 | | - // - Compute the address at `fp + res_offset + i`. |
103 | | - // - Write the extracted bit to that memory location. |
104 | | - self.memory_manager |
105 | | - .memory |
106 | | - .insert(((self.run_context.fp + *res_offset)? + i)?, bit)?; |
107 | | - } |
108 | | - } |
109 | | - Hint::Print { .. } => { |
110 | | - // TODO: implement |
111 | | - // This is for debugging purposes only so this is not urgent for now. |
112 | | - } |
113 | | - } |
114 | | - Ok(()) |
115 | | - } |
116 | | - |
117 | 34 | /// Advances the program counter (`pc`) to the next instruction. |
118 | 35 | /// |
119 | 36 | /// This function embodies the control flow logic of the zkVM. For most instructions, |
|
0 commit comments