Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
lispc committed Aug 27, 2024
1 parent b2b0fcd commit 854bec8
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 81 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions bin/src/chain_prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
// Instead this is more as a testing tool.
// For production prover, see https://github.com/scroll-tech/scroll/tree/develop/prover

use integration::capacity_checker::{
prepare_circuit_capacity_checker, run_circuit_capacity_checker, CCCMode,
use integration::{
capacity_checker::{prepare_circuit_capacity_checker, run_circuit_capacity_checker, CCCMode},
l2geth,
};
use prover::{
aggregator,
Expand All @@ -15,7 +16,6 @@ use prover::{
use std::env;

mod constants;
mod l2geth_client;
mod prove_utils;
mod rollupscan_client;

Expand Down Expand Up @@ -158,7 +158,7 @@ impl ChunkBuilder {
}

// Construct chunk myself
async fn prove_by_block(l2geth: &l2geth_client::Client, begin_block: i64, end_block: i64) {
async fn prove_by_block(l2geth: &l2geth::Client, begin_block: i64, end_block: i64) {
let mut chunk_builder = ChunkBuilder::new();
//chunk_builder.block_limit = Some(1);
let mut batch_builder = BatchBuilder::new();
Expand Down Expand Up @@ -263,7 +263,7 @@ fn prove_chunk(batch_id: u64, chunk_id: u64, block_traces: Vec<BlockTrace>) -> O

// Use constructed chunk/batch info from coordinator
async fn prove_by_batch(
l2geth: &l2geth_client::Client,
l2geth: &l2geth::Client,
rollupscan: &rollupscan_client::Client,
begin_batch: i64,
end_batch: i64,
Expand Down Expand Up @@ -328,7 +328,7 @@ async fn main() {

warmup();

let l2geth = l2geth_client::Client::new("chain_prover", &setting.l2geth_api_url)
let l2geth = l2geth::Client::new("chain_prover", &setting.l2geth_api_url)
.unwrap_or_else(|e| panic!("chain_prover: failed to initialize ethers Provider: {e}"));
let rollupscan = rollupscan_client::Client::new("chain_prover", &setting.rollupscan_api_url);

Expand Down
63 changes: 0 additions & 63 deletions bin/src/l2geth_client.rs

This file was deleted.

2 changes: 2 additions & 0 deletions integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition.workspace = true
license.workspace = true

[dependencies]
ethers-providers.workspace = true
anyhow.workspace = true
glob.workspace = true
itertools.workspace = true
Expand All @@ -14,6 +15,7 @@ rand.workspace = true
serde.workspace = true
serde_json.workspace = true
serde_derive.workspace = true
tokio.workspace = true

revm = { version = "3.5.0", default-features = false, features = ["std"] }
snark-verifier = { git = "https://github.com/scroll-tech/snark-verifier", branch = "develop" }
Expand Down
4 changes: 3 additions & 1 deletion integration/src/capacity_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,9 @@ pub fn ccc_by_chunk(
let row_usage = RowUsage::from_row_usage_details(rows);
pretty_print_row_usage(&row_usage, block_traces, chunk_id, "chunk-opt");

let avg_ccc_time_per_tx = Duration::from_millis(start_time.elapsed().as_millis() as u64 / witness_block.txs.len() as u64);
let avg_ccc_time_per_tx = Duration::from_millis(
start_time.elapsed().as_millis() as u64 / witness_block.txs.len() as u64,
);

(row_usage, avg_ccc_time_per_tx)
}
Expand Down
1 change: 1 addition & 0 deletions integration/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod capacity_checker;
pub mod evm;
pub mod l2geth;
pub mod prove;
pub mod test_util;
mod verifier;
53 changes: 42 additions & 11 deletions integration/tests/unit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@

use integration::{
capacity_checker::{
ccc_as_signer_light, ccc_by_chunk, prepare_circuit_capacity_checker, run_circuit_capacity_checker, txbytx_traces_from_block, CCCMode
ccc_as_signer_light, ccc_by_chunk, prepare_circuit_capacity_checker,
run_circuit_capacity_checker, txbytx_traces_from_block, CCCMode,
},
l2geth,
test_util::load_chunk_for_test,
};
use prover::{
io::read_all,
utils::{get_block_trace_from_file, init_env_and_log, short_git_version},
zkevm::{circuit::{block_traces_to_witness_block, TargetCircuit}, CircuitCapacityChecker},
utils::{get_block_trace_from_file, init_env_and_log, read_env_var, short_git_version},
zkevm::{
circuit::{block_traces_to_witness_block, TargetCircuit},
CircuitCapacityChecker,
},
};

#[test]
Expand Down Expand Up @@ -108,16 +113,44 @@ fn test_txbytx_traces() {
// part1: real row usage
let batch_id = 0;
let chunk_id = 0;
let block_trace = get_block_trace_from_file("tests/test_data/ccc/8626705-legacy-block.json");
let ccc_block: usize = read_env_var("CCC_BLOCK", 0);
let is_local = ccc_block == 0;
let (block_trace, txbytx_traces) = if is_local {
let block_trace =
get_block_trace_from_file("tests/test_data/ccc/8626705-legacy-block.json");

let txbytx_traces: Vec<BlockTrace> = {
let f = std::fs::File::open("tests/test_data/ccc/8626705-legacy-txbytx.json").unwrap();
serde_json::from_reader(&f).unwrap()
};
(block_trace, txbytx_traces)
} else {
let runtime = tokio::runtime::Runtime::new().unwrap();
let l2geth = l2geth::Client::new("unit_test", "http://127.0.0.1:8545")
.unwrap_or_else(|e| panic!("chain_prover: failed to initialize ethers Provider: {e}"));
let (trace, tx_traces) = runtime.block_on(async {
let trace = l2geth
.get_block_trace_by_num(ccc_block as i64, false)
.await
.unwrap_or_else(|e| {
panic!("chain_prover: failed to request l2geth block-trace API for block-{ccc_block}: {e}")
});
let tx_traces = l2geth
.get_txbytx_trace_by_num(ccc_block as i64)
.await
.unwrap_or_else(|e| {
panic!("chain_prover: failed to request l2geth block-trace API for block-{ccc_block}: {e}")
});
(trace, tx_traces)
});
(trace, tx_traces)
};
let (real_usage, t) = ccc_by_chunk(batch_id, chunk_id, &[block_trace]);
//log::info!("row usage {:#?}", real_usage);
//log::info!("avg time each tx: {}ms", t.as_millis());

// part2: tx by tx row usage
let txbytx_traces: Vec<BlockTrace> = {
let f = std::fs::File::open("tests/test_data/ccc/8626705-legacy-txbytx.json").unwrap();
serde_json::from_reader(&f).unwrap()
};

let tx_num = txbytx_traces.len();

let mut checker = CircuitCapacityChecker::new();
Expand All @@ -138,9 +171,7 @@ fn test_txbytx_traces() {
let r2 = real_usage.row_usage_details[i].row_number;
// FIXME: the "1" of bytecode circuit
assert!(r1 + 1 >= r2);
log::info!("{}\t{}\t{}", row_usage.row_usage_details[i].name,
r1, r2
);
log::info!("{}\t{}\t{}", row_usage.row_usage_details[i].name, r1, r2);
}
log::info!("{}\t{}\t{}", "avg-tx-ms", t.as_millis(), avg_ccc_time);
}
Expand Down

0 comments on commit 854bec8

Please sign in to comment.