Skip to content

Commit 7ac616e

Browse files
committed
vm: better building of the execution trace
1 parent b1a658f commit 7ac616e

File tree

9 files changed

+303
-241
lines changed

9 files changed

+303
-241
lines changed

crates/zk_vm/src/dot_product_air.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use p3_field::PrimeCharacteristicRing;
55
use p3_matrix::Matrix;
66
use vm::EF;
77

8-
use crate::execution_trace::WitnessDotProduct;
8+
use crate::witness::dot_product::WitnessDotProduct;
99

1010
/*
1111
| StartFlag | Len | IndexA | IndexB | IndexRes | ValueA | ValueB | Res | Computation |

crates/zk_vm/src/execution_trace.rs

Lines changed: 205 additions & 237 deletions
Large diffs are not rendered by default.

crates/zk_vm/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ mod instruction_encoder;
1010
mod poseidon_tables;
1111
pub mod prove_execution;
1212
pub mod verify_execution;
13+
pub mod witness;
1314

1415
#[cfg(test)]
1516
pub mod recursion;

crates/zk_vm/src/poseidon_tables.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use utils::{
44
};
55
use vm::F;
66

7-
use crate::execution_trace::{WitnessPoseidon16, WitnessPoseidon24};
7+
use crate::witness::poseidon::{WitnessPoseidon16, WitnessPoseidon24};
88

99
pub fn build_poseidon_columns(
1010
poseidons_16: &[WitnessPoseidon16],

crates/zk_vm/src/prove_execution.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use crate::{
3535
},
3636
dot_product_air::{DOT_PRODUCT_AIR_COLUMN_GROUPS, DotProductAir, build_dot_product_columns},
3737
exec_column_groups,
38-
execution_trace::{ExecutionTrace, get_execution_trace},
38+
execution_trace::ExecutionTrace,
3939
poseidon_tables::{all_poseidon_16_indexes, all_poseidon_24_indexes, build_poseidon_columns},
4040
};
4141

@@ -57,7 +57,7 @@ pub fn prove_execution(
5757
memory,
5858
} = info_span!("Witness generation").in_scope(|| {
5959
let execution_result = bytecode.execute(public_input, private_input);
60-
get_execution_trace(bytecode, &execution_result)
60+
ExecutionTrace::new(bytecode, &execution_result)
6161
});
6262

6363
let public_memory = &memory[..public_memory_size];
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use vm::EF;
2+
3+
/// Holds the high-level witness data for a single dot product precompile execution.
4+
#[derive(Debug)]
5+
pub struct WitnessDotProduct {
6+
/// The CPU cycle at which the dot product operation is initiated.
7+
pub cycle: usize,
8+
/// The starting memory address (vectorized pointer) of the first input slice.
9+
pub addr_0: usize,
10+
/// The starting memory address (vectorized pointer) of the second input slice.
11+
pub addr_1: usize,
12+
/// The memory address (vectorized pointer) where the final result is stored.
13+
pub addr_res: usize,
14+
/// The number of elements in each input slice.
15+
pub len: usize,
16+
/// The actual data values of the first input slice.
17+
pub slice_0: Vec<EF>,
18+
/// The actual data values of the second input slice.
19+
pub slice_1: Vec<EF>,
20+
/// The final computed result of the dot product.
21+
pub res: EF,
22+
}

crates/zk_vm/src/witness/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use dot_product::WitnessDotProduct;
2+
use multilinear_eval::WitnessMultilinearEval;
3+
use poseidon::{WitnessPoseidon16, WitnessPoseidon24};
4+
5+
pub mod dot_product;
6+
pub mod multilinear_eval;
7+
pub mod poseidon;
8+
9+
/// An enum to encapsulate any possible precompile witness.
10+
#[derive(Debug)]
11+
pub enum Witness {
12+
Poseidon16(WitnessPoseidon16),
13+
Poseidon24(WitnessPoseidon24),
14+
DotProduct(WitnessDotProduct),
15+
MultilinearEval(WitnessMultilinearEval),
16+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use vm::EF;
2+
3+
/// Holds the high-level witness data for a single multilinear evaluation precompile.
4+
#[derive(Debug)]
5+
pub struct WitnessMultilinearEval {
6+
/// The CPU cycle at which this operation is initiated.
7+
pub cycle: usize,
8+
/// The memory address of the polynomial's coefficients.
9+
pub addr_coeffs: usize,
10+
/// The memory address of the evaluation point's coordinates.
11+
pub addr_point: usize,
12+
/// The memory address where the final result is stored.
13+
pub addr_res: usize,
14+
/// The number of variables in the multilinear polynomial.
15+
pub n_vars: usize,
16+
/// The coordinates of the evaluation point.
17+
pub point: Vec<EF>,
18+
/// The final computed result of the evaluation.
19+
pub res: EF,
20+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use vm::F;
2+
3+
/// Holds the high-level witness data for a single Poseidon2 permutation over 16 elements.
4+
#[derive(Debug)]
5+
pub struct WitnessPoseidon16 {
6+
/// The CPU cycle at which this operation is initiated, if applicable.
7+
pub cycle: Option<usize>,
8+
/// The memory address (vectorized pointer, of size 1) of the first 8-element input vector.
9+
pub addr_input_a: usize,
10+
/// The memory address (vectorized pointer, of size 1) of the second 8-element input vector.
11+
pub addr_input_b: usize,
12+
/// The memory address (vectorized pointer, of size 2) where the two 8-element output vectors are stored.
13+
pub addr_output: usize,
14+
/// The full 16-element input state for the permutation.
15+
pub input: [F; 16],
16+
/// The full 16-element output state resulting from the permutation.
17+
pub output: [F; 16],
18+
}
19+
20+
/// Holds the high-level witness data for a single Poseidon2 permutation over 24 elements.
21+
#[derive(Debug)]
22+
pub struct WitnessPoseidon24 {
23+
/// The CPU cycle at which this operation is initiated, if applicable.
24+
pub cycle: Option<usize>,
25+
/// The memory address (vectorized pointer, of size 2) of the first two 8-element input vectors.
26+
pub addr_input_a: usize,
27+
/// The memory address (vectorized pointer, of size 1) of the third 8-element input vector.
28+
pub addr_input_b: usize,
29+
/// The memory address (vectorized pointer, of size 1) where the relevant 8-element output vector is stored.
30+
pub addr_output: usize,
31+
/// The full 24-element input state for the permutation.
32+
pub input: [F; 24],
33+
/// The last 8 elements of the 24-element output state from the permutation.
34+
pub output: [F; 8],
35+
}

0 commit comments

Comments
 (0)