@@ -11,123 +11,6 @@ use p3_symmetric::Permutation;
1111use rayon:: prelude:: * ;
1212use 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 ) ]
13215pub 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
14528pub 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,
0 commit comments