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

Mt refactor #135

Merged
merged 10 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
pull_request:
branches:
- main
- cap-rollup
- mt-refactor
schedule:
- cron: "0 0 * * 1"
workflow_dispatch:
Expand Down
5 changes: 0 additions & 5 deletions .license-header

This file was deleted.

20 changes: 4 additions & 16 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 10 additions & 9 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

inputs.rust-overlay.url = "github:oxalica/rust-overlay";
inputs.pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
inputs.pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs";

outputs = { self, nixpkgs, flake-utils, flake-compat, rust-overlay, pre-commit-hooks, ... }:
flake-utils.lib.eachDefaultSystem (system:
Expand Down Expand Up @@ -58,15 +59,15 @@
entry = "cargo sort -w";
pass_filenames = false;
};
license-header-c-style = {
enable = true;
description =
"Ensure files with c-style comments have license header";
entry = ''
insert_license --license-filepath .license-header --comment-style "//"'';
types_or = [ "rust" ];
pass_filenames = true;
};
# license-header-c-style = {
# enable = true;
# description =
# "Ensure files with c-style comments have license header";
# entry = ''
# insert_license --license-filepath .license-header --comment-style "//"'';
# types_or = [ "rust" ];
# pass_filenames = true;
# };
mrain marked this conversation as resolved.
Show resolved Hide resolved
};
};
};
Expand Down
5 changes: 5 additions & 0 deletions primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ itertools = { version = "0.10.1", default-features = false, features = [ "use_al
jf-relation = { path = "../relation", default-features = false }
jf-utils = { path = "../utilities" }
merlin = { version = "3.0.0", default-features = false }
num-bigint = { version = "0.4.3", default-features = false }
num-traits = { version = "0.2.15", default-features = false }
rand_chacha = { version = "0.3.1", default-features = false }
rayon = { version = "1.5.0", optional = true }
serde = { version = "1.0", default-features = false, features = ["derive"] }
sha2 = { version = "0.10.1", default-features = false }
sha3 = { version = "0.10.5", default-features = false }
typenum = { version = "1.15.0", default-features = false }
zeroize = { version = "1.3", default-features = false }

[dev-dependencies]
Expand All @@ -47,6 +51,7 @@ ark-ed-on-bn254 = "0.3.0"
bincode = "1.0"
criterion = "0.3.1"
quickcheck = "1.0.0"
hashbrown = "0.13.1"

[[bench]]
name = "merkle_path"
Expand Down
80 changes: 40 additions & 40 deletions primitives/benches/merkle_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,47 @@
#![deny(warnings)]
#[macro_use]
extern crate criterion;
use ark_ed_on_bls12_381::Fq as Fq381;
use ark_std::rand::{prelude::SliceRandom, Rng};
// use ark_ed_on_bls12_381::Fq as Fq381;
// use ark_std::rand::{prelude::SliceRandom, Rng};
use criterion::Criterion;
use jf_primitives::merkle_tree::{
MerkleLeafProof, MerklePath, MerklePathNode, MerkleTree, NodePos, NodeValue,
};
use std::time::Duration;

const BENCH_NAME: &str = "merkle_path_height_20";

fn twenty_hashes(c: &mut Criterion) {
let mut benchmark_group = c.benchmark_group(BENCH_NAME);
benchmark_group.sample_size(10);
benchmark_group.measurement_time(Duration::new(10, 0));

let mut rng = ark_std::test_rng();

let leaf: Fq381 = rng.gen();
let base: NodeValue<Fq381> = rng.gen();
let mut sibs = vec![];
for _ in 0..20 {
let pos = *[NodePos::Left, NodePos::Middle, NodePos::Right]
.choose(&mut rng)
.unwrap();
let sibling1: NodeValue<_> = rng.gen();
let sibling2: NodeValue<_> = rng.gen();
sibs.push(MerklePathNode {
sibling1,
sibling2,
pos,
});
}

let sibs = MerklePath { nodes: sibs };

let num_inputs = 0;
benchmark_group.bench_with_input(BENCH_NAME, &num_inputs, move |b, &_num_inputs| {
b.iter(|| MerkleTree::check_proof(base, 0, &MerkleLeafProof::new(leaf, sibs.clone())))
});

benchmark_group.finish();
// use jf_primitives::merkle_tree::{
// MerkleLeafProof, MerklePath, MerklePathNode, MerkleTree, NodePos,
// NodeValue, };
// use std::time::Duration;

// const BENCH_NAME: &str = "merkle_path_height_20";

fn twenty_hashes(_c: &mut Criterion) {
// let mut benchmark_group = c.benchmark_group(BENCH_NAME);
mrain marked this conversation as resolved.
Show resolved Hide resolved
// benchmark_group.sample_size(10);
// benchmark_group.measurement_time(Duration::new(10, 0));

// let mut rng = ark_std::test_rng();

// let leaf: Fq381 = rng.gen();
// let base: NodeValue<Fq381> = rng.gen();
// let mut sibs = vec![];
// for _ in 0..20 {
// let pos = *[NodePos::Left, NodePos::Middle, NodePos::Right]
// .choose(&mut rng)
// .unwrap();
// let sibling1: NodeValue<_> = rng.gen();
// let sibling2: NodeValue<_> = rng.gen();
// sibs.push(MerklePathNode {
// sibling1,
// sibling2,
// pos,
// });
// }

// let sibs = MerklePath { nodes: sibs };

// let num_inputs = 0;
// benchmark_group.bench_with_input(BENCH_NAME, &num_inputs, move |b,
// &_num_inputs| { b.iter(|| MerkleTree::check_proof(base, 0,
// &MerkleLeafProof::new(leaf, sibs.clone()))) });

// benchmark_group.finish();
}

fn bench(c: &mut Criterion) {
Expand Down
3 changes: 2 additions & 1 deletion primitives/src/circuit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
//! Circuit implementation of various crypto primitives.
pub mod commitment;
pub mod elgamal;
pub mod merkle_tree;
// TODO(Chengyu): implement merkle_tree gadgets
// pub mod merkle_tree;
pub mod prf;
pub mod rescue;
pub mod signature;
Loading