diff --git a/.github/workflows/prover.yml b/.github/workflows/prover.yml index abd3167f7..d5e00014f 100644 --- a/.github/workflows/prover.yml +++ b/.github/workflows/prover.yml @@ -22,4 +22,4 @@ jobs: steps: - uses: actions/checkout@v3 - name: Run build - run: build-prover \ No newline at end of file + run: make build-prover \ No newline at end of file diff --git a/prover/Cargo.lock b/prover/Cargo.lock index 0b06da25f..36dff54f3 100644 --- a/prover/Cargo.lock +++ b/prover/Cargo.lock @@ -47,10 +47,10 @@ dependencies = [ [[package]] name = "aggregator" version = "0.1.0" -source = "git+https://github.com/morph-l2/zkevm-circuits.git?branch=dev4844#247b36fb833e90fc98f5879369d727ff8d80ef8c" +source = "git+https://github.com/morph-l2/zkevm-circuits.git?branch=dev4844#cfcda5b7ed8207904f3db2b310bcefa397508f15" dependencies = [ "ark-std 0.3.0", - "bls12_381", + "bls12_381 0.7.0 (git+https://github.com/chengwenxi/bls12_381.git?branch=eip4844)", "env_logger 0.10.1", "eth-types", "ethers-core", @@ -569,6 +569,19 @@ dependencies = [ "subtle", ] +[[package]] +name = "bls12_381" +version = "0.7.0" +source = "git+https://github.com/morph-l2/bls12_381.git?branch=eip4844#5a21fec34fb2f350a1635538de59ecd91d1c5a70" +dependencies = [ + "ff 0.12.1", + "group 0.12.1", + "pairing", + "pasta_curves", + "rand_core", + "subtle", +] + [[package]] name = "brotli" version = "3.4.0" @@ -609,7 +622,7 @@ checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" [[package]] name = "bus-mapping" version = "0.1.0" -source = "git+https://github.com/morph-l2/zkevm-circuits.git?branch=dev4844#247b36fb833e90fc98f5879369d727ff8d80ef8c" +source = "git+https://github.com/morph-l2/zkevm-circuits.git?branch=dev4844#cfcda5b7ed8207904f3db2b310bcefa397508f15" dependencies = [ "eth-types", "ethers-core", @@ -1388,7 +1401,7 @@ dependencies = [ [[package]] name = "eth-types" version = "0.1.0" -source = "git+https://github.com/morph-l2/zkevm-circuits.git?branch=dev4844#247b36fb833e90fc98f5879369d727ff8d80ef8c" +source = "git+https://github.com/morph-l2/zkevm-circuits.git?branch=dev4844#cfcda5b7ed8207904f3db2b310bcefa397508f15" dependencies = [ "ethers-core", "ethers-signers", @@ -1708,7 +1721,7 @@ dependencies = [ [[package]] name = "external-tracer" version = "0.1.0" -source = "git+https://github.com/morph-l2/zkevm-circuits.git?branch=dev4844#247b36fb833e90fc98f5879369d727ff8d80ef8c" +source = "git+https://github.com/morph-l2/zkevm-circuits.git?branch=dev4844#cfcda5b7ed8207904f3db2b310bcefa397508f15" dependencies = [ "eth-types", "geth-utils", @@ -1945,7 +1958,7 @@ dependencies = [ [[package]] name = "gadgets" version = "0.1.0" -source = "git+https://github.com/morph-l2/zkevm-circuits.git?branch=dev4844#247b36fb833e90fc98f5879369d727ff8d80ef8c" +source = "git+https://github.com/morph-l2/zkevm-circuits.git?branch=dev4844#cfcda5b7ed8207904f3db2b310bcefa397508f15" dependencies = [ "digest 0.7.6", "eth-types", @@ -1978,7 +1991,7 @@ dependencies = [ [[package]] name = "geth-utils" version = "0.1.0" -source = "git+https://github.com/morph-l2/zkevm-circuits.git?branch=dev4844#247b36fb833e90fc98f5879369d727ff8d80ef8c" +source = "git+https://github.com/morph-l2/zkevm-circuits.git?branch=dev4844#cfcda5b7ed8207904f3db2b310bcefa397508f15" dependencies = [ "env_logger 0.9.3", "gobuild 0.1.0-alpha.2 (git+https://github.com/scroll-tech/gobuild.git)", @@ -2116,7 +2129,7 @@ dependencies = [ [[package]] name = "halo2-base" version = "0.2.2" -source = "git+https://github.com/dongliangCai/halo2-lib.git?branch=sync-blob-gadget#232ae85a852475c86f449af1e3bb1945c24973f1" +source = "git+https://github.com/morph-l2/halo2-lib.git?branch=sync-blob-gadget#a9ff18fb24a45f679e7bcb957d46a541001145e3" dependencies = [ "ff 0.12.1", "halo2_proofs", @@ -2150,11 +2163,11 @@ dependencies = [ [[package]] name = "halo2-ecc" version = "0.2.2" -source = "git+https://github.com/dongliangCai/halo2-lib.git?branch=sync-blob-gadget#232ae85a852475c86f449af1e3bb1945c24973f1" +source = "git+https://github.com/morph-l2/halo2-lib.git?branch=sync-blob-gadget#a9ff18fb24a45f679e7bcb957d46a541001145e3" dependencies = [ "ff 0.12.1", "group 0.12.1", - "halo2-base 0.2.2 (git+https://github.com/dongliangCai/halo2-lib.git?branch=sync-blob-gadget)", + "halo2-base 0.2.2 (git+https://github.com/morph-l2/halo2-lib.git?branch=sync-blob-gadget)", "itertools", "num-bigint", "num-integer", @@ -2674,7 +2687,7 @@ dependencies = [ [[package]] name = "keccak256" version = "0.1.0" -source = "git+https://github.com/morph-l2/zkevm-circuits.git?branch=dev4844#247b36fb833e90fc98f5879369d727ff8d80ef8c" +source = "git+https://github.com/morph-l2/zkevm-circuits.git?branch=dev4844#cfcda5b7ed8207904f3db2b310bcefa397508f15" dependencies = [ "env_logger 0.9.3", "eth-types", @@ -2963,7 +2976,7 @@ dependencies = [ [[package]] name = "mock" version = "0.1.0" -source = "git+https://github.com/morph-l2/zkevm-circuits.git?branch=dev4844#247b36fb833e90fc98f5879369d727ff8d80ef8c" +source = "git+https://github.com/morph-l2/zkevm-circuits.git?branch=dev4844#cfcda5b7ed8207904f3db2b310bcefa397508f15" dependencies = [ "eth-types", "ethers-core", @@ -2979,7 +2992,7 @@ dependencies = [ [[package]] name = "mpt-zktrie" version = "0.1.0" -source = "git+https://github.com/morph-l2/zkevm-circuits.git?branch=dev4844#247b36fb833e90fc98f5879369d727ff8d80ef8c" +source = "git+https://github.com/morph-l2/zkevm-circuits.git?branch=dev4844#cfcda5b7ed8207904f3db2b310bcefa397508f15" dependencies = [ "eth-types", "halo2-mpt-circuits", @@ -3598,7 +3611,7 @@ checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94" [[package]] name = "prover" version = "0.1.0" -source = "git+https://github.com/morph-l2/zkevm-circuits.git?branch=dev4844#247b36fb833e90fc98f5879369d727ff8d80ef8c" +source = "git+https://github.com/morph-l2/zkevm-circuits.git?branch=dev4844#cfcda5b7ed8207904f3db2b310bcefa397508f15" dependencies = [ "aggregator", "anyhow", @@ -5576,10 +5589,10 @@ dependencies = [ [[package]] name = "zkevm-circuits" version = "0.1.0" -source = "git+https://github.com/morph-l2/zkevm-circuits.git?branch=dev4844#247b36fb833e90fc98f5879369d727ff8d80ef8c" +source = "git+https://github.com/morph-l2/zkevm-circuits.git?branch=dev4844#cfcda5b7ed8207904f3db2b310bcefa397508f15" dependencies = [ "array-init", - "bls12_381", + "bls12_381 0.7.0 (git+https://github.com/morph-l2/bls12_381.git?branch=eip4844)", "bus-mapping", "either", "env_logger 0.9.3", @@ -5587,8 +5600,8 @@ dependencies = [ "ethers-core", "ethers-signers", "gadgets", - "halo2-base 0.2.2 (git+https://github.com/dongliangCai/halo2-lib.git?branch=sync-blob-gadget)", - "halo2-ecc 0.2.2 (git+https://github.com/dongliangCai/halo2-lib.git?branch=sync-blob-gadget)", + "halo2-base 0.2.2 (git+https://github.com/morph-l2/halo2-lib.git?branch=sync-blob-gadget)", + "halo2-ecc 0.2.2 (git+https://github.com/morph-l2/halo2-lib.git?branch=sync-blob-gadget)", "halo2_proofs", "hex", "itertools", @@ -5642,6 +5655,7 @@ dependencies = [ "tokio", "tower", "tower-http 0.4.4", + "zkevm-circuits", ] [[package]] diff --git a/prover/Cargo.toml b/prover/Cargo.toml index c897e1138..005626c46 100644 --- a/prover/Cargo.toml +++ b/prover/Cargo.toml @@ -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"] } diff --git a/prover/src/prover.rs b/prover/src/prover.rs index 99c22c541..37b647c1c 100644 --- a/prover/src/prover.rs +++ b/prover/src/prover.rs @@ -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}; @@ -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)] @@ -84,12 +88,37 @@ async fn generate_proof(batch_index: u64, chunk_traces: Vec>, 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 = 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, @@ -104,6 +133,10 @@ async fn generate_proof(batch_index: u64, chunk_traces: Vec>, 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!( @@ -112,18 +145,26 @@ async fn generate_proof(batch_index: u64, chunk_traces: Vec>, 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;