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

Optimized aggregation #49

Merged
merged 4 commits into from
Dec 15, 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
5 changes: 4 additions & 1 deletion contracts/script/DeploySpectre.s.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// SPDX-License-Identifier: MIT
// The Licensed Work is (c) 2023 ChainSafe
// Code: https://github.com/ChainSafe/Spectre
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity ^0.8.0;

import "forge-std/Script.sol";
Expand Down
5 changes: 4 additions & 1 deletion contracts/script/DeploySpectreTestnet.s.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// SPDX-License-Identifier: MIT
// The Licensed Work is (c) 2023 ChainSafe
// Code: https://github.com/ChainSafe/Spectre
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity ^0.8.0;

import "forge-std/Script.sol";
Expand Down
4 changes: 0 additions & 4 deletions contracts/script/deploy_local.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# The Licensed Work is (c) 2023 ChainSafe
# Code: https://github.com/ChainSafe/Spectre
# SPDX-License-Identifier: LGPL-3.0-only

#!/bin/sh
cd $(git rev-parse --show-toplevel)
source .env
Expand Down
4 changes: 0 additions & 4 deletions contracts/script/deploy_testnet.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# The Licensed Work is (c) 2023 ChainSafe
# Code: https://github.com/ChainSafe/Spectre
# SPDX-License-Identifier: LGPL-3.0-only

#!/bin/sh
cd $(git rev-parse --show-toplevel)
source .env
Expand Down
4 changes: 2 additions & 2 deletions contracts/snark-verifiers/committee_update_verifier.sol

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/snark-verifiers/sync_step_verifier.sol

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion contracts/src/EndianConversions.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// SPDX-License-Identifier: MIT
// The Licensed Work is (c) 2023 ChainSafe
// Code: https://github.com/ChainSafe/Spectre
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity ^0.8.0;

library EndianConversions {
Expand Down
5 changes: 4 additions & 1 deletion contracts/src/RotateLib.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// SPDX-License-Identifier: MIT
// The Licensed Work is (c) 2023 ChainSafe
// Code: https://github.com/ChainSafe/Spectre
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity ^0.8.0;

import { EndianConversions } from "./EndianConversions.sol";
Expand Down
5 changes: 4 additions & 1 deletion contracts/src/Spectre.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// SPDX-License-Identifier: MIT
// The Licensed Work is (c) 2023 ChainSafe
// Code: https://github.com/ChainSafe/Spectre
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity ^0.8.0;

import {SyncStepLib} from "./SyncStepLib.sol";
Expand Down
5 changes: 4 additions & 1 deletion contracts/src/SyncStepLib.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// SPDX-License-Identifier: MIT
// The Licensed Work is (c) 2023 ChainSafe
// Code: https://github.com/ChainSafe/Spectre
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity ^0.8.0;

import { EndianConversions } from "./EndianConversions.sol";
Expand Down
5 changes: 4 additions & 1 deletion contracts/src/interfaces/CommitteeUpdateVerifier.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// SPDX-License-Identifier: MIT
// The Licensed Work is (c) 2023 ChainSafe
// Code: https://github.com/ChainSafe/Spectre
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity ^0.8.0;

interface CommitteeUpdateVerifier {
Expand Down
5 changes: 4 additions & 1 deletion contracts/src/interfaces/SyncStepVerifier.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// SPDX-License-Identifier: MIT
// The Licensed Work is (c) 2023 ChainSafe
// Code: https://github.com/ChainSafe/Spectre
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity ^0.8.0;

interface SyncStepVerifier {
Expand Down
5 changes: 4 additions & 1 deletion contracts/src/mocks/CommitteeUpdateMockVerifier.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@

// SPDX-License-Identifier: MIT
// The Licensed Work is (c) 2023 ChainSafe
// Code: https://github.com/ChainSafe/Spectre
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity ^0.8.0;

import { CommitteeUpdateVerifier } from "../interfaces/CommitteeUpdateVerifier.sol";
Expand Down
5 changes: 4 additions & 1 deletion contracts/src/mocks/SyncStepMockVerifier.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@

// SPDX-License-Identifier: MIT
// The Licensed Work is (c) 2023 ChainSafe
// Code: https://github.com/ChainSafe/Spectre
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity ^0.8.0;

import { SyncStepVerifier, SyncStepCompressedVerifier } from "../interfaces/SyncStepVerifier.sol";
Expand Down
5 changes: 4 additions & 1 deletion contracts/test/RotateExternal.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// SPDX-License-Identifier: MIT
// The Licensed Work is (c) 2023 ChainSafe
// Code: https://github.com/ChainSafe/Spectre
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity 0.8.19;

import { RotateLib } from "../src/RotateLib.sol";
Expand Down
5 changes: 4 additions & 1 deletion contracts/test/SyncStepExternal.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// SPDX-License-Identifier: MIT
// The Licensed Work is (c) 2023 ChainSafe
// Code: https://github.com/ChainSafe/Spectre
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity 0.8.19;

import {SyncStepLib} from "../src/SyncStepLib.sol";
Expand Down
16 changes: 8 additions & 8 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ setup-step network *k='22':
cargo run -r -- circuit sync-step -p ./build/sync_step_$1.pkey -k $2 setup

setup-step-compressed network *k='23':
cargo run -r -- circuit sync-step-compressed -p ./build/sync_step_$1.pkey -k 21 \
--verifier-k $2 --verifier-pk-path ./build/sync_step_verifier_$1.pkey setup
cargo run -r -- circuit sync-step-compressed -k 20 -p ./build/sync_step_$1.pkey \
-K $2 -P ./build/sync_step_verifier_$1.pkey -L 19 setup

setup-committee-update network *k='25':
cargo run -r -- circuit committee-update -p ./build/committee_update_$1.pkey -k 18 \
--verifier-k $2 --verifier-pk-path ./build/committee_update_verifier_$1.pkey setup
setup-committee-update network *k='24':
cargo run -r -- circuit committee-update -k 20 -p ./build/committee_update_$1.pkey \
-K $2 -P ./build/committee_update_verifier_$1.pkey setup

gen-verifier-step network:
cargo run -r -- circuit sync-step -p ./build/sync_step_$1.pkey gen-verifier -o ./contracts/snark-verifiers/sync_step.sol

gen-verifier-step-compressed network:
cargo run -r -- circuit sync-step-compressed -p ./build/sync_step_$1.pkey --verifier-pk-path ./build/sync_step_verifier_$1.pkey \
cargo run -r -- circuit sync-step-compressed -p ./build/sync_step_$1.pkey -P ./build/sync_step_verifier_$1.pkey \
gen-verifier -o ./contracts/snark-verifiers/sync_step_verifier.sol

gen-verifier-committee-update network:
cargo run -r -- circuit committee-update -p ./build/committee_update_$1.pkey --verifier-pk-path ./build/committee_update_verifier_$1.pkey \
cargo run -r -- circuit committee-update -p ./build/committee_update_$1.pkey -P ./build/committee_update_verifier_$1.pkey \
gen-verifier -o ./contracts/snark-verifiers/committee_update_verifier.sol

build-contracts:
Expand All @@ -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
15 changes: 5 additions & 10 deletions lightclient-circuits/config/committee_update_testnet.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
{
"params": {
"k": 18,
"k": 20,
"num_advice_per_phase": [
7
2
],
"num_fixed": 1,
"num_lookup_advice_per_phase": [
1,
0,
0
],
"lookup_bits": 17,
"lookup_bits": 19,
"num_instance_columns": 1
},
"break_points": [
[
262134,
262134,
262134,
262133,
262134,
262134
1048566
]
]
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"params": {
"degree": 25,
"degree": 24,
"num_advice": 1,
"num_lookup_advice": 1,
"num_fixed": 1,
"lookup_bits": 8
"lookup_bits": 23
},
"break_points": [
[]
]
}
}
26 changes: 16 additions & 10 deletions lightclient-circuits/config/sync_step_testnet.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
{
"params": {
"k": 21,
"k": 20,
"num_advice_per_phase": [
6
12
],
"num_fixed": 1,
"num_lookup_advice_per_phase": [
1,
2,
0,
0
],
"lookup_bits": 20,
"lookup_bits": 19,
"num_instance_columns": 1
},
"break_points": [
[
2097142,
2097142,
2097140,
2097142,
2097142
1048566,
1048564,
1048566,
1048566,
1048565,
1048566,
1048566,
1048566,
1048564,
1048566,
1048566
]
]
}
}
22 changes: 11 additions & 11 deletions lightclient-circuits/config/sync_step_verifier_testnet.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"params": {
"degree": 23,
"num_advice": 1,
"num_lookup_advice": 1,
"num_fixed": 1,
"lookup_bits": 8
},
"break_points": [
[]
]
}
"params": {
"degree": 23,
"num_advice": 1,
"num_lookup_advice": 1,
"num_fixed": 1,
"lookup_bits": 19
},
"break_points": [
[]
]
}
32 changes: 23 additions & 9 deletions lightclient-circuits/src/aggregation_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
use crate::util::{AppCircuit, Halo2ConfigPinning, PinnableCircuit};
use halo2_base::{
gates::{circuit::CircuitBuilderStage, flex_gate::MultiPhaseThreadBreakPoints},
halo2_proofs::{halo2curves::bn256::Fr, plonk::Error},
utils::fs::gen_srs,
halo2_proofs::{
halo2curves::bn256::{Bn256, Fr},
plonk::Error,
poly::{commitment::Params, kzg::commitment::ParamsKZG},
},
};
use serde::{Deserialize, Serialize};
use snark_verifier_sdk::{
Expand All @@ -20,12 +23,25 @@ use std::{
};

/// Configuration for the aggregation circuit.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct AggregationConfigPinning {
pub params: AggregationConfigParams,
pub break_points: MultiPhaseThreadBreakPoints,
}

impl AggregationConfigPinning {
pub fn new(k: u32, lookup_bits: usize) -> Self {
Self {
params: AggregationConfigParams {
degree: k,
lookup_bits,
..Default::default()
},
..Default::default()
}
}
}

impl Halo2ConfigPinning for AggregationConfigPinning {
type BreakPoints = MultiPhaseThreadBreakPoints;

Expand Down Expand Up @@ -82,22 +98,20 @@ impl AppCircuit for AggregationCircuit {
stage: CircuitBuilderStage,
pinning: Option<Self::Pinning>,
snark: &Self::Witness,
k: u32,
params: &ParamsKZG<Bn256>,
) -> Result<impl crate::util::PinnableCircuit<Fr>, Error> {
let lookup_bits = k as usize - 1;
let params = gen_srs(k);
let circuit_params = pinning.clone().map_or(
AggregationConfigParams {
degree: k,
lookup_bits,
degree: params.k(),
lookup_bits: params.k() as usize - 1,
..Default::default()
},
|p| p.params,
);
let mut circuit = AggregationCircuit::new::<SHPLONK>(
stage,
circuit_params,
&params,
params,
snark.clone(),
Default::default(),
);
Expand Down
Loading
Loading