Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/prover.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Run build
run: build-prover
run: make build-prover
50 changes: 32 additions & 18 deletions prover/Cargo.lock

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

1 change: 1 addition & 0 deletions prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2021"
[dependencies]
halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "develop" }
prover = { git = "https://github.com/morph-l2/zkevm-circuits.git", branch = "dev4844", default-features = false, features = ["parallel_syn", "scroll", "shanghai", "strict-ccc"] }
zkevm-circuits = { git = "https://github.com/morph-l2/zkevm-circuits.git", branch = "dev4844", default-features = false, features = ["parallel_syn", "scroll", "shanghai", "strict-ccc"] }
eth-types = { git = "https://github.com/morph-l2/zkevm-circuits.git", branch = "dev4844"}

tokio = { version = "1", features = ["full"] }
Expand Down
79 changes: 60 additions & 19 deletions prover/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ use crate::utils::{
get_block_traces_by_number, GENERATE_EVM_VERIFIER, PROVER_L2_RPC, PROVER_PARAMS_DIR, PROVER_PROOF_DIR,
PROVE_RESULT, PROVE_TIME, SCROLL_PROVER_ASSETS_DIR,
};
use eth_types::{ToLittleEndian, U256};
use ethers::providers::Provider;
use ethers::utils::keccak256;
use prover::aggregator::Prover as BatchProver;
use prover::config::{LayerId, LAYER4_DEGREE};
use prover::utils::chunk_trace_to_witness_block_with_index;
use prover::utils::{chunk_trace_to_witness_block, chunk_trace_to_witness_block_with_index};
use prover::zkevm::Prover as ChunkProver;
use prover::{BlockTrace, ChunkHash, ChunkProof, CompressionCircuit};
use serde::{Deserialize, Serialize};
Expand All @@ -15,7 +17,9 @@ use std::io::Write;
use std::time::{Duration, Instant};
use std::{sync::Arc, thread};
use tokio::sync::Mutex;
use eth_types::U256;
use zkevm_circuits::blob_circuit::block_to_blob;

const BLOB_DATA_SIZE: usize = 4096 * 32;

// proveRequest
#[derive(Serialize, Deserialize, Debug)]
Expand Down Expand Up @@ -84,12 +88,37 @@ async fn generate_proof(batch_index: u64, chunk_traces: Vec<Vec<BlockTrace>>, ch
let proof_path = PROVER_PROOF_DIR.to_string() + format!("/batch_{}", batch_index).as_str();
fs::create_dir_all(proof_path.clone()).unwrap();
let mut chunk_proofs: Vec<(ChunkHash, ChunkProof)> = vec![];
for (index, chunk_trace) in chunk_traces.iter().enumerate() {
let batch_commit: U256 = U256::from(0);
let challenge_point: U256 = U256::from(0);
let index: usize = index;
let partial_result: U256 = U256::from(0);

// get batch_blob from chunks
let mut batch_blob = [0u8; BLOB_DATA_SIZE];
let mut offset = 0;
for chunk_trace in chunk_traces.iter() {
match chunk_trace_to_witness_block(chunk_trace.to_vec()) {
Ok(witness) => {
let partial_result = block_to_blob(&witness).unwrap();
batch_blob[offset..partial_result.len()].copy_from_slice(&partial_result);
offset += partial_result.len();
}
Err(e) => {
log::error!("convert trace to witness of batch = {:#?} error: {:#?}", batch_index, e);
PROVE_RESULT.set(2);
return;
}
};
}

// todo: get batch_commit from eth trace
let batch_commit: U256 = U256::from(0);

// challenge_point = keccak256(batch_commit||batchBlob)
let mut pre: Vec<u8> = vec![];
pre.extend(batch_commit.to_le_bytes().to_vec());
pre.extend(batch_blob);
let challenge_point = U256::from_little_endian(keccak256(pre.as_slice()).as_ref());

let mut index = 0;
for chunk_trace in chunk_traces.iter(){
let partial_result: U256 = U256::from(0);
let chunk_witness = match chunk_trace_to_witness_block_with_index(
chunk_trace.to_vec(),
batch_commit,
Expand All @@ -104,6 +133,10 @@ async fn generate_proof(batch_index: u64, chunk_traces: Vec<Vec<BlockTrace>>, ch
return;
}
};

let partial_result_bytes = block_to_blob(&chunk_witness).ok();
index += partial_result_bytes.unwrap().len() / 32;

let chunk_hash = ChunkHash::from_witness_block(&chunk_witness, false);

log::info!(
Expand All @@ -112,18 +145,26 @@ async fn generate_proof(batch_index: u64, chunk_traces: Vec<Vec<BlockTrace>>, ch
index
);
// Start chunk prove
let chunk_proof: ChunkProof =
match chunk_prover.gen_chunk_proof_with_index(chunk_trace.to_vec(), index, None, None, Some(proof_path.as_str())) {
Ok(proof) => {
log::info!(">>chunk_{:#?} prove complate, batch index = {:#?}", index, batch_index);
proof
}
Err(e) => {
log::error!("chunk in batch_{:#?} prove err: {:#?}", batch_index, e);
PROVE_RESULT.set(2);
return;
}
};
let chunk_proof: ChunkProof = match chunk_prover.gen_chunk_proof_with_index(
chunk_trace.to_vec(),
batch_commit,
challenge_point,
index,
partial_result,
None,
None,
Some(proof_path.as_str()),
) {
Ok(proof) => {
log::info!(">>chunk_{:#?} prove complate, batch index = {:#?}", index, batch_index);
proof
}
Err(e) => {
log::error!("chunk in batch_{:#?} prove err: {:#?}", batch_index, e);
PROVE_RESULT.set(2);
return;
}
};

//save chunk.protocol
let protocol = &chunk_proof.protocol;
Expand Down