Skip to content

Commit

Permalink
Download the spec tests on CI run (#22)
Browse files Browse the repository at this point in the history
* adds download spec tests task to CI

* fix task naming

* simply gh action test

* add nocapture flag

* skip `cargo check` action

* gen SRS in a separate gh action

* remove params from `AppCircuit::create_circuit`

---------

Co-authored-by: Timofey Luin <[email protected]>
  • Loading branch information
willemolding and nulltea authored Oct 5, 2023
1 parent ea77170 commit 5e613c7
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 40 deletions.
17 changes: 13 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@ jobs:
toolchain: nightly-2022-10-28
override: true
components: rustfmt
- name: Check
run: cargo check --all
- name: Check
run: RUST_LOG="lightclient-circuits=debug" cargo test --release test_eth2_spec_mock

- name: Install just
uses: extractions/setup-just@v1

- name: Download consensus spec
run: just download-spec-tests

# skip this in favour of compiling in the `Test` action.
# - name: Check
# run: cargo check --all

- name: Test
run: RUST_LOG="lightclient-circuits=debug" PARAMS_DIR="./test_data" cargo test --release test_eth2_spec_mock_1 -- --nocapture
9 changes: 5 additions & 4 deletions lightclient-circuits/src/aggregation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@ impl AppCircuit for AggregationCircuit {
fn create_circuit(
stage: CircuitBuilderStage,
pinning: Option<Self::Pinning>,
params: &ParamsKZG<halo2curves::bn256::Bn256>,
snark: &Self::Witness,
k: u32,
) -> Result<impl crate::util::PinnableCircuit<Fr>, halo2_proofs::plonk::Error> {
let lookup_bits = params.k() as usize - 1;
let lookup_bits = k as usize - 1;
let params = gen_srs(k);
let mut circuit = AggregationCircuit::new::<SHPLONK>(
stage,
pinning.map(|p| p.break_points),
lookup_bits,
params,
&params,
snark.clone(),
);

Expand All @@ -53,7 +54,7 @@ impl AppCircuit for AggregationCircuit {
circuit.expose_previous_instances(false);
}
_ => {
circuit.config(params.k(), Some(10));
circuit.config(k, Some(10));
set_var("LOOKUP_BITS", lookup_bits.to_string());
}
};
Expand Down
10 changes: 5 additions & 5 deletions lightclient-circuits/src/committee_update_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ impl<S: Spec> AppCircuit for CommitteeUpdateCircuit<S, bn256::Fr> {
fn create_circuit(
stage: CircuitBuilderStage,
pinning: Option<Self::Pinning>,
params: &ParamsKZG<bn256::Bn256>,
witness: &witness::CommitteeRotationArgs<S, bn256::Fr>,
k: u32,
) -> Result<impl crate::util::PinnableCircuit<bn256::Fr>, Error> {
let mut thread_pool = ShaBitThreadBuilder::from_stage(stage);
let range = RangeChip::<bn256::Fr>::new(RangeStrategy::Vertical, 8);
Expand All @@ -198,7 +198,7 @@ impl<S: Spec> AppCircuit for CommitteeUpdateCircuit<S, bn256::Fr> {
CircuitBuilderStage::Prover => {}
_ => {
thread_pool.config(
params.k() as usize,
k as usize,
Some(
var("MINIMUM_ROWS")
.unwrap_or_else(|_| "0".to_string())
Expand Down Expand Up @@ -305,8 +305,8 @@ mod tests {
let circuit = CommitteeUpdateCircuit::<Testnet, Fr>::create_circuit(
CircuitBuilderStage::Mock,
Some(pinning),
&params,
&witness,
params.k(),
)
.unwrap();

Expand Down Expand Up @@ -336,8 +336,8 @@ mod tests {
let circuit = CommitteeUpdateCircuit::<Testnet, Fr>::create_circuit(
CircuitBuilderStage::Prover,
Some(pinning),
&params,
&witness,
K,
)
.unwrap();

Expand Down Expand Up @@ -381,8 +381,8 @@ mod tests {
let agg_circuit = AggregationCircuit::create_circuit(
CircuitBuilderStage::Prover,
Some(agg_config),
&params,
&vec![snark.clone()],
AGG_K,
)
.unwrap();

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 @@ -461,8 +461,8 @@ impl<S: Spec> AppCircuit for SyncStepCircuit<S, bn256::Fr> {
fn create_circuit(
stage: CircuitBuilderStage,
pinning: Option<Self::Pinning>,
params: &ParamsKZG<Bn256>,
args: &Self::Witness,
k: u32,
) -> Result<impl crate::util::PinnableCircuit<bn256::Fr>, Error> {
let mut thread_pool = ShaThreadBuilder::from_stage(stage);
let range = RangeChip::<bn256::Fr>::new(RangeStrategy::Vertical, 8);
Expand All @@ -473,7 +473,7 @@ impl<S: Spec> AppCircuit for SyncStepCircuit<S, bn256::Fr> {
CircuitBuilderStage::Prover => {}
_ => {
thread_pool.config(
params.k() as usize,
k as usize,
Some(
var("MINIMUM_ROWS")
.unwrap_or_else(|_| "0".to_string())
Expand Down Expand Up @@ -553,8 +553,8 @@ mod tests {
let circuit = SyncStepCircuit::<Testnet, Fr>::create_circuit(
CircuitBuilderStage::Mock,
Some(pinning),
&params,
&witness,
K,
)
.unwrap();

Expand Down Expand Up @@ -586,8 +586,8 @@ mod tests {
let circuit = SyncStepCircuit::<Testnet, Fr>::create_circuit(
CircuitBuilderStage::Prover,
Some(pinning),
&params,
&witness,
K,
)
.unwrap();

Expand Down Expand Up @@ -617,8 +617,8 @@ mod tests {
let circuit = SyncStepCircuit::<Testnet, Fr>::create_circuit(
CircuitBuilderStage::Prover,
Some(pinning),
&params,
&witness,
K,
)
.unwrap();

Expand Down
33 changes: 23 additions & 10 deletions lightclient-circuits/src/util/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use halo2_base::gates::builder::{
CircuitBuilderStage, FlexGateConfigParams, MultiPhaseThreadBreakPoints,
};
use halo2_proofs::plonk::{Circuit, Error, VerifyingKey};
use halo2_proofs::poly::commitment::Params;
use halo2_proofs::{plonk::ProvingKey, poly::kzg::commitment::ParamsKZG};
use halo2curves::bn256::{Bn256, Fr, G1Affine};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -99,8 +100,8 @@ pub trait AppCircuit: Sized {
fn create_circuit(
stage: CircuitBuilderStage,
pinning: Option<Self::Pinning>,
params: &ParamsKZG<Bn256>,
args: &Self::Witness,
k: u32,
) -> Result<impl crate::util::PinnableCircuit<Fr>, Error>;

/// Reads the proving key for the pre-circuit.
Expand All @@ -111,7 +112,7 @@ pub trait AppCircuit: Sized {
args: &Self::Witness,
) -> ProvingKey<G1Affine> {
let circuit =
Self::create_circuit(CircuitBuilderStage::Keygen, None, params, args).unwrap();
Self::create_circuit(CircuitBuilderStage::Keygen, None, args, params.k()).unwrap();
custom_read_pk(path, &circuit)
}

Expand All @@ -124,7 +125,7 @@ pub trait AppCircuit: Sized {
witness: &Self::Witness,
) -> ProvingKey<G1Affine> {
let circuit =
Self::create_circuit(CircuitBuilderStage::Keygen, None, params, witness).unwrap();
Self::create_circuit(CircuitBuilderStage::Keygen, None, witness, params.k()).unwrap();

let pk_exists = pk_path.as_ref().exists();
let pk = gen_pk(params, &circuit, Some(pk_path.as_ref()));
Expand Down Expand Up @@ -162,8 +163,12 @@ pub trait AppCircuit: Sized {
witness: &Self::Witness,
) -> Result<Snark, Error> {
let pinning = Self::Pinning::from_path(pinning_path);
let circuit =
Self::create_circuit(CircuitBuilderStage::Prover, Some(pinning), params, witness)?;
let circuit = Self::create_circuit(
CircuitBuilderStage::Prover,
Some(pinning),
witness,
params.k(),
)?;
let snark = gen_snark_shplonk(params, pk, circuit, path);

Ok(snark)
Expand All @@ -175,7 +180,7 @@ pub trait AppCircuit: Sized {
yul_path: Option<impl AsRef<Path>>,
witness: &Self::Witness,
) -> Result<Vec<u8>, Error> {
let circuit = Self::create_circuit(CircuitBuilderStage::Keygen, None, params, witness)?;
let circuit = Self::create_circuit(CircuitBuilderStage::Keygen, None, witness, params.k())?;
let deployment_code =
custom_gen_evm_verifier_shplonk(params, pk.get_vk(), &circuit, yul_path);

Expand All @@ -191,8 +196,12 @@ pub trait AppCircuit: Sized {
witness: &Self::Witness,
) -> Result<(Vec<u8>, Vec<Vec<Fr>>), Error> {
let pinning = Self::Pinning::from_path(pinning_path);
let circuit =
Self::create_circuit(CircuitBuilderStage::Prover, Some(pinning), params, witness)?;
let circuit = Self::create_circuit(
CircuitBuilderStage::Prover,
Some(pinning),
witness,
params.k(),
)?;
let instances = circuit.instances();
let proof = gen_evm_proof_shplonk(params, pk, circuit, instances.clone());

Expand All @@ -208,8 +217,12 @@ pub trait AppCircuit: Sized {
witness: &Self::Witness,
) -> Result<String, Error> {
let pinning = Self::Pinning::from_path(pinning_path);
let circuit =
Self::create_circuit(CircuitBuilderStage::Prover, Some(pinning), params, witness)?;
let circuit = Self::create_circuit(
CircuitBuilderStage::Prover,
Some(pinning),
witness,
params.k(),
)?;
let calldata = write_calldata_generic(params, pk, circuit, path, deployment_code);

Ok(calldata)
Expand Down
27 changes: 17 additions & 10 deletions lightclient-circuits/tests/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,24 @@ fn read_test_files_and_gen_witness(
}

#[rstest]
fn test_eth2_spec_mock(
fn test_eth2_spec_mock_1(
#[files("../consensus-spec-tests/tests/minimal/capella/light_client/sync/pyspec_tests/light_client_sync")]
#[exclude("deneb*")]
path: PathBuf,
) {
run_test_eth2_spec_mock::<16, 20>(path)
}

#[rstest]
fn test_eth2_spec_mock_3(
#[files("../consensus-spec-tests/tests/minimal/capella/light_client/sync/pyspec_tests/**")]
#[exclude("deneb*")]
path: PathBuf,
) {
const K_ROTATION: u32 = 18;
const K_SYNC: u32 = 21;
let params = gen_srs(K_ROTATION);
run_test_eth2_spec_mock::<17, 20>(path)
}

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 = {
Expand All @@ -384,8 +393,8 @@ fn test_eth2_spec_mock(
CommitteeUpdateCircuit::<Minimal, bn256::Fr>::create_circuit(
CircuitBuilderStage::Mock,
Some(pinning),
&params,
&rotation_witness,
K_ROTATION,
)
.unwrap()
};
Expand All @@ -400,16 +409,14 @@ fn test_eth2_spec_mock(
prover.assert_satisfied_par();
end_timer!(timer);

let params = gen_srs(K_SYNC);

let sync_circuit = {
let pinning: Eth2ConfigPinning = Eth2ConfigPinning::from_path("./config/sync_step.json");

SyncStepCircuit::<Minimal, bn256::Fr>::create_circuit(
CircuitBuilderStage::Mock,
Some(pinning),
&params,
&sync_witness,
K_SYNC,
)
.unwrap()
};
Expand Down Expand Up @@ -446,8 +453,8 @@ fn test_eth2_spec_proofgen(
let circuit = SyncStepCircuit::<Minimal, bn256::Fr>::create_circuit(
CircuitBuilderStage::Prover,
Some(pinning),
&params,
&witness,
K,
)
.unwrap();

Expand Down Expand Up @@ -481,8 +488,8 @@ fn test_eth2_spec_evm_verify(
let circuit = SyncStepCircuit::<Minimal, bn256::Fr>::create_circuit(
CircuitBuilderStage::Prover,
Some(pinning),
&params,
&witness,
K,
)
.unwrap();

Expand Down
3 changes: 1 addition & 2 deletions preprocessor/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ mod tests {
async fn test_sync_circuit_sepolia() {
const CONFIG_PATH: &str = "../lightclient-circuits/config/sync_step.json";
const K: u32 = 21;
let params = gen_srs(K);

let witness = fetch_step_args::<Testnet>("http://3.128.78.74:5052".to_string())
.await
Expand All @@ -205,8 +204,8 @@ mod tests {
let circuit = SyncStepCircuit::<Testnet, Fr>::create_circuit(
CircuitBuilderStage::Mock,
Some(pinning),
&params,
&witness,
K
)
.unwrap();

Expand Down

0 comments on commit 5e613c7

Please sign in to comment.