Skip to content

Commit aa19c0f

Browse files
committed
remove duplicated structs
1 parent 5949c4a commit aa19c0f

File tree

10 files changed

+504
-590
lines changed

10 files changed

+504
-590
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/lean_compiler/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn compile_program(program: &str) -> (Bytecode, BTreeMap<usize, String>) {
2424
let intermediate_bytecode = compile_to_intermediate_bytecode(simple_program).unwrap();
2525
// println!("Intermediate Bytecode:\n\n{}", intermediate_bytecode.to_string());
2626
let compiled = compile_to_low_level_bytecode(intermediate_bytecode).unwrap();
27-
println!("Compiled Program:\n\n{}", compiled.to_string());
27+
println!("Compiled Program:\n\n{}", compiled);
2828
(compiled, function_locations)
2929
}
3030

crates/lean_prover/src/prove_execution.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub fn prove_execution(
4646
poseidons_16, // padded with empty poseidons
4747
poseidons_24, // padded with empty poseidons
4848
dot_products,
49-
vm_multilinear_evals,
49+
multilinear_evals: vm_multilinear_evals,
5050
public_memory_size,
5151
non_zero_memory_size,
5252
memory, // padded with zeros to next power of two
@@ -59,7 +59,7 @@ pub fn prove_execution(
5959
function_locations,
6060
vm_profiler,
6161
);
62-
get_execution_trace(bytecode, &execution_result)
62+
get_execution_trace(bytecode, execution_result)
6363
});
6464

6565
let public_memory = &memory[..public_memory_size];

crates/lean_prover/vm_air/src/dot_product_air.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use std::borrow::Borrow;
22

3-
use lean_vm::{DIMENSION, EF};
3+
use lean_vm::{DIMENSION, EF, WitnessDotProduct};
44
use p3_air::{Air, AirBuilder, BaseAir};
55
use p3_field::PrimeCharacteristicRing;
66
use p3_matrix::Matrix;
7-
use witness_generation::WitnessDotProduct;
87

98
/*
109
(DIMENSION = 5)

crates/lean_prover/witness_generation/src/execution_trace.rs

Lines changed: 13 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -11,123 +11,6 @@ use p3_symmetric::Permutation;
1111
use rayon::prelude::*;
1212
use utils::{ToUsize, get_poseidon16, get_poseidon24};
1313

14-
#[derive(Debug)]
15-
pub struct WitnessDotProduct {
16-
pub cycle: usize,
17-
pub addr_0: usize, // normal pointer
18-
pub addr_1: usize, // normal pointer
19-
pub addr_res: usize, // normal pointer
20-
pub len: usize,
21-
pub slice_0: Vec<EF>,
22-
pub slice_1: Vec<EF>,
23-
pub res: EF,
24-
}
25-
impl WitnessDotProduct {
26-
pub fn addresses_and_len_field_repr(&self) -> [F; 4] {
27-
[
28-
F::from_usize(self.addr_0),
29-
F::from_usize(self.addr_1),
30-
F::from_usize(self.addr_res),
31-
F::from_usize(self.len),
32-
]
33-
}
34-
}
35-
36-
#[derive(Debug)]
37-
pub struct RowMultilinearEval {
38-
pub addr_coeffs: usize,
39-
pub addr_point: usize,
40-
pub addr_res: usize,
41-
pub point: Vec<EF>,
42-
pub res: EF,
43-
}
44-
45-
impl RowMultilinearEval {
46-
pub fn n_vars(&self) -> usize {
47-
self.point.len()
48-
}
49-
50-
pub fn addresses_and_n_vars_field_repr(&self) -> [F; 4] {
51-
[
52-
F::from_usize(self.addr_coeffs),
53-
F::from_usize(self.addr_point),
54-
F::from_usize(self.addr_res),
55-
F::from_usize(self.n_vars()),
56-
]
57-
}
58-
}
59-
60-
#[derive(Debug, derive_more::Deref)]
61-
pub struct WitnessMultilinearEval {
62-
pub cycle: usize,
63-
#[deref]
64-
pub inner: RowMultilinearEval,
65-
}
66-
67-
#[derive(Debug)]
68-
pub struct WitnessPoseidon16 {
69-
pub cycle: Option<usize>,
70-
pub addr_input_a: usize, // vectorized pointer (of size 1)
71-
pub addr_input_b: usize, // vectorized pointer (of size 1)
72-
pub addr_output: usize, // vectorized pointer (of size 2)
73-
pub input: [F; 16],
74-
pub output: [F; 16],
75-
}
76-
77-
impl WitnessPoseidon16 {
78-
pub fn poseidon_of_zero() -> Self {
79-
Self {
80-
cycle: None,
81-
addr_input_a: ZERO_VEC_PTR,
82-
addr_input_b: ZERO_VEC_PTR,
83-
addr_output: POSEIDON_16_NULL_HASH_PTR,
84-
input: [F::ZERO; 16],
85-
output: get_poseidon16().permute([F::ZERO; 16]),
86-
}
87-
}
88-
89-
pub fn addresses_field_repr(&self) -> [F; 3] {
90-
[
91-
F::from_usize(self.addr_input_a),
92-
F::from_usize(self.addr_input_b),
93-
F::from_usize(self.addr_output),
94-
]
95-
}
96-
}
97-
98-
#[derive(Debug)]
99-
pub struct WitnessPoseidon24 {
100-
pub cycle: Option<usize>,
101-
pub addr_input_a: usize, // vectorized pointer (of size 2)
102-
pub addr_input_b: usize, // vectorized pointer (of size 1)
103-
pub addr_output: usize, // vectorized pointer (of size 1)
104-
pub input: [F; 24],
105-
pub output: [F; 8], // last 8 elements of the output
106-
}
107-
108-
impl WitnessPoseidon24 {
109-
pub fn poseidon_of_zero() -> Self {
110-
Self {
111-
cycle: None,
112-
addr_input_a: ZERO_VEC_PTR,
113-
addr_input_b: ZERO_VEC_PTR,
114-
addr_output: POSEIDON_24_NULL_HASH_PTR,
115-
input: [F::ZERO; 24],
116-
output: get_poseidon24().permute([F::ZERO; 24])[16..24]
117-
.try_into()
118-
.unwrap(),
119-
}
120-
}
121-
122-
pub fn addresses_field_repr(&self) -> [F; 3] {
123-
[
124-
F::from_usize(self.addr_input_a),
125-
F::from_usize(self.addr_input_b),
126-
F::from_usize(self.addr_output),
127-
]
128-
}
129-
}
130-
13114
#[derive(Debug)]
13215
pub struct ExecutionTrace {
13316
pub full_trace: Vec<Vec<F>>,
@@ -136,15 +19,15 @@ pub struct ExecutionTrace {
13619
pub poseidons_16: Vec<WitnessPoseidon16>, // padded with empty poseidons
13720
pub poseidons_24: Vec<WitnessPoseidon24>, // padded with empty poseidons
13821
pub dot_products: Vec<WitnessDotProduct>,
139-
pub vm_multilinear_evals: Vec<WitnessMultilinearEval>,
22+
pub multilinear_evals: Vec<WitnessMultilinearEval>,
14023
pub public_memory_size: usize,
14124
pub non_zero_memory_size: usize,
14225
pub memory: Vec<F>, // of length a multiple of public_memory_size
14326
}
14427

14528
pub fn get_execution_trace(
14629
bytecode: &Bytecode,
147-
execution_result: &ExecutionResult,
30+
execution_result: ExecutionResult,
14831
) -> ExecutionTrace {
14932
assert_eq!(execution_result.pcs.len(), execution_result.fps.len());
15033
let n_cycles = execution_result.pcs.len();
@@ -153,10 +36,6 @@ pub fn get_execution_trace(
15336
let mut trace = (0..N_INSTRUCTION_COLUMNS + N_EXEC_COLUMNS)
15437
.map(|_| F::zero_vec(1 << log_n_cycles_rounded_up))
15538
.collect::<Vec<Vec<F>>>();
156-
let mut poseidons_16 = Vec::new();
157-
let mut poseidons_24 = Vec::new();
158-
let mut dot_products = Vec::new();
159-
let mut vm_multilinear_evals = Vec::new();
16039

16140
for (cycle, (&pc, &fp)) in execution_result
16241
.pcs
@@ -223,60 +102,22 @@ pub fn get_execution_trace(
223102
.collect::<Vec<F>>();
224103
memory_padded.resize(memory.0.len().next_power_of_two(), F::ZERO);
225104

226-
// Build witnesses from VM-collected events
227-
for e in &execution_result.vm_poseidon16_events {
228-
poseidons_16.push(WitnessPoseidon16 {
229-
cycle: Some(e.cycle),
230-
addr_input_a: e.addr_input_a,
231-
addr_input_b: e.addr_input_b,
232-
addr_output: e.addr_output,
233-
input: e.input,
234-
output: e.output,
235-
});
236-
}
237-
for e in &execution_result.vm_poseidon24_events {
238-
poseidons_24.push(WitnessPoseidon24 {
239-
cycle: Some(e.cycle),
240-
addr_input_a: e.addr_input_a,
241-
addr_input_b: e.addr_input_b,
242-
addr_output: e.addr_output,
243-
input: e.input,
244-
output: e.output,
245-
});
246-
}
247-
for e in &execution_result.vm_dot_product_events {
248-
dot_products.push(WitnessDotProduct {
249-
cycle: e.cycle,
250-
addr_0: e.addr_0,
251-
addr_1: e.addr_1,
252-
addr_res: e.addr_res,
253-
len: e.len,
254-
slice_0: e.slice_0.clone(),
255-
slice_1: e.slice_1.clone(),
256-
res: e.res,
257-
});
258-
}
259-
for e in &execution_result.vm_multilinear_eval_events {
260-
vm_multilinear_evals.push(WitnessMultilinearEval {
261-
cycle: e.cycle,
262-
inner: RowMultilinearEval {
263-
addr_coeffs: e.addr_coeffs,
264-
addr_point: e.addr_point,
265-
addr_res: e.addr_res,
266-
point: e.point.clone(),
267-
res: e.res,
268-
},
269-
});
270-
}
271-
272-
let n_poseidons_16 = poseidons_16.len();
273-
let n_poseidons_24 = poseidons_24.len();
105+
let n_poseidons_16 = execution_result.poseidons_16.len();
106+
let n_poseidons_24 = execution_result.poseidons_24.len();
274107

275108
let empty_poseidon16_output = get_poseidon16().permute([F::ZERO; 16]);
276109
let empty_poseidon24_output = get_poseidon24().permute([F::ZERO; 24])[16..24]
277110
.try_into()
278111
.unwrap();
279112

113+
let ExecutionResult {
114+
mut poseidons_16,
115+
mut poseidons_24,
116+
dot_products,
117+
multilinear_evals,
118+
..
119+
} = execution_result;
120+
280121
poseidons_16.extend(
281122
(0..n_poseidons_16.next_power_of_two() - n_poseidons_16).map(|_| WitnessPoseidon16 {
282123
cycle: None,
@@ -305,7 +146,7 @@ pub fn get_execution_trace(
305146
poseidons_16,
306147
poseidons_24,
307148
dot_products,
308-
vm_multilinear_evals,
149+
multilinear_evals,
309150
public_memory_size: execution_result.public_memory_size,
310151
non_zero_memory_size: memory.0.len(),
311152
memory: memory_padded,

crates/lean_prover/witness_generation/src/poseidon_tables.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
use lean_vm::F;
1+
use lean_vm::{F, WitnessPoseidon16, WitnessPoseidon24};
22
use p3_field::PrimeCharacteristicRing;
33
use rayon::prelude::*;
44
use utils::{
55
generate_trace_poseidon_16, generate_trace_poseidon_24, padd_with_zero_to_next_power_of_two,
66
};
77

8-
use crate::{WitnessPoseidon16, WitnessPoseidon24};
9-
108
pub fn build_poseidon_columns(
119
poseidons_16: &[WitnessPoseidon16],
1210
poseidons_24: &[WitnessPoseidon24],

crates/lean_vm/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ p3-poseidon2-air.workspace = true
3030
lookup.workspace = true
3131
sumcheck.workspace = true
3232
thiserror.workspace = true
33+
derive_more.workspace = true

0 commit comments

Comments
 (0)