diff --git a/Cargo.lock b/Cargo.lock index 260923340a..a79d1fa423 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -817,6 +817,30 @@ dependencies = [ "inout", ] +[[package]] +name = "circuit-benchmarks" +version = "0.1.0" +dependencies = [ + "ark-std 0.3.0", + "bus-mapping", + "env_logger", + "eth-types", + "ethers-signers", + "halo2_proofs 0.2.0", + "hex", + "itertools", + "keccak256", + "mock", + "rand", + "rand_chacha", + "rand_xorshift", + "serde", + "serde_json", + "snark-verifier", + "snark-verifier-sdk", + "zkevm-circuits", +] + [[package]] name = "clang-sys" version = "1.6.1" diff --git a/Cargo.toml b/Cargo.toml index 0aa183b25b..f620ce3d78 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,11 +9,12 @@ members = [ "eth-types", "external-tracer", "mock", + "circuit-benchmarks", "testool", ] [patch.crates-io] -halo2_proofs = { git = "https://github.com/taikoxyz/halo2.git", branch = "taiko/unstable"} +halo2_proofs = { git = "https://github.com/taikoxyz/halo2.git", branch = "taiko/unstable" } # Definition of benchmarks profile to use. [profile.bench] diff --git a/circuit-benchmarks/Cargo.toml b/circuit-benchmarks/Cargo.toml index 147eb70d8c..bdd0ae6eda 100644 --- a/circuit-benchmarks/Cargo.toml +++ b/circuit-benchmarks/Cargo.toml @@ -8,8 +8,19 @@ license = "MIT OR Apache-2.0" [dependencies] halo2_proofs = { git = "https://github.com/taikoxyz/halo2.git", branch = "taiko/unstable" } -snark-verifier = { git = "https://github.com/taikoxyz/snark-verifier.git", branch = "a6-integration", default-features = false, features = ["loader_halo2", "system_halo2", "loader_evm", "parallel"] } -snark-verifier-sdk = { git = "https://github.com/taikoxyz/snark-verifier.git", branch = "a6-integration", default-features = false, features = ["loader_halo2", "loader_evm", "parallel", "display", "halo2_circuit_params"] } +snark-verifier = { git = "https://github.com/taikoxyz/snark-verifier.git", branch = "a6-integration", default-features = false, features = [ + "loader_halo2", + "system_halo2", + "loader_evm", + "parallel", +] } +snark-verifier-sdk = { git = "https://github.com/taikoxyz/snark-verifier.git", branch = "a6-integration", default-features = false, features = [ + "loader_halo2", + "loader_evm", + "parallel", + "display", + "halo2_circuit_params", +] } ark-std = { version = "0.3", features = ["print-trace"] } zkevm-circuits = { path = "../zkevm-circuits", features = ["test"] } @@ -28,5 +39,5 @@ serde_json = "*" hex = "0.4.3" [features] -default = [] +default = ["benches"] benches = [] diff --git a/circuit-benchmarks/src/taiko_super_circuit.rs b/circuit-benchmarks/src/taiko_super_circuit.rs index 2fe5ef3dd3..76821143cf 100644 --- a/circuit-benchmarks/src/taiko_super_circuit.rs +++ b/circuit-benchmarks/src/taiko_super_circuit.rs @@ -12,7 +12,7 @@ use halo2_proofs::{ use rand::SeedableRng; use serde::{Deserialize, Serialize}; use snark_verifier::{ - loader::evm::{encode_calldata, Address as VerifierAddress, EvmLoader, ExecutorBuilder}, + loader::evm::{deploy_and_call, encode_calldata, EvmLoader}, pcs::kzg::*, system::halo2::{compile, transcript::evm::EvmTranscript, Config}, verifier::SnarkVerifier, @@ -86,9 +86,9 @@ pub fn gen_verifier( } }; - let yul = loader.yul_code(); - fs::write(Path::new("./aggregation_plonk.yul"), &yul).unwrap(); - yul + let sol = loader.solidity_code(); + fs::write(Path::new("./aggregation_plonk.sol"), &sol).unwrap(); + sol } /// for chain to verify @@ -102,26 +102,13 @@ pub fn evm_verify(deployment_code: Vec, instances: Vec>, proof: Vec< calldata.len(), ); - let success = { - let mut evm = ExecutorBuilder::default() - .with_gas_limit(u64::MAX.into()) - .build(); - let caller = VerifierAddress::from_low_u64_be(0xfe); - let deploy = evm.deploy(caller, deployment_code.into(), 0.into()); - match deploy.address { - Some(addr) => { - let result = evm.call_raw(caller, addr, calldata.into(), 0.into()); - println!("Deployment cost: {} gas", deploy.gas_used); - println!("Verification cost: {} gas", result.gas_used); - !result.reverted - } - None => { - println!("Deployment failed due to {:?}", deploy.exit_reason); - false - } + match deploy_and_call(deployment_code, calldata) { + Ok(_) => println!("Verification success"), + Err(e) => { + // println!("Verification failed due to {:?}", e); + panic!("Verification failed due to {:?}", e); } - }; - assert!(success); + } } #[cfg(test)] @@ -215,7 +202,7 @@ mod tests { let params = gen_srs(MIN_AGG_DEGREE); let mut snark_roots = Vec::new(); for snark in snarks { - let pcd_circuit = TaikoAggregationCircuit::::new(¶ms, [snark]).unwrap(); + let agg_circuit = TaikoAggregationCircuit::::new(¶ms, [snark]).unwrap(); let start0 = start_timer!(|| "gen vk & pk"); // let pk = gen_pk( @@ -224,8 +211,8 @@ mod tests { // Some(Path::new("./examples/agg.pk")), // agg_circuit.params(), // ); - let vk = keygen_vk(¶ms, &pcd_circuit).expect("keygen_vk should not fail"); - let pk = keygen_pk(¶ms, vk, &pcd_circuit).expect("keygen_pk should not fail"); + let vk = keygen_vk(¶ms, &agg_circuit).expect("keygen_vk should not fail"); + let pk = keygen_pk(¶ms, vk, &agg_circuit).expect("keygen_pk should not fail"); end_timer!(start0); let _root = match aggregation_type { @@ -233,7 +220,7 @@ mod tests { gen_snark_gwc( ¶ms, &pk, - pcd_circuit.clone(), + agg_circuit.clone(), // Some(Path::new("./examples/agg.snark")) None::<&str>, ) @@ -242,7 +229,7 @@ mod tests { gen_snark_shplonk( ¶ms, &pk, - pcd_circuit.clone(), + agg_circuit.clone(), // Some(Path::new("./examples/agg.snark")) None::<&str>, ) @@ -297,7 +284,7 @@ mod tests { ) .unwrap(); - let deployment_code = gen_verifier( + let deployment_sol = gen_verifier( ¶ms, &vk, Config::kzg() @@ -306,7 +293,7 @@ mod tests { num_instances, aggregation_type, ); - let evm_verifier_bytecode = evm::compile_yul(&deployment_code); + let evm_verifier_bytecode = evm::compile_solidity(&deployment_sol); evm_verify(evm_verifier_bytecode, instances, proof_calldata); } @@ -370,7 +357,7 @@ mod tests { num_instances, agg_type, ); - let evm_verifier_bytecode = evm::compile_yul(&deployment_code); + let evm_verifier_bytecode = evm::compile_solidity(&deployment_code); evm_verify(evm_verifier_bytecode, instances, proof_calldata); } @@ -382,7 +369,7 @@ mod tests { let mut deployment_code = String::new(); file.read_to_string(&mut deployment_code) .expect("yul file read ok"); - let evm_verifier_bytecode = evm::compile_yul(&deployment_code); + let evm_verifier_bytecode = evm::compile_solidity(&deployment_code); let proof_path = "./proof.json"; let proof_file = fs::File::open(proof_path).expect("proof file open ok"); diff --git a/integration-tests/src/integration_public_data_circuits.rs b/integration-tests/src/integration_public_data_circuits.rs index 6045913e8a..7d07b3977d 100644 --- a/integration-tests/src/integration_public_data_circuits.rs +++ b/integration-tests/src/integration_public_data_circuits.rs @@ -22,7 +22,6 @@ mod public_data_test { dev::{CellValue, MockProver}, halo2curves::bn256::Fr, }; - use log::error; use std::str::FromStr; use testool::{parse_address, parse_hash}; use zkevm_circuits::{ @@ -307,9 +306,9 @@ mod public_data_test { let k = 20; let prover = MockProver::run(k, &circuit, instance).unwrap(); let res = prover.verify_par(); - if let Err(err) = res { - error!("Verification failures: {:#?}", err); - panic!("Failed verification"); + if res.is_err() { + // show what went wrong + prover.assert_satisfied(); } } @@ -338,20 +337,20 @@ mod public_data_test { fn gen_requests() -> Vec { let metadata = BlockMetadata { - l1Hash: parse_hash("6e3b781b2d9a04e21ecba49e67dc3fb0a8242408cc07fa6fed5d8bd0eca2c985") + l1Hash: parse_hash("8374d2fde2f3e5640f0ce4f6bb557e988336c2dae71e55cb3734c5c6be450820") .unwrap() .as_fixed_bytes() .into(), txListHash: parse_hash( - "569e75fc77c1a856f6daaf9e69d8a9566ca34aa47f9133711ce065a571af0cfd", + "b3de7eaf38c3c84a34d7d80100c1b133bd7734f03b5c8e86cb806d684b718d85", ) .unwrap() .as_fixed_bytes() .into(), id: 10, - timestamp: 1694510352, - l1Height: 4272887, - coinbase: parse_address("0000777700000000000000000000000000000001") + timestamp: 1699729048, + l1Height: 131, + coinbase: parse_address("0x1000777700000000000000000000000000000001") .unwrap() .as_fixed_bytes() .into(), @@ -361,19 +360,19 @@ mod public_data_test { let block_evidence = BlockEvidence { blockMetadata: metadata, parentHash: parse_hash( - "a534f7f74d155fa0575ccfd9dbb2a7c4f89baa0fb48c3a312f0d97e3fbff7c47", + "beb327617555bd45c05ac7e33d2c509c77192eb8c372873483696b1a7367750a", ) .unwrap() .as_fixed_bytes() .into(), blockHash: parse_hash( - "c32ce5789b5ae9b2a3921e43fb16c429abcb520acf5e27dc717a9caf46c4319f", + "8a8c11d6c46c1e8cce87900b52854fc74975aab054355c2a060aeefc6419b606", ) .unwrap() .as_fixed_bytes() .into(), signalRoot: parse_hash( - "95a87577b110954a0daf867bd574aa726ec9a061b4bf0903d5adef23872f7f1b", + "61e8be9519dac9b5e5124dd2e3f4e79628def914c8a9e6290caddef681fad23b", ) .unwrap() .as_fixed_bytes() diff --git a/zkevm-circuits/src/anchor_tx_circuit.rs b/zkevm-circuits/src/anchor_tx_circuit.rs index fc1bc9e7e3..5c2390b338 100644 --- a/zkevm-circuits/src/anchor_tx_circuit.rs +++ b/zkevm-circuits/src/anchor_tx_circuit.rs @@ -37,14 +37,14 @@ const ANCHOR_VALUE: u64 = 0; const ANCHOR_IS_CREATE: bool = false; const ANCHOR_GAS_PRICE: u64 = 0; const ANCHOR_GAS_TIP_CAP: u64 = 0; -const ANCHOR_GAS_LIMIT: u64 = 0; +const ANCHOR_GAS_LIMIT: u64 = 250000; const MAX_DEGREE: usize = 9; const BYTE_POW_BASE: u64 = 1 << 8; /// L2 contract address pub static L2_CONTRACT: Lazy
= Lazy::new(|| { - Address::from_str("0x1000777700000000000000000000000000000001") + Address::from_str("0x1670010000000000000000000000000000010001") .expect("invalid l2 contract address") }); diff --git a/zkevm-circuits/src/taiko_super_circuit.rs b/zkevm-circuits/src/taiko_super_circuit.rs index 15ca0a8e81..d1166ba48e 100644 --- a/zkevm-circuits/src/taiko_super_circuit.rs +++ b/zkevm-circuits/src/taiko_super_circuit.rs @@ -4,6 +4,8 @@ #[cfg(any(feature = "test", test))] pub mod test; +#[cfg(feature = "for-a7")] +use crate::anchor_tx_circuit::{AnchorTxCircuit, AnchorTxCircuitConfig, AnchorTxCircuitConfigArgs}; #[cfg(feature = "for-a7")] use crate::bytecode_circuit::circuit::{ BytecodeCircuit, BytecodeCircuitConfig, BytecodeCircuitConfigArgs, @@ -11,21 +13,20 @@ use crate::bytecode_circuit::circuit::{ #[cfg(feature = "for-a7")] use crate::copy_circuit::{CopyCircuit, CopyCircuitConfig, CopyCircuitConfigArgs}; #[cfg(feature = "for-a7")] +use crate::evm_circuit::{EvmCircuit, EvmCircuitConfig, EvmCircuitConfigArgs}; +#[cfg(feature = "for-a7")] use crate::exp_circuit::{ExpCircuit, ExpCircuitConfig}; #[cfg(feature = "for-a7")] use crate::keccak_circuit::{KeccakCircuit, KeccakCircuitConfig, KeccakCircuitConfigArgs}; #[cfg(feature = "for-a7")] use crate::state_circuit::{StateCircuit, StateCircuitConfig, StateCircuitConfigArgs}; #[cfg(feature = "for-a7")] +use crate::table::{ByteTable, BytecodeTable, CopyTable, ExpTable}; +#[cfg(feature = "for-a7")] use crate::{table::MptTable, witness::MptUpdates}; use crate::{ - anchor_tx_circuit::{AnchorTxCircuit, AnchorTxCircuitConfig, AnchorTxCircuitConfigArgs}, - evm_circuit::{EvmCircuit, EvmCircuitConfig, EvmCircuitConfigArgs}, - table::{ - BlockTable, ByteTable, BytecodeTable, CopyTable, ExpTable, KeccakTable, PiTable, RwTable, - TxTable, - }, + table::{BlockTable, ByteTable, KeccakTable}, taiko_pi_circuit::{ PublicData, TaikoPiCircuit, TaikoPiCircuitConfig, TaikoPiCircuitConfigArgs, }, @@ -48,19 +49,27 @@ use snark_verifier_sdk::CircuitExt; /// Configuration of the Super Circuit #[derive(Clone)] pub struct SuperCircuitConfig { + #[cfg(feature = "for-a7")] tx_table: TxTable, + #[cfg(feature = "for-a7")] rw_table: RwTable, #[cfg(feature = "for-a7")] mpt_table: MptTable, + #[cfg(feature = "for-a7")] bytecode_table: BytecodeTable, + #[cfg(feature = "for-a7")] pi_table: PiTable, keccak_table: KeccakTable, block_table: BlockTable, byte_table: ByteTable, + #[cfg(feature = "for-a7")] copy_table: CopyTable, + #[cfg(feature = "for-a7")] exp_table: ExpTable, pi_circuit: TaikoPiCircuitConfig, + #[cfg(feature = "for-a7")] anchor_tx_circuit: AnchorTxCircuitConfig, + #[cfg(feature = "for-a7")] evm_circuit: EvmCircuitConfig, #[cfg(feature = "for-a7")] keccak_circuit: KeccakCircuitConfig, @@ -88,17 +97,24 @@ impl SubCircuitConfig for SuperCircuitConfig { meta: &mut ConstraintSystem, Self::ConfigArgs { challenges }: Self::ConfigArgs, ) -> Self { + #[cfg(feature = "for-a7")] let tx_table = TxTable::construct(meta); + #[cfg(feature = "for-a7")] let rw_table = RwTable::construct(meta); #[cfg(feature = "for-a7")] let mpt_table = MptTable::construct(meta); + #[cfg(feature = "for-a7")] let bytecode_table = BytecodeTable::construct(meta); + #[cfg(feature = "for-a7")] let pi_table = PiTable::construct(meta); let block_table = BlockTable::construct(meta); let keccak_table = KeccakTable::construct(meta); let byte_table = ByteTable::construct(meta); + #[cfg(feature = "for-a7")] let q_copy_table = meta.fixed_column(); + #[cfg(feature = "for-a7")] let copy_table = CopyTable::construct(meta, q_copy_table); + #[cfg(feature = "for-a7")] let exp_table = ExpTable::construct(meta); let pi_circuit = TaikoPiCircuitConfig::new( @@ -108,10 +124,11 @@ impl SubCircuitConfig for SuperCircuitConfig { block_table: block_table.clone(), keccak_table: keccak_table.clone(), byte_table: byte_table.clone(), - challenges: challenges.clone(), + challenges, }, ); + #[cfg(feature = "for-a7")] let anchor_tx_circuit = AnchorTxCircuitConfig::new( meta, AnchorTxCircuitConfigArgs { @@ -122,6 +139,7 @@ impl SubCircuitConfig for SuperCircuitConfig { }, ); + #[cfg(feature = "for-a7")] let evm_circuit = EvmCircuitConfig::new( meta, EvmCircuitConfigArgs { @@ -188,19 +206,27 @@ impl SubCircuitConfig for SuperCircuitConfig { }; Self { + #[cfg(feature = "for-a7")] tx_table, + #[cfg(feature = "for-a7")] rw_table, #[cfg(feature = "for-a7")] mpt_table, + #[cfg(feature = "for-a7")] bytecode_table, + #[cfg(feature = "for-a7")] copy_table, + #[cfg(feature = "for-a7")] exp_table, + #[cfg(feature = "for-a7")] pi_table, pi_circuit, block_table, keccak_table, byte_table, + #[cfg(feature = "for-a7")] anchor_tx_circuit, + #[cfg(feature = "for-a7")] evm_circuit, #[cfg(feature = "for-a7")] keccak_circuit, @@ -221,11 +247,13 @@ impl SubCircuitConfig for SuperCircuitConfig { pub struct SuperCircuit { /// Public Input Circuit pub pi_circuit: TaikoPiCircuit, + /// Anchor Transaction Circuit + #[cfg(feature = "for-a7")] pub anchor_tx_circuit: AnchorTxCircuit, /// EVM Circuit + #[cfg(feature = "for-a7")] pub evm_circuit: EvmCircuit, - // planed circuits for a6 #[cfg(feature = "for-a7")] pub(crate) keccak_circuit: KeccakCircuit, @@ -264,10 +292,18 @@ impl SubCircuit for SuperCircuit { fn new_from_block(block: &Block) -> Self { let pi_circuit = TaikoPiCircuit::new_from_block(block); - let anchor_tx_circuit = AnchorTxCircuit::new_from_block(block); - let evm_circuit = EvmCircuit::new_from_block(block); #[cfg(feature = "for-a7")] - let (keccak_circuit, bytecode_circuit, state_circuit, copy_circuit, exp_circuit) = { + let ( + anchor_tx_circuit, + evm_circuit, + keccak_circuit, + bytecode_circuit, + state_circuit, + copy_circuit, + exp_circuit, + ) = { + let anchor_tx_circuit = AnchorTxCircuit::new_from_block(block); + let evm_circuit = EvmCircuit::new_from_block(block); let keccak_circuit = KeccakCircuit::new_from_block(block); let bytecode_circuit = BytecodeCircuit::new_from_block(block); let state_circuit = StateCircuit::new_from_block(block); @@ -284,7 +320,9 @@ impl SubCircuit for SuperCircuit { SuperCircuit::<_> { pi_circuit, + #[cfg(feature = "for-a7")] anchor_tx_circuit, + #[cfg(feature = "for-a7")] evm_circuit, #[cfg(feature = "for-a7")] keccak_circuit, @@ -311,7 +349,20 @@ impl SubCircuit for SuperCircuit { fn min_num_rows_block(block: &Block) -> (usize, usize) { [ TaikoPiCircuit::min_num_rows_block(block), + #[cfg(feature = "for-a7")] AnchorTxCircuit::min_num_rows_block(block), + #[cfg(feature = "for-a7")] + EvmCircuit::min_num_rows_block(block), + #[cfg(feature = "for-a7")] + KeccakCircuit::min_num_rows_block(block), + #[cfg(feature = "for-a7")] + BytecodeCircuit::min_num_rows_block(block), + #[cfg(feature = "for-a7")] + StateCircuit::min_num_rows_block(block), + #[cfg(feature = "for-a7")] + CopyCircuit::min_num_rows_block(block), + #[cfg(feature = "for-a7")] + ExpCircuit::min_num_rows_block(block), ] .iter() .fold((0, 0), |(x1, y1), (x2, y2)| { @@ -328,12 +379,15 @@ impl SubCircuit for SuperCircuit { ) -> Result<(), Error> { self.pi_circuit .synthesize_sub(&config.pi_circuit, challenges, layouter)?; - self.anchor_tx_circuit - .synthesize_sub(&config.anchor_tx_circuit, challenges, layouter)?; - self.evm_circuit - .synthesize_sub(&config.evm_circuit, challenges, layouter)?; #[cfg(feature = "for-a7")] { + self.anchor_tx_circuit.synthesize_sub( + &config.anchor_tx_circuit, + challenges, + layouter, + )?; + self.evm_circuit + .synthesize_sub(&config.evm_circuit, challenges, layouter)?; self.keccak_circuit .synthesize_sub(&config.keccak_circuit, challenges, layouter)?; self.bytecode_circuit @@ -408,39 +462,42 @@ impl Circuit for SuperCircuit { &challenges, )?; config.byte_table.load(&mut layouter)?; - config.pi_table.load( - &mut layouter, - self.block.protocol_instance.as_ref().unwrap(), - &challenges, - )?; - config.tx_table.load( - &mut layouter, - &self.block.txs, - self.block.circuits_params.max_txs, - self.block.circuits_params.max_calldata, - &challenges, - )?; - self.block.rws.check_rw_counter_sanity(); - config.rw_table.load( - &mut layouter, - &self.block.rws.table_assignments(), - self.block.circuits_params.max_rws, - challenges.evm_word(), - )?; - config - .bytecode_table - .load(&mut layouter, self.block.bytecodes.values(), &challenges)?; - config.exp_table.load(&mut layouter, &self.block)?; - config - .copy_table - .load(&mut layouter, &self.block, &challenges)?; - #[cfg(feature = "for-a7")] - config.mpt_table.load( - &mut layouter, - &MptUpdates::mock_from(&self.state_circuit.rows), - randomness, - )?; + { + config.pi_table.load( + &mut layouter, + self.block.protocol_instance.as_ref().unwrap(), + &challenges, + )?; + config.tx_table.load( + &mut layouter, + &self.block.txs, + self.block.circuits_params.max_txs, + self.block.circuits_params.max_calldata, + &challenges, + )?; + self.block.rws.check_rw_counter_sanity(); + config.rw_table.load( + &mut layouter, + &self.block.rws.table_assignments(), + self.block.circuits_params.max_rws, + challenges.evm_word(), + )?; + config.bytecode_table.load( + &mut layouter, + self.block.bytecodes.values(), + &challenges, + )?; + config.exp_table.load(&mut layouter, &self.block)?; + config + .copy_table + .load(&mut layouter, &self.block, &challenges)?; + config.mpt_table.load( + &mut layouter, + &MptUpdates::mock_from(&self.state_circuit.rows), + randomness, + )?; + } self.synthesize_sub(&config, &challenges, &mut layouter) } diff --git a/zkevm-circuits/src/witness/block.rs b/zkevm-circuits/src/witness/block.rs index 025c42dd87..0d766a5638 100644 --- a/zkevm-circuits/src/witness/block.rs +++ b/zkevm-circuits/src/witness/block.rs @@ -93,7 +93,7 @@ pub fn protocol_instancetable_assignments( [ Value::known(F::from(PiFieldTag::L1Height as u64)), rlc_be_bytes( - &Word::from(protocol_instance.block_evidence.blockMetadata.l1Hash.0).to_be_bytes(), + &Word::from(protocol_instance.block_evidence.blockMetadata.l1Height).to_be_bytes(), randomness, ), ],