Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

Commit 5cad070

Browse files
roynalnarutolispc
andauthored
batch header refactor (#328)
* update e2e tests based on prover updates * update dep and proof outputs (test data) --------- Co-authored-by: Zhuo Zhang <[email protected]>
1 parent af1437c commit 5cad070

7 files changed

+65
-46
lines changed

Cargo.lock

+10-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration/tests/batch_tests.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,13 @@ fn test_batches_with_each_chunk_num_prove_verify() {
3030
output_dir.push(format!("batch_{}", len));
3131
fs::create_dir_all(&output_dir).unwrap();
3232
let batch = BatchProvingTask {
33+
version: batch.version,
34+
l1_message_popped: batch.l1_message_popped,
35+
total_l1_message_popped: batch.total_l1_message_popped,
36+
last_block_timestamp: batch.last_block_timestamp,
37+
batch_index: batch.batch_index,
38+
parent_batch_hash: batch.parent_batch_hash,
3339
chunk_proofs: batch.chunk_proofs[..len].to_vec(),
34-
batch_header: batch.batch_header,
3540
};
3641
prove_and_verify_batch(&output_dir.to_string_lossy(), &mut batch_prover, batch);
3742
}

integration/tests/bundle_tests.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ fn gen_bundle_proving_task(batch_proof_files: &[&str]) -> BundleProvingTask {
2222

2323
for proof_file in batch_proof_files {
2424
let batch_proof: BatchProof = from_json_file(proof_file).unwrap();
25-
log::debug!(
26-
"Loaded batch-proofs, header {:#?}",
27-
batch_proof.batch_header
28-
);
25+
log::debug!("Loaded batch-proofs, header {:#?}", batch_proof.batch_hash,);
2926
batch_proofs.push(batch_proof);
3027
}
3128

integration/tests/e2e_tests.rs

+45-28
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use prover::{
33
eth_types::H256,
44
proof::dump_as_json,
55
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,
77
};
88
use std::{env, fs, path::Path};
99

@@ -32,16 +32,17 @@ fn test_e2e_prove_verify() {
3232
let chunks2 = load_batch("./tests/extra_traces/batch2").unwrap();
3333

3434
let mut batch_prover_pending = None;
35-
let mut batch_header = None;
35+
let mut opt_batch_header = None;
3636
let mut batch_proofs = Vec::new();
3737

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();
4546
if i == 0 {
4647
dump_chunk_protocol(&batch, &output_dir);
4748
batch_prover_pending.replace(new_batch_prover(&output_dir));
@@ -50,26 +51,30 @@ fn test_e2e_prove_verify() {
5051

5152
let batch_proof = prove_and_verify_batch(&output_dir, batch_prover, batch);
5253
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());
5456
fs::rename(proof_path, proof_path_to).unwrap();
5557

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);
5865
batch_proofs.push(batch_proof);
5966
}
6067

6168
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 };
6570
prove_and_verify_bundle(&output_dir, batch_prover, bundle);
6671
}
6772

6873
fn gen_batch_proving_task(
6974
output_dir: &str,
7075
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>) {
7378
let chunks: Vec<_> = chunk_dirs
7479
.iter()
7580
.map(|chunk_dir| load_chunk(chunk_dir).1)
@@ -109,22 +114,34 @@ fn gen_batch_proving_task(
109114
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,
110115
0, 0, 0, 0, 0, 0, 0,
111116
]);
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),
115120
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| {
117122
header.total_l1_message_popped + l1_message_popped
118123
}),
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()),
121125
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+
},
126143
batch_header,
127-
}
144+
)
128145
}
129146

130147
fn log_batch_pi(trace_paths: &[String]) {

0 commit comments

Comments
 (0)