Skip to content

Commit

Permalink
Add CHANGELOG and several housekeeping files (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
weikengchen authored Jun 5, 2021
1 parent 1223fe4 commit 786ef7f
Show file tree
Hide file tree
Showing 19 changed files with 222 additions and 77 deletions.
14 changes: 14 additions & 0 deletions .github/.markdownlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# See https://github.com/DavidAnson/markdownlint#rules--aliases for list of markdown lint codes
default: true
# MD01 lint blocks having header's incrementing by more than # at a time.
MD001: false
MD007: { indent: 4 }
# MD013 blocks long lines
MD013: false
MD024: { siblings_only: true }
MD025: false
# MD033 lint blocks HTML in MD
MD033: false
# MD036 no-emphasis-as-heading
MD036: false
MD041: false
26 changes: 26 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!-- < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < ☺
v ✰ Thanks for creating a PR! ✰
v Before hitting that submit button please review the checkboxes.
v If a checkbox is n/a - please still include it but + a little note why
☺ > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -->

## Description

<!-- Add a description of the changes that this PR introduces and the files that
are the most critical to review.
-->

closes: #XXXX

---

Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

- [ ] Targeted PR against correct branch (main)
- [ ] Linked to Github issue with discussion and accepted design OR have an explanation in the PR that describes this work.
- [ ] Wrote unit tests
- [ ] Updated relevant documentation in the code
- [ ] Added a relevant changelog entry to the `Pending` section in `CHANGELOG.md`
- [ ] Re-reviewed `Files changed` in the Github PR explorer
20 changes: 20 additions & 0 deletions .github/workflows/linkify_changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Linkify Changelog

on:
workflow_dispatch

jobs:
linkify:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Add links
run: python3 scripts/linkify_changelog.py CHANGELOG.md
- name: Commit
run: |
git config user.name github-actions
git config user.email [email protected]
git add .
git commit -m "Linkify Changelog"
git push
34 changes: 34 additions & 0 deletions .github/workflows/mdlinter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Lint
on:
push:
branches:
- master
paths:
- "**.md"
pull_request:
paths:
- "**.md"

jobs:
build:
name: Markdown linter
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Lint Code Base
uses: docker://github/super-linter:latest
env:
LINTER_RULES_PATH: .github
VALIDATE_ALL_CODEBASE: true
DEFAULT_BRANCH: master
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VALIDATE_MD: true
MARKDOWN_CONFIG_FILE: .markdownlint.yml
VALIDATE_PROTOBUF: false
VALIDATE_JSCPD: false
# use Python Pylint as the only linter to avoid conflicts
VALIDATE_PYTHON_BLACK: false
VALIDATE_PYTHON_FLAKE8: false
VALIDATE_PYTHON_ISORT: false
VALIDATE_PYTHON_MYPY: false
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## Pending

### Breaking changes

- [\#30](https://github.com/arkworks-rs/crypto-primitives/pull/30) Refactor the Merkle tree to separate the leaf hash and two-to-one hash.

### Features

- [\#38](https://github.com/arkworks-rs/crypto-primitives/pull/38) Add a signature verification trait `SigVerifyGadget`.
- [\#44](https://github.com/arkworks-rs/crypto-primitives/pull/44) Add basic ElGamal encryption gadgets.
- [\#48](https://github.com/arkworks-rs/crypto-primitives/pull/48) Add `CanonicalSerialize` and `CanonicalDeserialize` to `Path` and `CRH` outputs.

### Improvements

### Bug fixes

## v0.2.0

### Breaking changes

### Features

- [\#2](https://github.com/arkworks-rs/crypto-primitives/pull/2) Add the `SNARK` gadget traits.
- [\#3](https://github.com/arkworks-rs/crypto-primitives/pull/3) Add unchecked allocation for `ProofVar` and `VerifyingKeyVar`.
- [\#4](https://github.com/arkworks-rs/crypto-primitives/pull/4) Add `verifier_size` to `SNARKGadget`.
- [\#6](https://github.com/arkworks-rs/crypto-primitives/pull/6) Add `IntoIterator` for SNARK input gadgets.
- [\#28](https://github.com/arkworks-rs/crypto-primitives/pull/28) Adds Poseidon CRH w/ constraints.

### Improvements

### Bug fixes

## v0.1.0 (Initial release of arkworks/crypto-primitives)
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@ This library is released under the MIT License and the Apache v2 License (see [L
## Build guide

The library compiles on the `stable` toolchain of the Rust compiler. To install the latest version of Rust, first install `rustup` by following the instructions [here](https://rustup.rs/), or via your platform's package manager. Once `rustup` is installed, install the Rust toolchain by invoking:

```bash
rustup install stable
```

After that, use `cargo`, the standard Rust build tool, to build the library:

```bash
git clone https://github.com/arkworks-rs/crypto-primitives.git
cargo build --release
```

This library comes with unit tests for each of the provided crates. Run the tests with:

```bash
cargo test
```
Expand All @@ -35,8 +38,8 @@ cargo test

This library is licensed under either of the following licenses, at your discretion.

* Apache License Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
* Apache License Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or [apache.org license link](http://www.apache.org/licenses/LICENSE-2.0))
* MIT license ([LICENSE-MIT](LICENSE-MIT) or [opensource.org license link](http://opensource.org/licenses/MIT))

Unless you explicitly state otherwise, any contribution submitted for inclusion in this library by you shall be dual licensed as above (as defined in the Apache v2 License), without any additional terms or conditions.

Expand Down
6 changes: 4 additions & 2 deletions cp-benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ edition = "2018"
################################# Dependencies ################################

[dev-dependencies]
ark-ed-on-bls12-377 = { git = "https://github.com/arkworks-rs/curves/", default-features = false }
ark-crypto-primitives = { path = "../" }
ark-ed-on-bls12-377 = { version = "^0.2.0", default-features = false }
ark-std = { version = "^0.2.0", default-features = false }

blake2 = { version = "0.9", default-features = false }
criterion = "0.3.1"
crypto-primitives = { path = "../crypto-primitives" }

################################# Benchmarks ##################################

Expand Down
7 changes: 4 additions & 3 deletions cp-benches/benches/crypto_primitives/comm.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#[macro_use]
extern crate criterion;

use algebra::{ed_on_bls12_377::EdwardsProjective as Edwards, UniformRand};
use ark_crypto_primitives::commitment::{pedersen::*, CommitmentScheme};
use ark_ed_on_bls12_377::EdwardsProjective as Edwards;
use ark_std::UniformRand;
use criterion::Criterion;
use crypto_primitives::commitment::{pedersen::*, CommitmentScheme};

#[derive(Clone, PartialEq, Eq, Hash)]
pub struct CommWindow;
Expand All @@ -28,7 +29,7 @@ fn pedersen_comm_eval(c: &mut Criterion) {
let input = vec![5u8; 128];
c.bench_function("Pedersen Commitment Eval", move |b| {
b.iter(|| {
let rng = &mut rand::thread_rng();
let rng = &mut ark_std::test_rng();
let commitment_randomness = Randomness::rand(rng);
Commitment::<Edwards, CommWindow>::commit(&parameters, &input, &commitment_randomness)
.unwrap()
Expand Down
13 changes: 8 additions & 5 deletions cp-benches/benches/crypto_primitives/crh.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#[macro_use]
extern crate criterion;

use algebra::ed_on_bls12_377::EdwardsProjective as Edwards;
use ark_crypto_primitives::crh::{
pedersen::{Window, CRH as PedersenCRH},
CRH,
};
use ark_ed_on_bls12_377::EdwardsProjective as Edwards;
use criterion::Criterion;
use crypto_primitives::crh::{pedersen::*, FixedLengthCRH};

#[derive(Clone, PartialEq, Eq, Hash)]
pub struct HashWindow;
Expand All @@ -17,17 +20,17 @@ fn pedersen_crh_setup(c: &mut Criterion) {
c.bench_function("Pedersen CRH Setup", move |b| {
b.iter(|| {
let mut rng = &mut ark_std::test_rng();
CRH::<Edwards, HashWindow>::setup(&mut rng).unwrap()
PedersenCRH::<Edwards, HashWindow>::setup(&mut rng).unwrap()
})
});
}

fn pedersen_crh_eval(c: &mut Criterion) {
let mut rng = &mut ark_std::test_rng();
let parameters = CRH::<Edwards, HashWindow>::setup(&mut rng).unwrap();
let parameters = PedersenCRH::<Edwards, HashWindow>::setup(&mut rng).unwrap();
let input = vec![5u8; 128];
c.bench_function("Pedersen CRH Eval", move |b| {
b.iter(|| CRH::<Edwards, HashWindow>::evaluate(&parameters, &input).unwrap())
b.iter(|| PedersenCRH::<Edwards, HashWindow>::evaluate(&parameters, &input).unwrap())
});
}

Expand Down
6 changes: 2 additions & 4 deletions cp-benches/benches/crypto_primitives/prf.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use rand;

#[macro_use]
extern crate criterion;

use criterion::Criterion;
use crypto_primitives::prf::*;
use ark_crypto_primitives::prf::*;
use ark_std::rand::Rng;
use criterion::Criterion;

fn blake2s_prf_eval(c: &mut Criterion) {
let rng = &mut ark_std::test_rng();
Expand Down
12 changes: 6 additions & 6 deletions cp-benches/benches/crypto_primitives/signature.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#[macro_use]
extern crate criterion;

use algebra::ed_on_bls12_377::EdwardsProjective as Edwards;
use ark_crypto_primitives::signature::{schnorr::*, SignatureScheme};
use ark_ed_on_bls12_377::EdwardsProjective as Edwards;
use ark_std::rand::Rng;
use blake2::Blake2s;
use criterion::Criterion;
use crypto_primitives::signature::{schnorr::*, SignatureScheme};
use ark_std::rand::Rng;

type SchnorrEdwards = Schnorr<Edwards, Blake2s>;
fn schnorr_signature_setup(c: &mut Criterion) {
c.bench_function("SchnorrEdwards: Setup", move |b| {
b.iter(|| {
let mut rng = &mut rand::thread_rng();
let mut rng = &mut ark_std::test_rng();
SchnorrEdwards::setup(&mut rng).unwrap()
})
});
Expand All @@ -23,7 +23,7 @@ fn schnorr_signature_keygen(c: &mut Criterion) {

c.bench_function("SchnorrEdwards: KeyGen", move |b| {
b.iter(|| {
let mut rng = &mut rand::thread_rng();
let mut rng = &mut ark_std::test_rng();
SchnorrEdwards::keygen(&parameters, &mut rng).unwrap()
})
});
Expand All @@ -37,7 +37,7 @@ fn schnorr_signature_sign(c: &mut Criterion) {

c.bench_function("SchnorrEdwards: Sign", move |b| {
b.iter(|| {
let mut rng = &mut rand::thread_rng();
let mut rng = &mut ark_std::test_rng();
SchnorrEdwards::sign(&parameters, &sk, &message, &mut rng).unwrap()
})
});
Expand Down
30 changes: 30 additions & 0 deletions scripts/linkify_changelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import fileinput
import os
import re
import sys

# Set this to the name of the repo, if you don't want it to be read from the filesystem.
# It assumes the changelog file is in the root of the repo.
repo_name = ""

# This script goes through the provided file, and replaces any " \#<number>",
# with the valid mark down formatted link to it. e.g.
# " [\#number](https://github.com/arkworks-rs/template/pull/<number>)
# Note that if the number is for a an issue, github will auto-redirect you when you click the link.
# It is safe to run the script multiple times in succession.
#
# Example usage $ python3 linkify_changelog.py ../CHANGELOG.md
changelog_path = sys.argv[1]
if repo_name == "":
path = os.path.abspath(changelog_path)
components = path.split(os.path.sep)
repo_name = components[-2]

for line in fileinput.input(inplace=True):
line = re.sub(
r"\- #([0-9]*)",
r"- [\#\1](https://github.com/arkworks-rs/" + repo_name + r"/pull/\1)",
line.rstrip(),
)
# edits the current file
print(line)
2 changes: 2 additions & 0 deletions src/crh/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::upper_case_acronyms)]

use ark_ff::bytes::ToBytes;
use ark_std::hash::Hash;
use ark_std::rand::Rng;
Expand Down
37 changes: 7 additions & 30 deletions src/crh/poseidon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<F: PrimeField, P: PoseidonRoundParams<F>> Poseidon<F, P> {
let full_rounds_end = P::FULL_ROUNDS_END;

let mut current_state = input.to_vec();
let mut current_state_temp = vec![F::zero().clone(); width];
let mut current_state_temp = vec![F::zero(); width];

let mut round_keys_offset = 0;

Expand Down Expand Up @@ -170,44 +170,21 @@ pub struct CRH<F: PrimeField, P: PoseidonRoundParams<F>> {
params: PhantomData<P>,
}

impl<F: PrimeField, P: PoseidonRoundParams<F>> CRH<F, P> {
pub fn create_mds<R: Rng>(_rng: &mut R) -> Vec<Vec<F>> {
let mds_matrix = Vec::new();
mds_matrix
}

pub fn create_round_consts<R: Rng>(_rng: &mut R) -> Vec<F> {
let round_consts = Vec::new();
round_consts
}
}

impl<F: PrimeField, P: PoseidonRoundParams<F>> CRHTrait for CRH<F, P> {
const INPUT_SIZE_BITS: usize = 32;
type Output = F;
type Parameters = Poseidon<F, P>;

fn setup<R: Rng>(rng: &mut R) -> Result<Self::Parameters, Error> {
// let time = start_timer!(|| format!(
// "Poseidon::Setup: {} {}-bit windows; {{0,1}}^{{{}}} -> C",
// W::NUM_WINDOWS,
// W::WINDOW_SIZE,
// W::NUM_WINDOWS * W::WINDOW_SIZE
// ));

let mds = Self::create_mds(rng);
let rc = Self::create_round_consts(rng);
Ok(Self::Parameters {
params: P::default(),
round_keys: rc,
mds_matrix: mds,
})
fn setup<R: Rng>(_rng: &mut R) -> Result<Self::Parameters, Error> {
// automatic generation of parameters are not implemented yet
// therefore, the developers must specify the parameters themselves
unimplemented!()
}

// https://github.com/arkworks-rs/algebra/blob/master/ff/src/to_field_vec.rs
fn evaluate(parameters: &Self::Parameters, input: &[u8]) -> Result<Self::Output, Error> {
let eval_time = start_timer!(|| "PoseidonCRH::Eval");
let elts: Vec<F> = input.to_field_elements().unwrap_or(Vec::new());
let elts: Vec<F> = input.to_field_elements().unwrap_or_default();
let result = match elts.len() {
2 => parameters.hash_2(elts[0], elts[1]),
4 => parameters.hash_4([elts[0], elts[1], elts[2], elts[3]]),
Expand Down Expand Up @@ -241,7 +218,7 @@ impl<F: PrimeField, P: PoseidonRoundParams<F>> TwoToOneCRH for CRH<F, P> {
let chained: Vec<_> = left_input
.iter()
.chain(right_input.iter())
.map(|x| *x)
.copied()
.collect();

<Self as CRHTrait>::evaluate(parameters, &chained)
Expand Down
Loading

0 comments on commit 786ef7f

Please sign in to comment.