diff --git a/Cargo.toml b/Cargo.toml index a192af4..ba496c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,7 +49,7 @@ halo2-base = { git = "https://github.com/axiom-crypto/halo2-lib", branch = "comm halo2-ecc = { git = "https://github.com/axiom-crypto/halo2-lib", branch = "community-edition", default-features = false } zkevm-hashes = { git = "https://github.com/axiom-crypto/halo2-lib", branch = "community-edition", default-features = false } -halo2curves = { package = "halo2curves-axiom", version = "0.4.2" } +halo2curves = { package = "halo2curves-axiom", version = "0.5" } # verifier SDK snark-verifier = { git = "https://github.com/axiom-crypto/snark-verifier.git", branch = "community-edition", default-features = false, features = [ @@ -89,7 +89,7 @@ ark-std = { version = "0.4.0", features = ["print-trace"] } [patch.crates-io] -halo2curves = { git = "https://github.com/timoftime/halo2curves", package = "halo2curves-axiom", rev = "1bd39b8" } +halo2curves = { git = "https://github.com/timoftime/halo2curves", package = "halo2curves-axiom", branch = "support_bls12-381" } ssz_rs = { git = "https://github.com/ralexstokes/ssz-rs", rev = "5f1ec833718efa07bbbff427ab28a1eeaa706164" } diff --git a/README.md b/README.md index df7bca4..2bcf13d 100644 --- a/README.md +++ b/README.md @@ -108,5 +108,6 @@ where `` is one of `["GOERLI", "SEPOLIA", "MAINNET"]`. Prover is accessible via JSON RPC interface. To start it, run: ```shell -cargo run -r -- rpc --port 3000 +cargo run -r -- rpc --port 3000 --spec testnet ``` +where `--spec` is one of `["testnet", "mainnet"]`. diff --git a/lightclient-circuits/src/committee_update_circuit.rs b/lightclient-circuits/src/committee_update_circuit.rs index 4a7f956..42a481c 100644 --- a/lightclient-circuits/src/committee_update_circuit.rs +++ b/lightclient-circuits/src/committee_update_circuit.rs @@ -193,9 +193,9 @@ impl CommitteeUpdateCircuit { let mut pk_vector: Vector, { S::SYNC_COMMITTEE_SIZE }> = args .pubkeys_compressed + .as_slice() .iter() - .cloned() - .map(|v| v.try_into().unwrap()) + .map(|v| v.as_slice().try_into().unwrap()) .collect_vec() .try_into() .unwrap(); @@ -329,12 +329,13 @@ mod tests { fn test_committee_update_circuit() { const K: u32 = 18; let witness = load_circuit_args(); + let params: ParamsKZG = gen_srs(K); - let circuit = CommitteeUpdateCircuit::::mock_circuit( + let circuit = CommitteeUpdateCircuit::::create_circuit( CircuitBuilderStage::Mock, None, &witness, - K, + ¶ms, ) .unwrap(); @@ -392,25 +393,25 @@ mod tests { ); let witness = load_circuit_args(); - let snark = gen_application_snark(¶ms_app, &pk_app, &witness, APP_PINNING_PATH); + let snark = vec![gen_application_snark( + ¶ms_app, + &pk_app, + &witness, + APP_PINNING_PATH, + )]; let agg_params = gen_srs(AGG_K); println!("agg_params k: {:?}", agg_params.k()); - let pk = AggregationCircuit::create_pk( - &agg_params, - AGG_PK_PATH, - AGG_CONFIG_PATH, - &vec![snark.clone()], - None, - ); + let pk = + AggregationCircuit::create_pk(&agg_params, AGG_PK_PATH, AGG_CONFIG_PATH, &snark, None); let agg_config = AggregationConfigPinning::from_path(AGG_CONFIG_PATH); let agg_circuit = AggregationCircuit::create_circuit( CircuitBuilderStage::Prover, Some(agg_config), - &vec![snark.clone()], + &snark, &agg_params, ) .unwrap(); @@ -423,13 +424,9 @@ mod tests { let proof = gen_evm_proof_shplonk(&agg_params, &pk, agg_circuit, instances.clone()); println!("proof size: {}", proof.len()); - let deployment_code = AggregationCircuit::gen_evm_verifier_shplonk( - &agg_params, - &pk, - None::, - &vec![snark], - ) - .unwrap(); + let deployment_code = + AggregationCircuit::gen_evm_verifier_shplonk(&agg_params, &pk, None::, &snark) + .unwrap(); println!("deployment_code size: {}", deployment_code.len()); evm_verify(deployment_code, instances, proof); } diff --git a/lightclient-circuits/src/lib.rs b/lightclient-circuits/src/lib.rs index 653a4c8..b6e8d2e 100644 --- a/lightclient-circuits/src/lib.rs +++ b/lightclient-circuits/src/lib.rs @@ -9,7 +9,6 @@ #![feature(stmt_expr_attributes)] #![feature(trait_alias)] #![feature(generic_arg_infer)] -#![feature(return_position_impl_trait_in_trait)] #![allow(clippy::needless_range_loop)] pub mod gadget; diff --git a/lightclient-circuits/src/sync_step_circuit.rs b/lightclient-circuits/src/sync_step_circuit.rs index 1d829e0..2cc17f1 100644 --- a/lightclient-circuits/src/sync_step_circuit.rs +++ b/lightclient-circuits/src/sync_step_circuit.rs @@ -84,8 +84,8 @@ impl StepCircuit { let pubkey_affines = args .pubkeys_uncompressed + .as_slice() .iter() - .cloned() .map(|bytes| { G1Affine::from_uncompressed_unchecked(&bytes.as_slice().try_into().unwrap()) .unwrap() @@ -264,8 +264,8 @@ impl StepCircuit { let pubkey_affines = args .pubkeys_uncompressed + .as_slice() .iter() - .cloned() .map(|bytes| { G1Affine::from_uncompressed_unchecked(&bytes.as_slice().try_into().unwrap()) .unwrap() @@ -468,10 +468,15 @@ mod tests { fn test_step_circuit() { const K: u32 = 20; let witness = load_circuit_args(); + let params: ParamsKZG = gen_srs(K); - let circuit = - StepCircuit::::mock_circuit(CircuitBuilderStage::Mock, None, &witness, K) - .unwrap(); + let circuit = StepCircuit::::create_circuit( + CircuitBuilderStage::Mock, + None, + &witness, + ¶ms, + ) + .unwrap(); let instance = StepCircuit::::get_instances(&witness, LIMB_BITS); @@ -562,14 +567,14 @@ mod tests { ); let witness = load_circuit_args(); - let snark = StepCircuit::::gen_snark_shplonk( + let snark = vec![StepCircuit::::gen_snark_shplonk( ¶ms_app, &pk_app, APP_PINNING_PATH, None::, &witness, ) - .unwrap(); + .unwrap()]; let agg_params = gen_srs(AGG_K); @@ -577,7 +582,7 @@ mod tests { &agg_params, AGG_PK_PATH, AGG_CONFIG_PATH, - &vec![snark.clone()], + &snark.clone(), Some(AggregationConfigPinning::new(AGG_K, 19)), ); @@ -586,7 +591,7 @@ mod tests { let agg_circuit = AggregationCircuit::create_circuit( CircuitBuilderStage::Prover, Some(agg_config), - &vec![snark.clone()], + &snark, &agg_params, ) .unwrap(); @@ -599,13 +604,9 @@ mod tests { let proof = gen_evm_proof_shplonk(&agg_params, &pk, agg_circuit, instances.clone()); println!("proof size: {}", proof.len()); - let deployment_code = AggregationCircuit::gen_evm_verifier_shplonk( - &agg_params, - &pk, - None::, - &vec![snark], - ) - .unwrap(); + let deployment_code = + AggregationCircuit::gen_evm_verifier_shplonk(&agg_params, &pk, None::, &snark) + .unwrap(); println!("deployment_code size: {}", deployment_code.len()); evm_verify(deployment_code, instances, proof); } diff --git a/lightclient-circuits/src/util/circuit.rs b/lightclient-circuits/src/util/circuit.rs index 7805cc9..030cea3 100644 --- a/lightclient-circuits/src/util/circuit.rs +++ b/lightclient-circuits/src/util/circuit.rs @@ -15,7 +15,6 @@ use halo2_base::halo2_proofs::{ plonk::{Circuit, Error, VerifyingKey}, poly::kzg::commitment::ParamsKZG, }; -use halo2_base::utils::fs::gen_srs; use serde::{Deserialize, Serialize}; use snark_verifier_sdk::evm::{ encode_calldata, evm_verify, gen_evm_proof_shplonk, gen_evm_verifier_shplonk, @@ -249,17 +248,6 @@ pub trait AppCircuit { Ok(calldata) } - - /// Same as [`AppCircuit::create_circuit`] but with a mock circuit. - fn mock_circuit( - stage: CircuitBuilderStage, - pinning: Option, - witness: &Self::Witness, - k: u32, - ) -> Result, Error> { - let params = gen_srs(k); - Self::create_circuit(stage, pinning, witness, ¶ms) - } } pub fn custom_gen_evm_verifier_shplonk>( diff --git a/lightclient-circuits/src/witness/rotation.rs b/lightclient-circuits/src/witness/rotation.rs index 0bdf1a5..e19bf1e 100644 --- a/lightclient-circuits/src/witness/rotation.rs +++ b/lightclient-circuits/src/witness/rotation.rs @@ -99,8 +99,13 @@ mod tests { use crate::{committee_update_circuit::CommitteeUpdateCircuit, util::AppCircuit}; use eth_types::Testnet; use halo2_base::{ - gates::circuit::CircuitBuilderStage, halo2_proofs::dev::MockProver, - halo2_proofs::halo2curves::bn256::Fr, + gates::circuit::CircuitBuilderStage, + halo2_proofs::dev::MockProver, + halo2_proofs::{ + halo2curves::bn256::{Bn256, Fr}, + poly::kzg::commitment::ParamsKZG, + }, + utils::fs::gen_srs, }; use snark_verifier_sdk::CircuitExt; @@ -108,12 +113,13 @@ mod tests { fn test_committee_update_default_witness() { const K: u32 = 18; let witness = CommitteeUpdateArgs::::default(); + let params: ParamsKZG = gen_srs(K); - let circuit = CommitteeUpdateCircuit::::mock_circuit( + let circuit = CommitteeUpdateCircuit::::create_circuit( CircuitBuilderStage::Mock, None, &witness, - K, + ¶ms, ) .unwrap(); diff --git a/lightclient-circuits/src/witness/step.rs b/lightclient-circuits/src/witness/step.rs index 9b84262..1e48e0f 100644 --- a/lightclient-circuits/src/witness/step.rs +++ b/lightclient-circuits/src/witness/step.rs @@ -128,8 +128,12 @@ mod tests { use crate::{sync_step_circuit::StepCircuit, util::AppCircuit}; use eth_types::Testnet; use halo2_base::{ - gates::circuit::CircuitBuilderStage, halo2_proofs::dev::MockProver, + gates::circuit::CircuitBuilderStage, halo2_proofs::halo2curves::bn256::Fr, + halo2_proofs::{ + dev::MockProver, halo2curves::bn256::Bn256, poly::kzg::commitment::ParamsKZG, + }, + utils::fs::gen_srs, }; use snark_verifier_sdk::CircuitExt; @@ -137,10 +141,15 @@ mod tests { fn test_step_default_witness() { const K: u32 = 20; let witness = SyncStepArgs::::default(); + let params: ParamsKZG = gen_srs(K); - let circuit = - StepCircuit::::mock_circuit(CircuitBuilderStage::Mock, None, &witness, K) - .unwrap(); + let circuit = StepCircuit::::create_circuit( + CircuitBuilderStage::Mock, + None, + &witness, + ¶ms, + ) + .unwrap(); let prover = MockProver::::run(K, &circuit, circuit.instances()).unwrap(); prover.assert_satisfied_par(); diff --git a/lightclient-circuits/tests/step.rs b/lightclient-circuits/tests/step.rs index e62279a..0eae2a1 100644 --- a/lightclient-circuits/tests/step.rs +++ b/lightclient-circuits/tests/step.rs @@ -158,11 +158,11 @@ fn test_eth2_spec_evm_verify( let pinning = Eth2ConfigPinning::from_path("./config/sync_step_21.json"); - let circuit = StepCircuit::::mock_circuit( + let circuit = StepCircuit::::create_circuit( CircuitBuilderStage::Prover, Some(pinning), &witness, - K, + ¶ms, ) .unwrap(); diff --git a/preprocessor/src/lib.rs b/preprocessor/src/lib.rs index 1b9381c..468d9e6 100644 --- a/preprocessor/src/lib.rs +++ b/preprocessor/src/lib.rs @@ -46,10 +46,10 @@ where [(); S::SYNC_COMMITTEE_DEPTH]:, [(); S::FINALIZED_HEADER_INDEX]:, { - let route = format!("eth/v1/beacon/light_client/updates"); + let route = "eth/v1/beacon/light_client/updates"; let mut updates: Vec> = client .http - .get(client.endpoint.join(&route)?) + .get(client.endpoint.join(route)?) .query(&[("start_period", period), ("count", 1)]) .send() .await? @@ -176,6 +176,9 @@ mod tests { use eth_types::Testnet; use ethereum_consensus_types::signing::{compute_domain, DomainType}; use ethereum_consensus_types::ForkData; + use halo2_base::halo2_proofs::halo2curves::bn256::Bn256; + use halo2_base::halo2_proofs::poly::kzg::commitment::ParamsKZG; + use halo2_base::utils::fs::gen_srs; use lightclient_circuits::committee_update_circuit::CommitteeUpdateCircuit; use lightclient_circuits::halo2_proofs::{dev::MockProver, halo2curves::bn256::Fr}; use lightclient_circuits::util::{Eth2ConfigPinning, Halo2ConfigPinning}; @@ -206,7 +209,7 @@ mod tests { // Fetch light client update and create circuit arguments let (s, mut c) = { - let mut update = get_light_client_update_at_period(&client, period) + let update = get_light_client_update_at_period(&client, period) .await .unwrap(); @@ -236,7 +239,7 @@ mod tests { fork_version, }; let domain = compute_domain(DomainType::SyncCommittee, &fork_data).unwrap(); - light_client_update_to_args::(&mut update, pubkeys_compressed, domain) + light_client_update_to_args::(&update, pubkeys_compressed, domain) .await .unwrap() }; @@ -263,9 +266,15 @@ mod tests { // Replaces the attested header with step circuits finalized header c.finalized_header = s.finalized_header.clone(); - let circuit = - StepCircuit::::mock_circuit(CircuitBuilderStage::Mock, None, &s, K) - .unwrap(); + let params: ParamsKZG = gen_srs(K); + + let circuit = StepCircuit::::create_circuit( + CircuitBuilderStage::Mock, + None, + &s, + ¶ms, + ) + .unwrap(); let prover = MockProver::::run(K, &circuit, circuit.instances()).unwrap(); prover.assert_satisfied_par(); @@ -273,11 +282,11 @@ mod tests { const CONFIG_PATH: &str = "../lightclient-circuits/config/committee_update_testnet.json"; let pinning = Eth2ConfigPinning::from_path(CONFIG_PATH); - let circuit = CommitteeUpdateCircuit::::mock_circuit( + let circuit = CommitteeUpdateCircuit::::create_circuit( CircuitBuilderStage::Mock, Some(pinning), &c, - K, + ¶ms, ) .unwrap(); diff --git a/preprocessor/src/rotation.rs b/preprocessor/src/rotation.rs index a298714..1166356 100644 --- a/preprocessor/src/rotation.rs +++ b/preprocessor/src/rotation.rs @@ -110,6 +110,8 @@ mod tests { use super::*; use beacon_api_client::mainnet::Client as MainnetClient; use eth_types::Testnet; + use halo2_base::halo2_proofs::halo2curves::bn256::Bn256; + use halo2_base::halo2_proofs::poly::kzg::commitment::ParamsKZG; use halo2_base::utils::fs::gen_srs; use lightclient_circuits::halo2_proofs::{dev::MockProver, halo2curves::bn256::Fr}; use lightclient_circuits::{ @@ -128,12 +130,13 @@ mod tests { MainnetClient::new(Url::parse("https://lodestar-sepolia.chainsafe.io").unwrap()); let witness = fetch_rotation_args::(&client).await.unwrap(); let pinning = Eth2ConfigPinning::from_path(CONFIG_PATH); + let params: ParamsKZG = gen_srs(K); - let circuit = CommitteeUpdateCircuit::::mock_circuit( + let circuit = CommitteeUpdateCircuit::::create_circuit( CircuitBuilderStage::Mock, Some(pinning), &witness, - K, + ¶ms, ) .unwrap(); diff --git a/preprocessor/src/step.rs b/preprocessor/src/step.rs index 4b4bb36..df207c7 100644 --- a/preprocessor/src/step.rs +++ b/preprocessor/src/step.rs @@ -160,6 +160,8 @@ pub async fn step_args_from_finality_update( #[cfg(test)] mod tests { use eth_types::Testnet; + use halo2_base::halo2_proofs::halo2curves::bn256::Bn256; + use halo2_base::halo2_proofs::poly::kzg::commitment::ParamsKZG; use halo2_base::utils::fs::gen_srs; use lightclient_circuits::halo2_proofs::{dev::MockProver, halo2curves::bn256::Fr}; use lightclient_circuits::{ @@ -179,10 +181,15 @@ mod tests { MainnetClient::new(Url::parse("https://lodestar-sepolia.chainsafe.io").unwrap()); let witness = fetch_step_args::(&client).await.unwrap(); + let params: ParamsKZG = gen_srs(K); - let circuit = - StepCircuit::::mock_circuit(CircuitBuilderStage::Mock, None, &witness, K) - .unwrap(); + let circuit = StepCircuit::::create_circuit( + CircuitBuilderStage::Mock, + None, + &witness, + ¶ms, + ) + .unwrap(); let prover = MockProver::::run(K, &circuit, circuit.instances()).unwrap(); prover.assert_satisfied_par(); diff --git a/prover/Cargo.toml b/prover/Cargo.toml index 151fcdf..ad46475 100644 --- a/prover/Cargo.toml +++ b/prover/Cargo.toml @@ -11,14 +11,13 @@ path = "src/main.rs" # cli clap = { version = "4.2", features = ["derive"] } strum = { version = "=0.25", features = ["derive"] } -cli-batteries = "0.5" hex = "0.4" eyre = "0.6" anstyle = "1.0.0" axum = { version = "0.7", features = ["tracing", "tower-log"] } tokio = { version = "1.32", features = ["macros"] } - jsonrpc-v2 = { version = "0.13", default-features = false, features = ["easy-errors", "macros", "bytes-v10", "hyper-integration"] } +tracing-subscriber = "0.3" # halo2 halo2curves.workspace = true @@ -55,9 +54,6 @@ ethereum-consensus-types.workspace = true futures = "0.3.29" ssz_rs.workspace = true -[build-dependencies] -cli-batteries = "=0.5" - [features] default = ["halo2_solidity_verifier"] experimental = ["halo2_solidity_verifier_new"] diff --git a/prover/build.rs b/prover/build.rs deleted file mode 100644 index 6bfc91a..0000000 --- a/prover/build.rs +++ /dev/null @@ -1,7 +0,0 @@ -// The Licensed Work is (c) 2023 ChainSafe -// Code: https://github.com/ChainSafe/Spectre -// SPDX-License-Identifier: LGPL-3.0-only - -fn main() { - cli_batteries::build_rs().unwrap() -} diff --git a/prover/src/main.rs b/prover/src/main.rs index b6061f3..2b09e4b 100644 --- a/prover/src/main.rs +++ b/prover/src/main.rs @@ -13,9 +13,8 @@ mod utils; use crate::{cli::spec_app, rpc::run_rpc}; use args::Cli; -use cli_batteries::version; +use clap::Parser; use utils::utils_cli; - mod args; async fn app(options: Cli) -> eyre::Result<()> { @@ -61,6 +60,9 @@ async fn app(options: Cli) -> eyre::Result<()> { } } -fn main() { - cli_batteries::run(version!(), app); +#[tokio::main] +async fn main() { + let args = Cli::parse(); + tracing_subscriber::fmt::init(); + app(args).await.unwrap(); } diff --git a/prover/src/prover.rs b/prover/src/prover.rs index 41f301f..03368b2 100644 --- a/prover/src/prover.rs +++ b/prover/src/prover.rs @@ -51,11 +51,10 @@ impl ProverState { default_witness: Circuit::Witness, ) -> CircuitContext { let degree = Circuit::get_degree(&config_path); - let params = gen_srs(degree); - let pk = Circuit::read_pk(¶ms, pk_path, &config_path, &default_witness); + let params = params_map.entry(degree).or_insert_with(|| gen_srs(degree)); - params_map.insert(degree, params); + let pk = Circuit::read_pk(params, pk_path, &config_path, &default_witness); CircuitContext { config_path, diff --git a/prover/src/rpc.rs b/prover/src/rpc.rs index 0fb7c58..dd41e5c 100644 --- a/prover/src/rpc.rs +++ b/prover/src/rpc.rs @@ -95,7 +95,7 @@ where state.committee_update_verifier.pk(), state.committee_update_verifier.config_path(), None, - &vec![snark.clone()], + &vec![snark], ) .map_err(JsonRpcError::internal)?; @@ -158,7 +158,7 @@ where state.step_verifier.pk(), state.step_verifier.config_path(), None, - &vec![snark.clone()], + &vec![snark], ) .map_err(JsonRpcError::internal)?; @@ -211,7 +211,7 @@ where [(); S::FINALIZED_HEADER_INDEX]:, { let tcp_listener = tokio::net::TcpListener::bind(format!("0.0.0.0:{}", port)).await?; - let timer = start_timer!(|| "Load proving keys"); + let timer = start_timer!(|| "Load Prover State and Context"); let state = ProverState::new::(config_dir.as_ref(), build_dir.as_ref(), concurrency); end_timer!(timer); let rpc_server = Arc::new(jsonrpc_server::(state)); diff --git a/prover/src/rpc_api.rs b/prover/src/rpc_api.rs index 29ee763..23adbb7 100644 --- a/prover/src/rpc_api.rs +++ b/prover/src/rpc_api.rs @@ -38,13 +38,3 @@ pub struct CommitteeUpdateEvmProofResult { pub committee_poseidon: U256, pub public_inputs: Vec, } - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct SyncCommitteePoseidonParams { - pub pubkeys: Vec>, -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct SyncCommitteePoseidonResult { - pub commitment: [u8; 32], -} diff --git a/prover/src/utils.rs b/prover/src/utils.rs index 9dabd3b..9c53db8 100644 --- a/prover/src/utils.rs +++ b/prover/src/utils.rs @@ -39,7 +39,7 @@ pub(crate) async fn utils_cli(method: UtilsCmd) -> eyre::Result<()> { }; let sync_period = bootstrap.header.beacon.slot / (32 * 256); - print!("Sync period: {} \n", sync_period); + println!("Sync period: {}", sync_period); let pubkeys_uncompressed = bootstrap .current_sync_committee .pubkeys diff --git a/rust-toolchain b/rust-toolchain index 6f6d7b3..9df1964 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2023-08-12 +nightly-2024-01-08