Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup Some Obvious Stuff #54

Merged
merged 12 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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" }


Expand Down
35 changes: 16 additions & 19 deletions lightclient-circuits/src/committee_update_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ impl<S: Spec, F: Field> CommitteeUpdateCircuit<S, F> {

let mut pk_vector: Vector<Vector<u8, 48>, { 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();
Expand Down Expand Up @@ -329,12 +329,13 @@ mod tests {
fn test_committee_update_circuit() {
const K: u32 = 18;
let witness = load_circuit_args();
let params: ParamsKZG<Bn256> = gen_srs(K);

let circuit = CommitteeUpdateCircuit::<Testnet, Fr>::mock_circuit(
&params,
CircuitBuilderStage::Mock,
None,
&witness,
K,
)
.unwrap();

Expand Down Expand Up @@ -392,25 +393,25 @@ mod tests {
);

let witness = load_circuit_args();
let snark = gen_application_snark(&params_app, &pk_app, &witness, APP_PINNING_PATH);
let snark = vec![gen_application_snark(
&params_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();
Expand All @@ -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::<String>,
&vec![snark],
)
.unwrap();
let deployment_code =
AggregationCircuit::gen_evm_verifier_shplonk(&agg_params, &pk, None::<String>, &snark)
.unwrap();
println!("deployment_code size: {}", deployment_code.len());
evm_verify(deployment_code, instances, proof);
}
Expand Down
1 change: 0 additions & 1 deletion lightclient-circuits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 17 additions & 16 deletions lightclient-circuits/src/sync_step_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ impl<S: Spec, F: Field> StepCircuit<S, F> {

let pubkey_affines = args
.pubkeys_uncompressed
.as_slice()
.iter()
.cloned()
.map(|bytes| {
G1Affine::from_uncompressed_unchecked(&bytes.as_slice().try_into().unwrap())
.unwrap()
Expand Down Expand Up @@ -264,8 +264,8 @@ impl<S: Spec, F: Field> StepCircuit<S, F> {

let pubkey_affines = args
.pubkeys_uncompressed
.as_slice()
.iter()
.cloned()
.map(|bytes| {
G1Affine::from_uncompressed_unchecked(&bytes.as_slice().try_into().unwrap())
.unwrap()
Expand Down Expand Up @@ -468,10 +468,15 @@ mod tests {
fn test_step_circuit() {
const K: u32 = 20;
let witness = load_circuit_args();
let params: ParamsKZG<Bn256> = gen_srs(K);

let circuit =
StepCircuit::<Testnet, Fr>::mock_circuit(CircuitBuilderStage::Mock, None, &witness, K)
.unwrap();
let circuit = StepCircuit::<Testnet, Fr>::mock_circuit(
&params,
CircuitBuilderStage::Mock,
None,
&witness,
)
.unwrap();

let instance = StepCircuit::<Testnet, Fr>::get_instances(&witness, LIMB_BITS);

Expand Down Expand Up @@ -562,22 +567,22 @@ mod tests {
);

let witness = load_circuit_args();
let snark = StepCircuit::<Testnet, Fr>::gen_snark_shplonk(
let snark = vec![StepCircuit::<Testnet, Fr>::gen_snark_shplonk(
&params_app,
&pk_app,
APP_PINNING_PATH,
None::<String>,
&witness,
)
.unwrap();
.unwrap()];

let agg_params = gen_srs(AGG_K);

let pk = AggregationCircuit::create_pk(
&agg_params,
AGG_PK_PATH,
AGG_CONFIG_PATH,
&vec![snark.clone()],
&snark.clone(),
Some(AggregationConfigPinning::new(AGG_K, 19)),
);

Expand All @@ -586,7 +591,7 @@ mod tests {
let agg_circuit = AggregationCircuit::create_circuit(
CircuitBuilderStage::Prover,
Some(agg_config),
&vec![snark.clone()],
&snark,
&agg_params,
)
.unwrap();
Expand All @@ -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::<String>,
&vec![snark],
)
.unwrap();
let deployment_code =
AggregationCircuit::gen_evm_verifier_shplonk(&agg_params, &pk, None::<String>, &snark)
.unwrap();
println!("deployment_code size: {}", deployment_code.len());
evm_verify(deployment_code, instances, proof);
}
Expand Down
6 changes: 2 additions & 4 deletions lightclient-circuits/src/util/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -252,13 +251,12 @@ pub trait AppCircuit {

/// Same as [`AppCircuit::create_circuit`] but with a mock circuit.
fn mock_circuit(
params: &ParamsKZG<Bn256>,
ec2 marked this conversation as resolved.
Show resolved Hide resolved
stage: CircuitBuilderStage,
pinning: Option<Self::Pinning>,
witness: &Self::Witness,
k: u32,
) -> Result<impl crate::util::PinnableCircuit<Fr>, Error> {
let params = gen_srs(k);
Self::create_circuit(stage, pinning, witness, &params)
Self::create_circuit(stage, pinning, witness, params)
}
}

Expand Down
12 changes: 9 additions & 3 deletions lightclient-circuits/src/witness/rotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,27 @@ 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;

#[test]
fn test_committee_update_default_witness() {
const K: u32 = 18;
let witness = CommitteeUpdateArgs::<Testnet>::default();
let params: ParamsKZG<Bn256> = gen_srs(K);

let circuit = CommitteeUpdateCircuit::<Testnet, Fr>::mock_circuit(
&params,
CircuitBuilderStage::Mock,
None,
&witness,
K,
)
.unwrap();

Expand Down
17 changes: 13 additions & 4 deletions lightclient-circuits/src/witness/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,28 @@ 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;

#[test]
fn test_step_default_witness() {
const K: u32 = 20;
let witness = SyncStepArgs::<Testnet>::default();
let params: ParamsKZG<Bn256> = gen_srs(K);

let circuit =
StepCircuit::<Testnet, Fr>::mock_circuit(CircuitBuilderStage::Mock, None, &witness, K)
.unwrap();
let circuit = StepCircuit::<Testnet, Fr>::mock_circuit(
&params,
CircuitBuilderStage::Mock,
None,
&witness,
)
.unwrap();

let prover = MockProver::<Fr>::run(K, &circuit, circuit.instances()).unwrap();
prover.assert_satisfied_par();
Expand Down
2 changes: 1 addition & 1 deletion lightclient-circuits/tests/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ fn test_eth2_spec_evm_verify(
let pinning = Eth2ConfigPinning::from_path("./config/sync_step_21.json");

let circuit = StepCircuit::<Minimal, bn256::Fr>::mock_circuit(
&params,
CircuitBuilderStage::Prover,
Some(pinning),
&witness,
K,
)
.unwrap();

Expand Down
17 changes: 11 additions & 6 deletions preprocessor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<VersionedValue<_>> = client
.http
.get(client.endpoint.join(&route)?)
.get(client.endpoint.join(route)?)
.query(&[("start_period", period), ("count", 1)])
.send()
.await?
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -236,7 +239,7 @@ mod tests {
fork_version,
};
let domain = compute_domain(DomainType::SyncCommittee, &fork_data).unwrap();
light_client_update_to_args::<Testnet>(&mut update, pubkeys_compressed, domain)
light_client_update_to_args::<Testnet>(&update, pubkeys_compressed, domain)
.await
.unwrap()
};
Expand All @@ -263,8 +266,10 @@ mod tests {
// Replaces the attested header with step circuits finalized header
c.finalized_header = s.finalized_header.clone();

let params: ParamsKZG<Bn256> = gen_srs(K);

let circuit =
StepCircuit::<Testnet, Fr>::mock_circuit(CircuitBuilderStage::Mock, None, &s, K)
StepCircuit::<Testnet, Fr>::mock_circuit(&params, CircuitBuilderStage::Mock, None, &s)
.unwrap();

let prover = MockProver::<Fr>::run(K, &circuit, circuit.instances()).unwrap();
Expand All @@ -274,10 +279,10 @@ mod tests {

let pinning = Eth2ConfigPinning::from_path(CONFIG_PATH);
let circuit = CommitteeUpdateCircuit::<Testnet, Fr>::mock_circuit(
&params,
CircuitBuilderStage::Mock,
Some(pinning),
&c,
K,
)
.unwrap();

Expand Down
5 changes: 4 additions & 1 deletion preprocessor/src/rotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -128,12 +130,13 @@ mod tests {
MainnetClient::new(Url::parse("https://lodestar-sepolia.chainsafe.io").unwrap());
let witness = fetch_rotation_args::<Testnet, _>(&client).await.unwrap();
let pinning = Eth2ConfigPinning::from_path(CONFIG_PATH);
let params: ParamsKZG<Bn256> = gen_srs(K);

let circuit = CommitteeUpdateCircuit::<Testnet, Fr>::mock_circuit(
&params,
CircuitBuilderStage::Mock,
Some(pinning),
&witness,
K,
)
.unwrap();

Expand Down
Loading
Loading