Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/batch_circuit_pi' into feat…
Browse files Browse the repository at this point in the history
…/agg_recursion
  • Loading branch information
noel2004 committed Jul 2, 2024
2 parents 6815128 + 4d48233 commit 4ed709c
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
23 changes: 22 additions & 1 deletion aggregator/src/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ mod tests {
vec![vec![]; MAX_AGG_SNARKS],
),
(
"max number of chunkks all non-empty",
"max number of chunks all non-empty",
(0..MAX_AGG_SNARKS)
.map(|i| (10u8..11 + u8::try_from(i).unwrap()).collect())
.collect(),
Expand Down Expand Up @@ -742,6 +742,27 @@ mod tests {
]
.iter()
{
// batch header
let batch_header = crate::batch::BatchHeader {
version: 3,
batch_index: 6789,
l1_message_popped: 101,
total_l1_message_popped: 10101,
parent_batch_hash: H256::repeat_byte(1),
last_block_timestamp: 192837,
..Default::default()
};
let chunks_without_padding = crate::chunk::ChunkInfo::mock_chunk_infos(&tcase);
let batch_hash = BatchHash::<MAX_AGG_SNARKS>::construct_with_unpadded(
&chunks_without_padding,
batch_header,
);
println!(
"[[ {:60} ]] batch_hash = {:0>64x}\n\n",
annotation, batch_hash.current_batch_hash,
);

// blob data
let batch_data: BatchData<MAX_AGG_SNARKS> = tcase.into();
let point_evaluation_assignments = PointEvaluationAssignments::from(&batch_data);
let versioned_hash = batch_data.get_versioned_hash();
Expand Down
43 changes: 43 additions & 0 deletions aggregator/src/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,49 @@ impl ChunkInfo {
H256(keccak256(&self.tx_bytes))
}

#[cfg(test)]
pub(crate) fn mock_chunk_infos(txs_data: &[Vec<u8>]) -> Vec<Self> {
use crate::MAX_AGG_SNARKS;

assert!(txs_data.len() <= MAX_AGG_SNARKS);
let state_roots: [H256; MAX_AGG_SNARKS + 1] = (0..=MAX_AGG_SNARKS)
.map(|i| {
let i = i as u8;
let mut state_root = [0u8; 32];
state_root[31] = i;
state_root.into()
})
.collect::<Vec<_>>()
.try_into()
.expect("should not fail");

txs_data
.iter()
.enumerate()
.map(|(i, tx_data)| {
let withdraw_root = {
let mut root = [0u8; 32];
root[31] = 255 - (i as u8);
root.into()
};
let data_hash = {
let mut root = [0u8; 32];
root[0] = 255 - (i as u8);
root.into()
};
ChunkInfo {
chain_id: 123456,
prev_state_root: state_roots[i],
post_state_root: state_roots[i + 1],
withdraw_root,
data_hash,
tx_bytes: tx_data.to_vec(),
is_padding: false,
}
})
.collect::<Vec<_>>()
}

/// Sample a chunk info from random (for testing)
#[cfg(test)]
pub(crate) fn mock_random_chunk_info_for_testing<R: rand::RngCore>(r: &mut R) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion aggregator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mod tests;

pub use self::core::extract_proof_and_instances_with_pairing_check;
pub use aggregation::*;
pub use batch::BatchHash;
pub use batch::{BatchHash, BatchHeader};
pub use blob::BatchData;
pub use chunk::ChunkInfo;
pub use compression::*;
Expand Down
4 changes: 2 additions & 2 deletions prover/src/common/prover/aggregation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
io::{load_snark, write_snark},
utils::gen_rng,
};
use aggregator::{BatchCircuit, BatchHash, ChunkInfo, MAX_AGG_SNARKS};
use aggregator::{BatchCircuit, BatchHash, BatchHeader, ChunkInfo, MAX_AGG_SNARKS};
use anyhow::{anyhow, Result};
use rand::Rng;
use snark_verifier_sdk::Snark;
Expand All @@ -21,7 +21,7 @@ impl Prover {
) -> Result<Snark> {
env::set_var("AGGREGATION_CONFIG", layer_config_path(id));

let batch_hash = BatchHash::construct(chunk_hashes);
let batch_hash = BatchHash::construct(chunk_hashes, BatchHeader::default());

let circuit: BatchCircuit<MAX_AGG_SNARKS> =
BatchCircuit::new(self.params(degree), previous_snarks, &mut rng, batch_hash)
Expand Down

0 comments on commit 4ed709c

Please sign in to comment.