Skip to content

Commit

Permalink
fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
nulltea committed Dec 15, 2023
1 parent 6ad5044 commit 8231818
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 22 deletions.
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ download-spec-tests: clean-spec-tests
#!/usr/bin/env bash
if [[ ! -d 'consensus-spec-tests' ]]; then
echo "Downloading test data."
test-utils/scripts/download_consensus_specs.sh
bash test-utils/scripts/download_consensus_specs.sh
fi
# deletes all the downloaded spec tests
Expand Down
2 changes: 1 addition & 1 deletion lightclient-circuits/src/committee_update_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub struct CommitteeUpdateCircuit<S: Spec, F: Field> {
}

impl<S: Spec, F: Field> CommitteeUpdateCircuit<S, F> {
fn synthesize(
pub fn synthesize(
builder: &mut ShaCircuitBuilder<F, ShaBitGateManager<F>>,
fp_chip: &FpChip<F>,
args: &witness::CommitteeUpdateArgs<S>,
Expand Down
10 changes: 5 additions & 5 deletions lightclient-circuits/src/sync_step_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub struct StepCircuit<S: Spec + ?Sized, F: Field> {
}

impl<S: Spec, F: Field> StepCircuit<S, F> {
fn synthesize(
pub fn synthesize(
builder: &mut ShaCircuitBuilder<F, ShaFlexGateManager<F>>,
fp_chip: &FpChip<F>,
args: &witness::SyncStepArgs<S>,
Expand Down Expand Up @@ -439,6 +439,7 @@ impl<S: Spec> AppCircuit for StepCircuit<S, bn256::Fr> {
}
}


#[cfg(test)]
mod tests {
use std::fs;
Expand Down Expand Up @@ -515,7 +516,7 @@ mod tests {
"../build/sync_step_22.pkey",
"./config/sync_step_22.json",
&SyncStepArgs::<Testnet>::default(),
None
None,
);

let witness = load_circuit_args();
Expand Down Expand Up @@ -558,7 +559,7 @@ mod tests {
APP_PK_PATH,
APP_PINNING_PATH,
&SyncStepArgs::<Testnet>::default(),
None
None,
);

let witness = load_circuit_args();
Expand All @@ -578,8 +579,7 @@ mod tests {
AGG_PK_PATH,
AGG_CONFIG_PATH,
&vec![snark.clone()],
Some(AggregationConfigPinning::new(AGG_K, 19))

Some(AggregationConfigPinning::new(AGG_K, 19)),
);

let agg_config = AggregationConfigPinning::from_path(AGG_CONFIG_PATH);
Expand Down
76 changes: 61 additions & 15 deletions lightclient-circuits/tests/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@

use ark_std::{end_timer, start_timer};
use eth_types::{Minimal, LIMB_BITS};
use eth_types::{Spec, NUM_LIMBS};
use halo2_base::gates::circuit::CircuitBuilderStage;
use halo2_base::halo2_proofs::dev::MockProver;
use halo2_base::halo2_proofs::halo2curves::bn256;
use halo2_base::utils::fs::gen_srs;
use halo2_ecc::bls12_381::FpChip;
use lightclient_circuits::committee_update_circuit::CommitteeUpdateCircuit;
use lightclient_circuits::gadget::crypto::{ShaBitGateManager, ShaFlexGateManager};
use lightclient_circuits::sync_step_circuit::StepCircuit;
use lightclient_circuits::util::AppCircuit;
use lightclient_circuits::util::Eth2ConfigPinning;
use lightclient_circuits::util::Halo2ConfigPinning;
use lightclient_circuits::witness::CommitteeUpdateArgs;
use lightclient_circuits::witness::SyncStepArgs;
use lightclient_circuits::Eth2CircuitBuilder;
use rstest::rstest;
use snark_verifier_sdk::CircuitExt;
use std::env::var;
use std::path::PathBuf;

use test_utils::read_test_files_and_gen_witness;
Expand All @@ -29,16 +35,62 @@ fn test_eth2_spec_mock_1(
run_test_eth2_spec_mock::<18, 19>(path)
}

// Same as StepCircuit::create_circuit without loading SRS which fails CI.
pub(crate) fn mock_step_circuit<S: Spec>(
args: &SyncStepArgs<S>,
k: u32,
lookup_bits: Option<usize>,
) -> impl lightclient_circuits::util::PinnableCircuit<bn256::Fr> {
let mut builder =
Eth2CircuitBuilder::<ShaFlexGateManager<bn256::Fr>>::from_stage(CircuitBuilderStage::Mock)
.use_k(k as usize)
.use_instance_columns(1);
let range = builder.range_chip(lookup_bits.unwrap_or(k as usize - 1));
let fp_chip = FpChip::new(&range, LIMB_BITS, NUM_LIMBS);

let assigned_instances =
StepCircuit::<S, bn256::Fr>::synthesize(&mut builder, &fp_chip, args).unwrap();
builder.set_instances(0, assigned_instances);

builder.calculate_params(Some(
var("MINIMUM_ROWS")
.unwrap_or_else(|_| "0".to_string())
.parse()
.unwrap(),
));
builder
}

// Same as CommitteeUpdateCircuit::create_circuit without loading SRS which fails CI.
pub(crate) fn mock_committee_update_circuit<S: Spec>(
witness: &CommitteeUpdateArgs<S>,
k: u32,
lookup_bits: Option<usize>,
) -> impl lightclient_circuits::util::PinnableCircuit<bn256::Fr> {
let mut builder =
Eth2CircuitBuilder::<ShaBitGateManager<bn256::Fr>>::from_stage(CircuitBuilderStage::Mock)
.use_k(k as usize)
.use_instance_columns(1);
let range = builder.range_chip(lookup_bits.unwrap_or(k as usize - 1));
let fp_chip = FpChip::new(&range, LIMB_BITS, NUM_LIMBS);

let assigned_instances =
CommitteeUpdateCircuit::<S, bn256::Fr>::synthesize(&mut builder, &fp_chip, witness)
.unwrap();
builder.set_instances(0, assigned_instances);
builder.calculate_params(Some(
var("MINIMUM_ROWS")
.unwrap_or_else(|_| "0".to_string())
.parse()
.unwrap(),
));
builder
}

fn run_test_eth2_spec_mock<const K_ROTATION: u32, const K_SYNC: u32>(path: PathBuf) {
let (sync_witness, rotation_witness) = read_test_files_and_gen_witness(&path);

let rotation_circuit = CommitteeUpdateCircuit::<Minimal, bn256::Fr>::mock_circuit(
CircuitBuilderStage::Mock,
None,
&rotation_witness,
K_ROTATION,
)
.unwrap();
let rotation_circuit = mock_committee_update_circuit(&rotation_witness, K_ROTATION, None);

let timer = start_timer!(|| "committee_update mock prover run");
let prover = MockProver::<bn256::Fr>::run(
Expand All @@ -50,13 +102,7 @@ fn run_test_eth2_spec_mock<const K_ROTATION: u32, const K_SYNC: u32>(path: PathB
prover.assert_satisfied_par();
end_timer!(timer);

let sync_circuit = StepCircuit::<Minimal, bn256::Fr>::mock_circuit(
CircuitBuilderStage::Mock,
None,
&sync_witness,
K_SYNC,
)
.unwrap();
let sync_circuit = mock_step_circuit(&sync_witness, K_SYNC, None);

let instance = StepCircuit::<Minimal, bn256::Fr>::get_instances(&sync_witness, LIMB_BITS);

Expand Down Expand Up @@ -107,7 +153,7 @@ fn test_eth2_spec_evm_verify(
"../build/sync_step_21.pkey",
"./config/sync_step_21.json",
&SyncStepArgs::<Minimal>::default(),
None
None,
);

let (witness, _) = read_test_files_and_gen_witness(&path);
Expand Down

0 comments on commit 8231818

Please sign in to comment.