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

Commit 6fb53d3

Browse files
authored
Merge branch 'main' into release-v0.8.0
2 parents 66adc6e + cde2eda commit 6fb53d3

File tree

4 files changed

+83
-4
lines changed

4 files changed

+83
-4
lines changed

prover/src/aggregator/prover.rs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ impl Prover {
118118
let real_chunk_count = chunk_hashes_proofs.len();
119119
assert!((1..=MAX_AGG_SNARKS).contains(&real_chunk_count));
120120

121+
check_chunk_hashes(name, &chunk_hashes_proofs)?;
121122
let (mut chunk_hashes, chunk_proofs): (Vec<_>, Vec<_>) =
122123
chunk_hashes_proofs.into_iter().unzip();
123124

@@ -167,3 +168,81 @@ impl Prover {
167168
}
168169
}
169170
}
171+
172+
macro_rules! compare_field {
173+
($name:expr, $idx:expr, $field:ident, $lhs:ident, $rhs:ident) => {
174+
if $lhs.$field != $rhs.$field {
175+
bail!(
176+
"{} chunk-no-{}, different {}: {} != {}",
177+
$name,
178+
$idx,
179+
stringify!($field),
180+
$lhs.$field,
181+
$rhs.$field
182+
);
183+
}
184+
};
185+
}
186+
187+
fn check_chunk_hashes(name: &str, chunk_hashes_proofs: &[(ChunkHash, ChunkProof)]) -> Result<()> {
188+
for (idx, (in_arg, chunk_proof)) in chunk_hashes_proofs.iter().enumerate() {
189+
if let Some(in_proof) = chunk_proof.chunk_hash {
190+
compare_field!(name, idx, chain_id, in_arg, in_proof);
191+
compare_field!(name, idx, prev_state_root, in_arg, in_proof);
192+
compare_field!(name, idx, post_state_root, in_arg, in_proof);
193+
compare_field!(name, idx, withdraw_root, in_arg, in_proof);
194+
compare_field!(name, idx, data_hash, in_arg, in_proof);
195+
}
196+
}
197+
198+
Ok(())
199+
}
200+
201+
#[cfg(test)]
202+
mod tests {
203+
use super::*;
204+
use eth_types::H256;
205+
206+
#[test]
207+
fn test_check_chunk_hashes() {
208+
let chunk_hashes_proofs = vec![
209+
(ChunkHash::default(), ChunkProof::default()),
210+
(
211+
ChunkHash {
212+
chain_id: 1,
213+
prev_state_root: H256::zero(),
214+
data_hash: [100; 32].into(),
215+
..Default::default()
216+
},
217+
ChunkProof {
218+
chunk_hash: Some(ChunkHash {
219+
chain_id: 1,
220+
prev_state_root: [0; 32].into(),
221+
data_hash: [100; 32].into(),
222+
..Default::default()
223+
}),
224+
..Default::default()
225+
},
226+
),
227+
(
228+
ChunkHash {
229+
post_state_root: H256::zero(),
230+
..Default::default()
231+
},
232+
ChunkProof {
233+
chunk_hash: Some(ChunkHash {
234+
post_state_root: [1; 32].into(),
235+
..Default::default()
236+
}),
237+
..Default::default()
238+
},
239+
),
240+
];
241+
242+
let result = check_chunk_hashes("test-batch", &chunk_hashes_proofs);
243+
assert_eq!(
244+
result.unwrap_err().downcast_ref::<String>().unwrap(),
245+
"test-batch chunk-no-2, different post_state_root: 0x0000…0000 != 0x0101…0101"
246+
);
247+
}
248+
}

prover/src/io.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ pub fn serialize_verify_circuit_final_pair(pair: &(G1Affine, G1Affine, Vec<Fr>))
157157

158158
pub fn write_snark(file_path: &str, snark: &Snark) {
159159
let mut fd = std::fs::File::create(file_path).unwrap();
160-
serde_json::to_writer_pretty(&mut fd, snark).unwrap()
160+
serde_json::to_writer(&mut fd, snark).unwrap()
161161
}
162162

163163
pub fn load_snark(file_path: &str) -> anyhow::Result<Option<Snark>> {

prover/src/proof.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub use batch::BatchProof;
3030
pub use chunk::ChunkProof;
3131
pub use evm::EvmProof;
3232

33-
#[derive(Clone, Debug, Deserialize, Serialize)]
33+
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
3434
pub struct Proof {
3535
#[serde(with = "base64")]
3636
proof: Vec<u8>,
@@ -118,7 +118,7 @@ impl Proof {
118118
pub fn dump_as_json<P: serde::Serialize>(dir: &str, filename: &str, proof: &P) -> Result<()> {
119119
// Write full proof as json.
120120
let mut fd = File::create(dump_proof_path(dir, filename))?;
121-
serde_json::to_writer_pretty(&mut fd, proof)?;
121+
serde_json::to_writer(&mut fd, proof)?;
122122

123123
Ok(())
124124
}

prover/src/proof/chunk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use serde_derive::{Deserialize, Serialize};
99
use snark_verifier::Protocol;
1010
use snark_verifier_sdk::Snark;
1111

12-
#[derive(Clone, Debug, Deserialize, Serialize)]
12+
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
1313
pub struct ChunkProof {
1414
#[serde(with = "base64")]
1515
pub storage_trace: Vec<u8>,

0 commit comments

Comments
 (0)