Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

add circuit-benchmark back and fix compiling issue #169

Merged
merged 4 commits into from
Dec 4, 2023
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
24 changes: 24 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
17 changes: 14 additions & 3 deletions circuit-benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand All @@ -28,5 +39,5 @@ serde_json = "*"
hex = "0.4.3"

[features]
default = []
default = ["benches"]
benches = []
51 changes: 19 additions & 32 deletions circuit-benchmarks/src/taiko_super_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
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,
Expand Down Expand Up @@ -50,7 +50,7 @@
StdRng::seed_from_u64(9)
}

/// Returns [<len>, ...] of `instance`

Check warning on line 53 in circuit-benchmarks/src/taiko_super_circuit.rs

View workflow job for this annotation

GitHub Actions / Intra-doc links

unclosed HTML tag `len`
pub fn gen_num_instance(instance: &[Vec<Fr>]) -> Vec<usize> {
instance.iter().map(|v| v.len()).collect()
}
Expand Down Expand Up @@ -86,9 +86,9 @@
}
};

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();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we changing from yul to solidity?

sol
}

/// for chain to verify
Expand All @@ -102,26 +102,13 @@
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)]
Expand Down Expand Up @@ -215,7 +202,7 @@
let params = gen_srs(MIN_AGG_DEGREE);
let mut snark_roots = Vec::new();
for snark in snarks {
let pcd_circuit = TaikoAggregationCircuit::<AS>::new(&params, [snark]).unwrap();
let agg_circuit = TaikoAggregationCircuit::<AS>::new(&params, [snark]).unwrap();

let start0 = start_timer!(|| "gen vk & pk");
// let pk = gen_pk(
Expand All @@ -224,16 +211,16 @@
// Some(Path::new("./examples/agg.pk")),
// agg_circuit.params(),
// );
let vk = keygen_vk(&params, &pcd_circuit).expect("keygen_vk should not fail");
let pk = keygen_pk(&params, vk, &pcd_circuit).expect("keygen_pk should not fail");
let vk = keygen_vk(&params, &agg_circuit).expect("keygen_vk should not fail");
let pk = keygen_pk(&params, vk, &agg_circuit).expect("keygen_pk should not fail");
end_timer!(start0);

let _root = match aggregation_type {
AccumulationSchemeType::GwcType => {
gen_snark_gwc(
&params,
&pk,
pcd_circuit.clone(),
agg_circuit.clone(),
// Some(Path::new("./examples/agg.snark"))
None::<&str>,
)
Expand All @@ -242,7 +229,7 @@
gen_snark_shplonk(
&params,
&pk,
pcd_circuit.clone(),
agg_circuit.clone(),
// Some(Path::new("./examples/agg.snark"))
None::<&str>,
)
Expand Down Expand Up @@ -297,7 +284,7 @@
)
.unwrap();

let deployment_code = gen_verifier(
let deployment_sol = gen_verifier(
&params,
&vk,
Config::kzg()
Expand All @@ -306,7 +293,7 @@
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);
}
Expand Down Expand Up @@ -370,7 +357,7 @@
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);
}
Expand All @@ -382,7 +369,7 @@
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");
Expand Down
23 changes: 11 additions & 12 deletions integration-tests/src/integration_public_data_circuits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -338,20 +337,20 @@ mod public_data_test {

fn gen_requests() -> Vec<ProtocolInstance> {
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(),
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/anchor_tx_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Address> = Lazy::new(|| {
Address::from_str("0x1000777700000000000000000000000000000001")
Address::from_str("0x1670010000000000000000000000000000010001")
.expect("invalid l2 contract address")
});

Expand Down
Loading
Loading