Skip to content

Commit

Permalink
add sanity checks between infra/circuits
Browse files Browse the repository at this point in the history
  • Loading branch information
roynalnaruto committed Jul 11, 2024
1 parent 9f8a697 commit 86158b5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
40 changes: 34 additions & 6 deletions prover/src/aggregator/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<N_SNARKS> = BatchHash::construct(&chunk_hashes, batch_header);

let layer3_snark = self.prover_impl.load_or_gen_agg_snark(
name,
LayerId::Layer3.id(),
Expand Down
11 changes: 3 additions & 8 deletions prover/src/types.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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<ChunkProof>,
pub batch_header: BatchHeader<MAX_AGG_SNARKS>,
}

impl BatchProvingTask {
Expand Down

0 comments on commit 86158b5

Please sign in to comment.