Skip to content

Commit

Permalink
Revisit CI: Formatting + CI steps (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzejkop committed Sep 20, 2024
1 parent 7b9b02c commit 060e883
Show file tree
Hide file tree
Showing 13 changed files with 226 additions and 220 deletions.
20 changes: 9 additions & 11 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ jobs:
test:
name: Test
runs-on: ubuntu-latest
env:
RUSTFLAGS: "-D warnings"
steps:
- name: Checkout Repository
uses: actions/checkout@v4
Expand All @@ -20,41 +22,37 @@ jobs:
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.toml') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Cache Cargo index
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.toml') }}
restore-keys: |
${{ runner.os }}-cargo-index-
- name: Cache Cargo build
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.toml') }}
restore-keys: |
${{ runner.os }}-cargo-build-
- name: Check
run: cargo check

- name: Check (workspace & tests)
run: cargo check --workspace --tests

- name: Check (workspace, tests, benches & all features)
run: cargo check --workspace --tests --benches --all-features

- name: Check Formatting
run: echo "Formatting temporarily disabled"
# run: cargo fmt --all -- --check
run: cargo fmt --all -- --check

- name: Run Clippy
run: cargo clippy --all-targets --all-features

- name: Run test
run: cargo test --workspace --all-features
# vet:
# name: Vet Dependencies
# runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions benches/cascading_merkle_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ criterion_group!(
);

struct TreeValues<H: Hasher> {
depth: usize,
empty_value: H::Hash,
depth: usize,
empty_value: H::Hash,
initial_values: Vec<H::Hash>,
}

Expand Down
6 changes: 3 additions & 3 deletions benches/lazy_merkle_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ criterion_group!(
);

struct TreeValues<H: Hasher> {
depth: usize,
prefix_depth: usize,
empty_value: H::Hash,
depth: usize,
prefix_depth: usize,
empty_value: H::Hash,
initial_values: Vec<H::Hash>,
}

Expand Down
1 change: 1 addition & 0 deletions crates/ark-zkey/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "ark-zkey"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
color-eyre = "0.6"
Expand Down
4 changes: 2 additions & 2 deletions crates/ark-zkey/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ pub fn convert_zkey(
) -> Result<()> {
let arkzkey_file_path = PathBuf::from(arkzkey_path);

let mut file =
File::create(&arkzkey_file_path).wrap_err("Failed to create serialized proving key file")?;
let mut file = File::create(&arkzkey_file_path)
.wrap_err("Failed to create serialized proving key file")?;

proving_key
.serialize_compressed(&mut file)
Expand Down
6 changes: 2 additions & 4 deletions crates/semaphore-depth-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,16 @@ use syn::{
/// ```
/// with `depth_16` and `depth_30` features active will generate the following
/// code:
/// ```
/// ```no_run
/// fn test_depth_non_zero(depth: usize) {
/// assert!(depth > 0);
/// }
///
/// # #[no_run]
/// #[test]
/// fn test_depth_non_zero_depth_16() {
/// test_depth_non_zero(16);
/// }
///
/// # #[no_run]
/// #[test]
/// fn test_depth_non_zero_depth_30() {
/// test_depth_non_zero(30);
Expand Down Expand Up @@ -65,7 +63,7 @@ pub fn test_all_depths(_attr: TokenStream, item: TokenStream) -> TokenStream {
#[derive(Debug)]
struct ArrayForDepthsInput {
replaced_ident: Ident,
expr: syn::Expr,
expr: syn::Expr,
}

#[derive(Debug)]
Expand Down
19 changes: 0 additions & 19 deletions rustfmt.toml

This file was deleted.

159 changes: 90 additions & 69 deletions src/cascading_merkle_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ pub struct CascadingMerkleTree<H, S = Vec<<H as Hasher>::Hash>>
where
H: Hasher,
{
depth: usize,
root: H::Hash,
empty_value: H::Hash,
depth: usize,
root: H::Hash,
empty_value: H::Hash,
sparse_column: Vec<H::Hash>,
storage: S,
_marker: std::marker::PhantomData<H>,
storage: S,
_marker: std::marker::PhantomData<H>,
}

impl<H, S> CascadingMerkleTree<H, S>
Expand Down Expand Up @@ -678,12 +678,12 @@ mod tests {
let leaves = vec![1; num_leaves];
let tree = CascadingMerkleTree::<TestHasher>::new_with_leaves(vec![], 10, &0, &leaves);
let expected = CascadingMerkleTree::<TestHasher> {
depth: 10,
root: 5,
empty_value: 0,
depth: 10,
root: 5,
empty_value: 0,
sparse_column: vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
storage: vec![5, 1, 2, 1, 4, 2, 1, 1, 5, 1, 1, 0, 1, 0, 0, 0],
_marker: std::marker::PhantomData,
storage: vec![5, 1, 2, 1, 4, 2, 1, 1, 5, 1, 1, 0, 1, 0, 0, 0],
_marker: std::marker::PhantomData,
};
debug_tree(&tree);
tree.validate().unwrap();
Expand All @@ -697,12 +697,12 @@ mod tests {
let empty = 0;
let tree = CascadingMerkleTree::<TestHasher>::new_with_leaves(vec![], 10, &empty, &leaves);
let expected = CascadingMerkleTree::<TestHasher> {
depth: 10,
root: 8,
empty_value: 0,
depth: 10,
root: 8,
empty_value: 0,
sparse_column: vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
storage: vec![8, 1, 2, 1, 4, 2, 1, 1, 8, 4, 2, 2, 1, 1, 1, 1],
_marker: std::marker::PhantomData,
storage: vec![8, 1, 2, 1, 4, 2, 1, 1, 8, 4, 2, 2, 1, 1, 1, 1],
_marker: std::marker::PhantomData,
};
debug_tree(&tree);
tree.validate().unwrap();
Expand All @@ -715,12 +715,12 @@ mod tests {
let empty = 0;
let tree = CascadingMerkleTree::<TestHasher>::new_with_leaves(vec![], 10, &empty, &leaves);
let expected = CascadingMerkleTree::<TestHasher> {
depth: 10,
root: 0,
empty_value: 0,
depth: 10,
root: 0,
empty_value: 0,
sparse_column: vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
storage: vec![0, 0],
_marker: std::marker::PhantomData,
storage: vec![0, 0],
_marker: std::marker::PhantomData,
};
debug_tree(&tree);
tree.validate().unwrap();
Expand All @@ -733,12 +733,12 @@ mod tests {
let empty = 1;
let tree = CascadingMerkleTree::<TestHasher>::new_with_leaves(vec![], 10, &empty, &leaves);
let expected = CascadingMerkleTree::<TestHasher> {
depth: 10,
root: 1024,
empty_value: 1,
depth: 10,
root: 1024,
empty_value: 1,
sparse_column: vec![1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],
storage: vec![0, 1],
_marker: std::marker::PhantomData,
storage: vec![0, 1],
_marker: std::marker::PhantomData,
};
debug_tree(&tree);
tree.validate().unwrap();
Expand All @@ -752,12 +752,12 @@ mod tests {
let empty = 1;
let tree = CascadingMerkleTree::<TestHasher>::new_with_leaves(vec![], 4, &empty, &leaves);
let expected = CascadingMerkleTree::<TestHasher> {
depth: 4,
root: 8,
empty_value: 1,
depth: 4,
root: 8,
empty_value: 1,
sparse_column: vec![1, 2, 4, 8, 16],
storage: vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
_marker: std::marker::PhantomData,
storage: vec![8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
_marker: std::marker::PhantomData,
};
debug_tree(&tree);
tree.validate().unwrap();
Expand Down Expand Up @@ -820,9 +820,12 @@ mod tests {
tree.validate().unwrap();
debug_tree(&tree);
let expected = vec![
(0, vec![
1usize, 3, 6, 7, 12, 13, 14, 15, 24, 25, 26, 27, 28, 29, 30, 31,
]),
(
0,
vec![
1usize, 3, 6, 7, 12, 13, 14, 15, 24, 25, 26, 27, 28, 29, 30, 31,
],
),
(1, vec![2, 5, 10, 11, 20, 21, 22, 23]),
(2, vec![4, 9, 18, 19]),
(3, vec![8, 17]),
Expand Down Expand Up @@ -870,42 +873,60 @@ mod tests {
debug_tree(&tree);
tree.validate().unwrap();
let expected = vec![
(1, vec![
Branch::Left(2),
Branch::Left(7),
Branch::Left(13),
Branch::Left(8),
]),
(2, vec![
Branch::Right(1),
Branch::Left(7),
Branch::Left(13),
Branch::Left(8),
]),
(3, vec![
Branch::Left(4),
Branch::Right(3),
Branch::Left(13),
Branch::Left(8),
]),
(4, vec![
Branch::Right(3),
Branch::Right(3),
Branch::Left(13),
Branch::Left(8),
]),
(5, vec![
Branch::Left(6),
Branch::Left(2),
Branch::Right(10),
Branch::Left(8),
]),
(6, vec![
Branch::Right(5),
Branch::Left(2),
Branch::Right(10),
Branch::Left(8),
]),
(
1,
vec![
Branch::Left(2),
Branch::Left(7),
Branch::Left(13),
Branch::Left(8),
],
),
(
2,
vec![
Branch::Right(1),
Branch::Left(7),
Branch::Left(13),
Branch::Left(8),
],
),
(
3,
vec![
Branch::Left(4),
Branch::Right(3),
Branch::Left(13),
Branch::Left(8),
],
),
(
4,
vec![
Branch::Right(3),
Branch::Right(3),
Branch::Left(13),
Branch::Left(8),
],
),
(
5,
vec![
Branch::Left(6),
Branch::Left(2),
Branch::Right(10),
Branch::Left(8),
],
),
(
6,
vec![
Branch::Right(5),
Branch::Left(2),
Branch::Right(10),
Branch::Left(8),
],
),
];
for (leaf, expected_proof) in expected {
let proof = tree.proof_from_hash(leaf).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use ark_bn254::{Bn254, Fr};
use ark_groth16::ProvingKey;
use ark_relations::r1cs::ConstraintMatrices;
use once_cell::sync::Lazy;

use semaphore_depth_config::{get_depth_index, get_supported_depth_count};
use semaphore_depth_macros::array_for_depths;

Expand All @@ -29,5 +28,6 @@ pub fn zkey(depth: usize) -> &'static (ProvingKey<Bn254>, ConstraintMatrices<Fr>
#[must_use]
pub fn graph(depth: usize) -> &'static [u8] {
let index = get_depth_index(depth).unwrap_or_else(|| panic!("depth {depth} is not supported"));
&GRAPH_BYTES[index]

GRAPH_BYTES[index]
}
Loading

0 comments on commit 060e883

Please sign in to comment.