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 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
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:
pull_request:
branches:
- main
- cap-rollup
schedule:
- cron: "0 0 * * 1"
workflow_dispatch:
Expand Down
5 changes: 0 additions & 5 deletions .license-header

This file was deleted.

13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,17 @@
- Primitive gadgets, including `commitment`, `el gamal` etc. remains in `jf-primitives/circuit`.
- Circuit for rescue hash function is now in `jf-primitives/circuit/rescue`.
- `par-utils` is moved to `jf-utils`.
- Introduct new `PolynomialCommitmentScheme` trait and basic implementations
- Now `PlonkKzgSnark` use our own KZG10 implementation
- Introduct new `PolynomialCommitmentScheme` trait and basic implementations.
- Now `PlonkKzgSnark` use our own KZG10 implementation.
- Merkle tree is refactored (#135)
- Introduce new traits which define the functionalities.
- `MerkleTreeScheme` is the abstraction of a static array accumulator,
- `AppendableMerkleTreeScheme` is the abstraction of an appendable vector accumulator.
- `UniversalMerkleTreeScheme` is the abstraction of a key-value map accumulator, which also supports non-membership query/proof.
- `ForgetableMerkleTreeScheme` allows you to forget/remember some leafs from the memory.
- Implementation of new generic merkle tree: `MerkleTree` and `UniversalMerkleTree`
- A default rate-3 rescue merkle tree implementation is provided in `prelude` module.
- Other example instantiation can be found in `example` module.

## v0.1.2

Expand Down
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.

10 changes: 1 addition & 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,6 @@
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;
};
};
};
};
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 }
tagged-base64 = { git = "https://github.com/espressosystems/tagged-base64", tag = "0.2.4" }
zeroize = { version = "1.3", default-features = false }

Expand All @@ -48,6 +52,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
28 changes: 6 additions & 22 deletions primitives/benches/merkle_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
#[macro_use]
extern crate criterion;
use ark_ed_on_bls12_381::Fq as Fq381;
use ark_std::rand::{prelude::SliceRandom, Rng};
use ark_std::rand::Rng;
use criterion::Criterion;
use jf_primitives::merkle_tree::{
MerkleLeafProof, MerklePath, MerklePathNode, MerkleTree, NodePos, NodeValue,
};
use jf_primitives::merkle_tree::{prelude::RescueMerkleTree, MerkleTreeScheme};
use std::time::Duration;

const BENCH_NAME: &str = "merkle_path_height_20";
Expand All @@ -25,28 +23,14 @@ fn twenty_hashes(c: &mut Criterion) {
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 mt = RescueMerkleTree::<Fq381>::from_elems(20, &[leaf, leaf]).unwrap();
let (_, proof) = mt.lookup(0).expect_ok().unwrap();

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())))
b.iter(|| mt.verify(0, &proof).unwrap())
});

benchmark_group.finish();
}

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