Skip to content

Commit

Permalink
License & docs (#48)
Browse files Browse the repository at this point in the history
* use max lookup bits for circuit degree

* remove y coord check

* tweak poseidon

* half number of poseidon hash inputs

* add step aggregation

* remove committee poseidon from pi commit in contracts

* tweak circuit accordingly

* re-gen step verifier sol

* update tests

* post merge fixes

* cargo fix

* cargo fix + fmt

* cargo fix + fmt

* Add new cli

* regenerate committee update contract

* add new rpc

* support compressed step verifier in contracts

* gen verifier contracts

* add license

* update deployment scripts

* cargo fix

* remove sync_step.sol

* add .licensesnip file

* docs (WIP)

* docs (WIP)

* docs & refactoring

* docs (WIP)

* add license headers
  • Loading branch information
nulltea authored Dec 14, 2023
1 parent 7fb8fb5 commit 94208af
Show file tree
Hide file tree
Showing 71 changed files with 1,223 additions and 912 deletions.
3 changes: 3 additions & 0 deletions .licensesnip
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The Licensed Work is (c) 2023 ChainSafe
Code: https://github.com/ChainSafe/Spectre
SPDX-License-Identifier: LGPL-3.0-only
681 changes: 671 additions & 10 deletions LICENSE

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions contract-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// The Licensed Work is (c) 2023 ChainSafe
// Code: https://github.com/ChainSafe/Spectre
// SPDX-License-Identifier: LGPL-3.0-only

use ethers::{
core::utils::{Anvil, AnvilInstance},
middleware::SignerMiddleware,
Expand Down
10 changes: 7 additions & 3 deletions contract-tests/tests/rotation_input_encoding.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// The Licensed Work is (c) 2023 ChainSafe
// Code: https://github.com/ChainSafe/Spectre
// SPDX-License-Identifier: LGPL-3.0-only

#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

Expand All @@ -11,7 +15,7 @@ use itertools::Itertools;
use lightclient_circuits::committee_update_circuit::CommitteeUpdateCircuit;
use lightclient_circuits::halo2_proofs::halo2curves::bn256;
use lightclient_circuits::poseidon::poseidon_committee_commitment_from_compressed;
use lightclient_circuits::witness::CommitteeRotationArgs;
use lightclient_circuits::witness::CommitteeUpdateArgs;
use rstest::rstest;
use ssz_rs::prelude::*;
use ssz_rs::Merkleized;
Expand All @@ -24,11 +28,11 @@ abigen!(
);

// CommitteeRotationArgs type produced by abigen macro matches the solidity struct type
impl<Spec: eth_types::Spec> From<CommitteeRotationArgs<Spec>> for RotateInput
impl<Spec: eth_types::Spec> From<CommitteeUpdateArgs<Spec>> for RotateInput
where
[(); Spec::SYNC_COMMITTEE_SIZE]:,
{
fn from(args: CommitteeRotationArgs<Spec>) -> Self {
fn from(args: CommitteeUpdateArgs<Spec>) -> Self {
let poseidon_commitment = poseidon_committee_commitment_from_compressed(
&args.pubkeys_compressed.iter().cloned().collect_vec(),
);
Expand Down
4 changes: 4 additions & 0 deletions contract-tests/tests/spectre.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// The Licensed Work is (c) 2023 ChainSafe
// Code: https://github.com/ChainSafe/Spectre
// SPDX-License-Identifier: LGPL-3.0-only

/**
* These are the highest level integration tests for the Spectre protocol
* They treat the Spectre contract as an ethereum light-client and test against the spec
Expand Down
4 changes: 4 additions & 0 deletions contract-tests/tests/step_input_encoding.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// The Licensed Work is (c) 2023 ChainSafe
// Code: https://github.com/ChainSafe/Spectre
// SPDX-License-Identifier: LGPL-3.0-only

use std::ops::Deref;
use std::path::PathBuf;

Expand Down
10 changes: 7 additions & 3 deletions contracts/rust-abi/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
// The Licensed Work is (c) 2023 ChainSafe
// Code: https://github.com/ChainSafe/Spectre
// SPDX-License-Identifier: LGPL-3.0-only

#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
use ethers::{contract::abigen, types::U256};
use itertools::Itertools;
use lightclient_circuits::{
poseidon::poseidon_committee_commitment_from_compressed,
witness::{CommitteeRotationArgs, SyncStepArgs},
witness::{CommitteeUpdateArgs, SyncStepArgs},
};
use ssz_rs::{Merkleized, Vector};
use std::ops::Deref;
Expand Down Expand Up @@ -63,11 +67,11 @@ impl SyncStepInput {
}

// CommitteeRotationArgs type produced by abigen macro matches the solidity struct type
impl<Spec: eth_types::Spec> From<CommitteeRotationArgs<Spec>> for RotateInput
impl<Spec: eth_types::Spec> From<CommitteeUpdateArgs<Spec>> for RotateInput
where
[(); Spec::SYNC_COMMITTEE_SIZE]:,
{
fn from(args: CommitteeRotationArgs<Spec>) -> Self {
fn from(args: CommitteeUpdateArgs<Spec>) -> Self {
let sync_committee_poseidon = poseidon_committee_commitment_from_compressed(
&args.pubkeys_compressed.iter().cloned().collect_vec(),
);
Expand Down
4 changes: 4 additions & 0 deletions contracts/script/deploy_local.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 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: 4 additions & 0 deletions contracts/script/deploy_testnet.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 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
5 changes: 5 additions & 0 deletions eth-types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// The Licensed Work is (c) 2023 ChainSafe
// Code: https://github.com/ChainSafe/Spectre
// SPDX-License-Identifier: LGPL-3.0-only

#![allow(incomplete_features)]
#![feature(associated_type_bounds)]
#![feature(associated_type_defaults)]
Expand All @@ -11,4 +15,5 @@ pub use spec::{Mainnet, Minimal, Spec, Testnet};
pub const NUM_LIMBS: usize = 4;
pub const LIMB_BITS: usize = 104;

/// The field used in circuits.
pub trait Field = BigPrimeField + PrimeField<Repr = [u8; 32]>;
5 changes: 5 additions & 0 deletions eth-types/src/spec.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// The Licensed Work is (c) 2023 ChainSafe
// Code: https://github.com/ChainSafe/Spectre
// SPDX-License-Identifier: LGPL-3.0-only

use core::fmt::Debug;

/// Beacon chain specification.
pub trait Spec: 'static + Sized + Copy + Default + Debug {
const SYNC_COMMITTEE_SIZE: usize;
const SYNC_COMMITTEE_ROOT_INDEX: usize;
Expand Down
31 changes: 0 additions & 31 deletions lightclient-circuits/config/committee_update_18.json

This file was deleted.

31 changes: 0 additions & 31 deletions lightclient-circuits/config/committee_update_mainnet.json

This file was deleted.

15 changes: 5 additions & 10 deletions lightclient-circuits/config/committee_update_testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,25 @@
"params": {
"k": 18,
"num_advice_per_phase": [
12
7
],
"num_fixed": 1,
"num_lookup_advice_per_phase": [
1,
0,
0
],
"lookup_bits": 8,
"lookup_bits": 17,
"num_instance_columns": 1
},
"break_points": [
[
262134,
262132,
262134,
262132,
262133,
262132,
262132,
262134,
262133,
262132,
262134,
262133
262134
]
]
}
}
12 changes: 0 additions & 12 deletions lightclient-circuits/config/committee_update_verifier_25.json

This file was deleted.

12 changes: 0 additions & 12 deletions lightclient-circuits/config/committee_update_verifier_mainnet.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"break_points": [
[]
]
}
}
40 changes: 0 additions & 40 deletions lightclient-circuits/config/sync_step_20.json

This file was deleted.

25 changes: 0 additions & 25 deletions lightclient-circuits/config/sync_step_22.json

This file was deleted.

25 changes: 0 additions & 25 deletions lightclient-circuits/config/sync_step_mainnet.json

This file was deleted.

15 changes: 9 additions & 6 deletions lightclient-circuits/config/sync_step_testnet.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
{
"params": {
"k": 22,
"k": 21,
"num_advice_per_phase": [
3
6
],
"num_fixed": 1,
"num_lookup_advice_per_phase": [
1,
0,
0
],
"lookup_bits": 21,
"lookup_bits": 20,
"num_instance_columns": 1
},
"break_points": [
[
4194294,
4194294
2097142,
2097142,
2097140,
2097142,
2097142
]
]
}
}
Loading

0 comments on commit 94208af

Please sign in to comment.