From 86158b58907aac1c4c8f43ce9d5b29170d309401 Mon Sep 17 00:00:00 2001 From: Rohit Narurkar Date: Thu, 11 Jul 2024 10:59:05 +0100 Subject: [PATCH] add sanity checks between infra/circuits --- prover/src/aggregator/prover.rs | 40 ++++++++++++++++++++++++++++----- prover/src/types.rs | 11 +++------ 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/prover/src/aggregator/prover.rs b/prover/src/aggregator/prover.rs index 9e27e17e77..e5b0ba3a2b 100644 --- a/prover/src/aggregator/prover.rs +++ b/prover/src/aggregator/prover.rs @@ -146,16 +146,44 @@ impl Prover { // Load or generate aggregation snark (layer-3). let batch_header = BatchHeader::construct_from_chunks( - batch.version, - batch.batch_index, - batch.l1_message_popped, - batch.total_l1_message_popped, - batch.parent_batch_hash, - batch.last_block_timestamp, + batch.batch_header.version, + batch.batch_header.batch_index, + batch.batch_header.l1_message_popped, + batch.batch_header.total_l1_message_popped, + batch.batch_header.parent_batch_hash, + batch.batch_header.last_block_timestamp, &chunk_hashes, ); + + // sanity check between: + // - BatchHeader supplied from infra + // - BatchHeader re-constructed by circuits + // + // for the fields data_hash, z, y, blob_versioned_hash. + assert_eq!( + batch_header.data_hash, batch.batch_header.data_hash, + "BatchHeader(sanity) mismatch data_hash expected={}, got={}", + batch.batch_header.data_hash, batch_header.data_hash + ); + assert_eq!( + batch_header.blob_data_proof[0], batch.batch_header.blob_data_proof[0], + "BatchHeader(sanity) mismatch blob data proof (z) expected={}, got={}", + batch.batch_header.blob_data_proof[0], batch_header.blob_data_proof[0], + ); + assert_eq!( + batch_header.blob_data_proof[1], batch.batch_header.blob_data_proof[1], + "BatchHeader(sanity) mismatch blob data proof (y) expected={}, got={}", + batch.batch_header.blob_data_proof[1], batch_header.blob_data_proof[1], + ); + assert_eq!( + batch_header.blob_versioned_hash, batch.batch_header.blob_versioned_hash, + "BatchHeader(sanity) mismatch blob versioned hash expected={}, got={}", + batch.batch_header.blob_versioned_hash, batch_header.blob_versioned_hash, + ); + let batch_hash = batch_header.batch_hash(); let batch_info: BatchHash = BatchHash::construct(&chunk_hashes, batch_header); + let layer3_snark = self.prover_impl.load_or_gen_agg_snark( name, LayerId::Layer3.id(), diff --git a/prover/src/types.rs b/prover/src/types.rs index c049a97fc6..ef57cba56d 100644 --- a/prover/src/types.rs +++ b/prover/src/types.rs @@ -1,5 +1,5 @@ -use aggregator::ChunkInfo; -use eth_types::{l2_types::BlockTrace, H256}; +use aggregator::{BatchHeader, ChunkInfo, MAX_AGG_SNARKS}; +use eth_types::l2_types::BlockTrace; use serde::{Deserialize, Serialize}; use zkevm_circuits::evm_circuit::witness::Block; @@ -43,13 +43,8 @@ impl ChunkProvingTask { #[derive(Debug, Clone, Deserialize, Serialize)] pub struct BatchProvingTask { - pub version: u8, - pub batch_index: u64, - pub l1_message_popped: u64, - pub total_l1_message_popped: u64, - pub parent_batch_hash: H256, - pub last_block_timestamp: u64, pub chunk_proofs: Vec, + pub batch_header: BatchHeader, } impl BatchProvingTask {