@@ -3,7 +3,7 @@ use prover::{
3
3
eth_types:: H256 ,
4
4
proof:: dump_as_json,
5
5
utils:: { chunk_trace_to_witness_block, init_env_and_log, read_env_var} ,
6
- zkevm, BatchHash , BatchHeader , BatchProvingTask , ChunkInfo , ChunkProvingTask ,
6
+ zkevm, BatchHash , BatchHeader , BatchProvingTask , ChunkInfo , ChunkProvingTask , MAX_AGG_SNARKS ,
7
7
} ;
8
8
use std:: { env, fs, path:: Path } ;
9
9
@@ -32,16 +32,17 @@ fn test_e2e_prove_verify() {
32
32
let chunks2 = load_batch ( "./tests/extra_traces/batch2" ) . unwrap ( ) ;
33
33
34
34
let mut batch_prover_pending = None ;
35
- let mut batch_header = None ;
35
+ let mut opt_batch_header = None ;
36
36
let mut batch_proofs = Vec :: new ( ) ;
37
37
38
- for ( i, chunk) in [
39
- chunks1,
40
- chunks2,
41
- ] . into_iter ( ) . enumerate ( ) {
42
-
43
- let batch = gen_batch_proving_task ( & output_dir, & chunk, batch_header) ;
44
- dump_as_json ( & output_dir, format ! ( "batch_prove_{}" , i+1 ) . as_str ( ) , & batch) . unwrap ( ) ;
38
+ for ( i, chunk) in [ chunks1, chunks2] . into_iter ( ) . enumerate ( ) {
39
+ let ( batch, batch_header) = gen_batch_proving_task ( & output_dir, & chunk, opt_batch_header) ;
40
+ dump_as_json (
41
+ & output_dir,
42
+ format ! ( "batch_prove_{}" , i + 1 ) . as_str ( ) ,
43
+ & batch,
44
+ )
45
+ . unwrap ( ) ;
45
46
if i == 0 {
46
47
dump_chunk_protocol ( & batch, & output_dir) ;
47
48
batch_prover_pending. replace ( new_batch_prover ( & output_dir) ) ;
@@ -50,26 +51,30 @@ fn test_e2e_prove_verify() {
50
51
51
52
let batch_proof = prove_and_verify_batch ( & output_dir, batch_prover, batch) ;
52
53
let proof_path = Path :: new ( & output_dir) . join ( "full_proof_batch_agg.json" ) ;
53
- let proof_path_to = Path :: new ( & output_dir) . join ( format ! ( "full_proof_batch_agg_{}.json" , i+1 ) . as_str ( ) ) ;
54
+ let proof_path_to =
55
+ Path :: new ( & output_dir) . join ( format ! ( "full_proof_batch_agg_{}.json" , i + 1 ) . as_str ( ) ) ;
54
56
fs:: rename ( proof_path, proof_path_to) . unwrap ( ) ;
55
57
56
- log:: info!( "batch proof {}, prev hash {:x?}, current {:x?}" , i, batch_proof. batch_header. parent_batch_hash, batch_proof. batch_header. batch_hash( ) ) ;
57
- batch_header. replace ( batch_proof. batch_header . clone ( ) ) ;
58
+ log:: info!(
59
+ "batch proof {}, prev hash {:x?}, current {:x?}" ,
60
+ i,
61
+ batch_header. parent_batch_hash,
62
+ batch_proof. batch_hash,
63
+ ) ;
64
+ opt_batch_header. replace ( batch_header) ;
58
65
batch_proofs. push ( batch_proof) ;
59
66
}
60
67
61
68
let batch_prover = batch_prover_pending. as_mut ( ) . unwrap ( ) ;
62
- let bundle = prover:: BundleProvingTask {
63
- batch_proofs,
64
- } ;
69
+ let bundle = prover:: BundleProvingTask { batch_proofs } ;
65
70
prove_and_verify_bundle ( & output_dir, batch_prover, bundle) ;
66
71
}
67
72
68
73
fn gen_batch_proving_task (
69
74
output_dir : & str ,
70
75
chunk_dirs : & [ String ] ,
71
- batch_header : Option < BatchHeader > ,
72
- ) -> BatchProvingTask {
76
+ opt_batch_header : Option < BatchHeader < MAX_AGG_SNARKS > > ,
77
+ ) -> ( BatchProvingTask , BatchHeader < MAX_AGG_SNARKS > ) {
73
78
let chunks: Vec < _ > = chunk_dirs
74
79
. iter ( )
75
80
. map ( |chunk_dir| load_chunk ( chunk_dir) . 1 )
@@ -109,22 +114,34 @@ fn gen_batch_proving_task(
109
114
0xab , 0xac , 0xad , 0xae , 0xaf , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
110
115
0 , 0 , 0 , 0 , 0 , 0 , 0 ,
111
116
] ) ;
112
- let batch_header = BatchHeader {
113
- version : batch_header . map_or ( 4 , |header| header. version ) ,
114
- batch_index : batch_header . map_or ( 123 , |header| header. batch_index + 1 ) ,
117
+ let batch_header = BatchHeader :: construct_from_chunks (
118
+ opt_batch_header . map_or ( 4 , |header| header. version ) ,
119
+ opt_batch_header . map_or ( 123 , |header| header. batch_index + 1 ) ,
115
120
l1_message_popped,
116
- total_l1_message_popped : batch_header . map_or ( l1_message_popped, |header| {
121
+ opt_batch_header . map_or ( l1_message_popped, |header| {
117
122
header. total_l1_message_popped + l1_message_popped
118
123
} ) ,
119
- parent_batch_hash : batch_header
120
- . map_or ( dummy_parent_batch_hash, |header| header. batch_hash ( ) ) ,
124
+ opt_batch_header. map_or ( dummy_parent_batch_hash, |header| header. batch_hash ( ) ) ,
121
125
last_block_timestamp,
122
- ..Default :: default ( ) // these will be populated later.
123
- } ;
124
- BatchProvingTask {
125
- chunk_proofs,
126
+ & chunk_proofs
127
+ . clone ( )
128
+ . into_iter ( )
129
+ . map ( |cp| cp. chunk_info )
130
+ . collect :: < Vec < _ > > ( ) ,
131
+ ) ;
132
+
133
+ (
134
+ BatchProvingTask {
135
+ version : batch_header. version ,
136
+ batch_index : batch_header. batch_index ,
137
+ l1_message_popped : batch_header. l1_message_popped ,
138
+ total_l1_message_popped : batch_header. total_l1_message_popped ,
139
+ parent_batch_hash : batch_header. parent_batch_hash ,
140
+ last_block_timestamp : batch_header. last_block_timestamp ,
141
+ chunk_proofs,
142
+ } ,
126
143
batch_header,
127
- }
144
+ )
128
145
}
129
146
130
147
fn log_batch_pi ( trace_paths : & [ String ] ) {
0 commit comments