Skip to content

Commit 4f6b306

Browse files
committed
fix some comments, remove some unsed functions
1 parent d14fa37 commit 4f6b306

File tree

22 files changed

+107
-429
lines changed

22 files changed

+107
-429
lines changed

crates/lean_vm/src/core/constants.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//! VM constants and configuration
2-
31
/// Vector dimension for field operations
42
pub const DIMENSION: usize = 5;
53

crates/lean_vm/src/core/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//! Core VM abstractions and type definitions
2-
31
pub mod constants;
42
pub mod types;
53

crates/lean_vm/src/core/types.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//! Core type definitions for the VM
2-
31
use p3_koala_bear::{KoalaBear, QuinticExtensionFieldKB};
42

53
/// Base field type for VM operations
@@ -10,3 +8,6 @@ pub type EF = QuinticExtensionFieldKB;
108

119
/// Location in source code for debugging
1210
pub type LocationInSourceCode = usize;
11+
12+
/// String label for bytecode locations
13+
pub type Label = String;

crates/lean_vm/src/diagnostics/error.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
//! VM error types and execution results
2-
31
use crate::core::F;
42
use crate::execution::Memory;
53
use crate::witness::{
64
WitnessDotProduct, WitnessMultilinearEval, WitnessPoseidon16, WitnessPoseidon24,
75
};
86
use thiserror::Error;
97

10-
/// Errors that can occur during VM execution
118
#[derive(Debug, Clone, Error)]
129
pub enum RunnerError {
1310
#[error("Out of memory")]
@@ -35,10 +32,8 @@ pub enum RunnerError {
3532
MultilinearEvalPointNotPadded,
3633
}
3734

38-
/// Result type for VM operations
3935
pub type VMResult<T> = Result<T, RunnerError>;
4036

41-
/// Execution result containing outputs and execution data
4237
#[derive(Debug)]
4338
pub struct ExecutionResult {
4439
pub no_vec_runtime_memory: usize,
@@ -51,12 +46,3 @@ pub struct ExecutionResult {
5146
pub dot_products: Vec<WitnessDotProduct>,
5247
pub multilinear_evals: Vec<WitnessMultilinearEval>,
5348
}
54-
55-
impl ExecutionResult {
56-
/// Check if execution was successful
57-
///
58-
/// TODO: placeholder for now.
59-
pub fn is_success(&self) -> bool {
60-
true
61-
}
62-
}

crates/lean_vm/src/diagnostics/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//! Diagnostics, error handling, and debugging utilities
21
#![allow(unused_imports)]
32

43
pub mod error;

crates/lean_vm/src/execution/context.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
//! Execution context and state management
2-
31
use crate::core::LocationInSourceCode;
42
use std::collections::BTreeMap;
53

6-
/// Execution history for profiling and debugging
74
#[derive(Debug, Clone, Default)]
85
pub struct ExecutionHistory {
96
pub lines: Vec<LocationInSourceCode>,
@@ -33,7 +30,6 @@ impl ExecutionHistory {
3330
}
3431
}
3532

36-
/// VM execution context
3733
#[derive(Debug)]
3834
pub struct ExecutionContext<'a> {
3935
pub source_code: &'a str,

crates/lean_vm/src/execution/memory.rs

Lines changed: 0 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -55,43 +55,11 @@ impl Memory {
5555
Ok(())
5656
}
5757

58-
/// Reads a slice of memory values
59-
pub fn get_slice(&self, start: usize, len: usize) -> Result<Vec<F>, RunnerError> {
60-
(start..start + len).map(|i| self.get(i)).collect()
61-
}
62-
63-
/// Sets a slice of memory values
64-
pub fn set_slice(&mut self, start: usize, values: &[F]) -> Result<(), RunnerError> {
65-
for (i, &value) in values.iter().enumerate() {
66-
self.set(start + i, value)?;
67-
}
68-
Ok(())
69-
}
70-
7158
/// Gets the current size of allocated memory
7259
pub const fn size(&self) -> usize {
7360
self.0.len()
7461
}
7562

76-
/// Checks if a memory address is initialized
77-
pub fn is_initialized(&self, index: usize) -> bool {
78-
self.0.get(index).and_then(|x| x.as_ref()).is_some()
79-
}
80-
81-
/// Gets all initialized memory addresses and their values
82-
pub fn initialized_entries(&self) -> Vec<(usize, F)> {
83-
self.0
84-
.iter()
85-
.enumerate()
86-
.filter_map(|(i, opt)| opt.map(|v| (i, v)))
87-
.collect()
88-
}
89-
90-
/// Clears all memory
91-
pub fn clear(&mut self) {
92-
self.0.clear();
93-
}
94-
9563
/// Get a vector from vectorized memory
9664
pub fn get_vector(&self, index: usize) -> Result<[F; VECTOR_LEN], RunnerError> {
9765
Ok(self.get_vectorized_slice(index, 1)?.try_into().unwrap())
@@ -107,7 +75,6 @@ impl Memory {
10775
Ok(EF::from_basis_coefficients_slice(&coeffs).unwrap())
10876
}
10977

110-
/// Get a vectorized slice from memory
11178
pub fn get_vectorized_slice(&self, index: usize, len: usize) -> Result<Vec<F>, RunnerError> {
11279
let start = index * VECTOR_LEN;
11380
let total_len = len * VECTOR_LEN;
@@ -142,133 +109,8 @@ impl Memory {
142109
Ok(())
143110
}
144111

145-
/// Set a vectorized slice in memory
146-
pub fn set_vectorized_slice(&mut self, index: usize, value: &[F]) -> Result<(), RunnerError> {
147-
assert!(value.len().is_multiple_of(VECTOR_LEN));
148-
let start = index * VECTOR_LEN;
149-
value
150-
.iter()
151-
.enumerate()
152-
.try_for_each(|(i, &v)| self.set(start + i, v))
153-
}
154-
155112
/// Get a slice from memory for multilinear evaluation
156113
pub fn slice(&self, start: usize, len: usize) -> Result<Vec<F>, RunnerError> {
157114
(0..len).map(|i| self.get(start + i)).collect()
158115
}
159116
}
160-
161-
#[cfg(test)]
162-
mod tests {
163-
use super::*;
164-
165-
#[test]
166-
fn test_basic_memory_operations() {
167-
let mut memory = Memory::empty();
168-
169-
// Test setting and getting values
170-
memory.set(0, F::ONE).unwrap();
171-
memory.set(5, F::from_usize(42)).unwrap();
172-
173-
assert_eq!(memory.get(0).unwrap(), F::ONE);
174-
assert_eq!(memory.get(5).unwrap(), F::from_usize(42));
175-
176-
// Test undefined memory access
177-
assert!(matches!(memory.get(1), Err(RunnerError::UndefinedMemory)));
178-
}
179-
180-
#[test]
181-
fn test_memory_already_set_error() {
182-
let mut memory = Memory::empty();
183-
184-
memory.set(0, F::ONE).unwrap();
185-
// Setting same value should work
186-
memory.set(0, F::ONE).unwrap();
187-
188-
// Setting different value should fail
189-
assert!(matches!(
190-
memory.set(0, F::ZERO),
191-
Err(RunnerError::MemoryAlreadySet)
192-
));
193-
}
194-
195-
#[test]
196-
fn test_memory_slices() {
197-
let mut memory = Memory::empty();
198-
let values = vec![F::ONE, F::ZERO, F::from_usize(42), F::from_usize(100)];
199-
200-
memory.set_slice(10, &values).unwrap();
201-
let retrieved = memory.get_slice(10, 4).unwrap();
202-
203-
assert_eq!(retrieved, values);
204-
}
205-
206-
#[test]
207-
fn test_memory_initialization_and_utilities() {
208-
let public_data = vec![F::ONE, F::ZERO, F::from_usize(123)];
209-
let memory = Memory::new(public_data.clone());
210-
211-
// All public data should be initialized
212-
for (i, expected) in public_data.iter().enumerate() {
213-
assert!(memory.is_initialized(i));
214-
assert_eq!(memory.get(i).unwrap(), *expected);
215-
}
216-
217-
assert_eq!(memory.size(), 3);
218-
219-
let entries = memory.initialized_entries();
220-
assert_eq!(entries.len(), 3);
221-
assert_eq!(entries[0], (0, F::ONE));
222-
assert_eq!(entries[2], (2, F::from_usize(123)));
223-
}
224-
225-
#[test]
226-
fn test_vectorized_operations() {
227-
let mut memory = Memory::empty();
228-
let vector = [F::ONE; VECTOR_LEN];
229-
230-
memory.set_vector(0, vector).unwrap();
231-
let retrieved = memory.get_vector(0).unwrap();
232-
233-
assert_eq!(retrieved, vector);
234-
235-
// Test vectorized slice
236-
let slice_data = vec![F::from_usize(1); 2 * VECTOR_LEN];
237-
memory.set_vectorized_slice(1, &slice_data).unwrap();
238-
let retrieved_slice = memory.get_vectorized_slice(1, 2).unwrap();
239-
240-
assert_eq!(retrieved_slice, slice_data);
241-
}
242-
243-
#[test]
244-
fn test_extension_field_operations() {
245-
let mut memory = Memory::empty();
246-
247-
// Create a simple extension field element with proper dimension
248-
let mut coeffs = [F::ZERO; DIMENSION];
249-
coeffs[0] = F::ONE;
250-
let ef_value = EF::from_basis_coefficients_slice(&coeffs).unwrap();
251-
252-
memory.set_ef_element(0, ef_value).unwrap();
253-
let retrieved = memory.get_ef_element(0).unwrap();
254-
255-
assert_eq!(retrieved, ef_value);
256-
257-
// Test continuous slice of EF elements
258-
memory.set_ef_element(DIMENSION, ef_value).unwrap();
259-
let ef_slice = memory.get_continuous_slice_of_ef_elements(0, 2).unwrap();
260-
261-
assert_eq!(ef_slice.len(), 2);
262-
assert_eq!(ef_slice[0], ef_value);
263-
assert_eq!(ef_slice[1], ef_value);
264-
}
265-
266-
#[test]
267-
fn test_memory_clear() {
268-
let mut memory = Memory::new(vec![F::ONE, F::ZERO]);
269-
assert_eq!(memory.size(), 2);
270-
271-
memory.clear();
272-
assert_eq!(memory.size(), 0);
273-
}
274-
}

crates/lean_vm/src/execution/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ pub mod runner;
77
pub use context::*;
88
pub use memory::*;
99
pub use runner::*;
10+
11+
#[cfg(test)]
12+
mod tests;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
use crate::*;
2+
use p3_field::BasedVectorSpace;
3+
use p3_field::PrimeCharacteristicRing;
4+
5+
#[test]
6+
fn test_basic_memory_operations() {
7+
let mut memory = Memory::empty();
8+
9+
// Test setting and getting values
10+
memory.set(0, F::ONE).unwrap();
11+
memory.set(5, F::from_usize(42)).unwrap();
12+
13+
assert_eq!(memory.get(0).unwrap(), F::ONE);
14+
assert_eq!(memory.get(5).unwrap(), F::from_usize(42));
15+
16+
// Test undefined memory access
17+
assert!(matches!(memory.get(1), Err(RunnerError::UndefinedMemory)));
18+
}
19+
20+
#[test]
21+
fn test_memory_already_set_error() {
22+
let mut memory = Memory::empty();
23+
24+
memory.set(0, F::ONE).unwrap();
25+
// Setting same value should work
26+
memory.set(0, F::ONE).unwrap();
27+
28+
// Setting different value should fail
29+
assert!(matches!(
30+
memory.set(0, F::ZERO),
31+
Err(RunnerError::MemoryAlreadySet)
32+
));
33+
}
34+
35+
#[test]
36+
fn test_extension_field_operations() {
37+
let mut memory = Memory::empty();
38+
39+
// Create a simple extension field element with proper dimension
40+
let mut coeffs = [F::ZERO; DIMENSION];
41+
coeffs[0] = F::ONE;
42+
let ef_value = EF::from_basis_coefficients_slice(&coeffs).unwrap();
43+
44+
memory.set_ef_element(0, ef_value).unwrap();
45+
let retrieved = memory.get_ef_element(0).unwrap();
46+
47+
assert_eq!(retrieved, ef_value);
48+
49+
// Test continuous slice of EF elements
50+
memory.set_ef_element(DIMENSION, ef_value).unwrap();
51+
let ef_slice = memory.get_continuous_slice_of_ef_elements(0, 2).unwrap();
52+
53+
assert_eq!(ef_slice.len(), 2);
54+
assert_eq!(ef_slice[0], ef_value);
55+
assert_eq!(ef_slice[1], ef_value);
56+
}

crates/lean_vm/src/isa/bytecode.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,6 @@ pub struct Bytecode {
1515
pub ending_pc: usize,
1616
}
1717

18-
impl Bytecode {
19-
/// Create new bytecode with the given instructions
20-
pub fn new(instructions: Vec<Instruction>) -> Self {
21-
Self {
22-
ending_pc: instructions.len().saturating_sub(1),
23-
instructions,
24-
hints: BTreeMap::new(),
25-
starting_frame_memory: 0,
26-
}
27-
}
28-
29-
/// Add a hint at the specified program counter
30-
pub fn add_hint(&mut self, pc: usize, hint: Hint) {
31-
self.hints.entry(pc).or_default().push(hint);
32-
}
33-
34-
/// Get hints for a specific program counter
35-
pub fn get_hints(&self, pc: usize) -> &[Hint] {
36-
self.hints.get(&pc).map_or(&[], |v| v.as_slice())
37-
}
38-
39-
/// Get the number of instructions
40-
pub const fn len(&self) -> usize {
41-
self.instructions.len()
42-
}
43-
44-
/// Check if bytecode is empty
45-
pub const fn is_empty(&self) -> bool {
46-
self.instructions.is_empty()
47-
}
48-
}
49-
5018
impl Display for Bytecode {
5119
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
5220
for (pc, instruction) in self.instructions.iter().enumerate() {

0 commit comments

Comments
 (0)