Skip to content

Commit 786ef7f

Browse files
authored
Add CHANGELOG and several housekeeping files (#53)
1 parent 1223fe4 commit 786ef7f

File tree

19 files changed

+222
-77
lines changed

19 files changed

+222
-77
lines changed

.github/.markdownlint.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# See https://github.com/DavidAnson/markdownlint#rules--aliases for list of markdown lint codes
2+
default: true
3+
# MD01 lint blocks having header's incrementing by more than # at a time.
4+
MD001: false
5+
MD007: { indent: 4 }
6+
# MD013 blocks long lines
7+
MD013: false
8+
MD024: { siblings_only: true }
9+
MD025: false
10+
# MD033 lint blocks HTML in MD
11+
MD033: false
12+
# MD036 no-emphasis-as-heading
13+
MD036: false
14+
MD041: false

.github/PULL_REQUEST_TEMPLATE.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!-- < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < ☺
2+
v ✰ Thanks for creating a PR! ✰
3+
v Before hitting that submit button please review the checkboxes.
4+
v If a checkbox is n/a - please still include it but + a little note why
5+
☺ > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -->
6+
7+
## Description
8+
9+
<!-- Add a description of the changes that this PR introduces and the files that
10+
are the most critical to review.
11+
-->
12+
13+
closes: #XXXX
14+
15+
---
16+
17+
Before we can merge this PR, please make sure that all the following items have been
18+
checked off. If any of the checklist items are not applicable, please leave them but
19+
write a little note why.
20+
21+
- [ ] Targeted PR against correct branch (main)
22+
- [ ] Linked to Github issue with discussion and accepted design OR have an explanation in the PR that describes this work.
23+
- [ ] Wrote unit tests
24+
- [ ] Updated relevant documentation in the code
25+
- [ ] Added a relevant changelog entry to the `Pending` section in `CHANGELOG.md`
26+
- [ ] Re-reviewed `Files changed` in the Github PR explorer
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Linkify Changelog
2+
3+
on:
4+
workflow_dispatch
5+
6+
jobs:
7+
linkify:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v2
12+
- name: Add links
13+
run: python3 scripts/linkify_changelog.py CHANGELOG.md
14+
- name: Commit
15+
run: |
16+
git config user.name github-actions
17+
git config user.email github-actions@github.com
18+
git add .
19+
git commit -m "Linkify Changelog"
20+
git push

.github/workflows/mdlinter.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Lint
2+
on:
3+
push:
4+
branches:
5+
- master
6+
paths:
7+
- "**.md"
8+
pull_request:
9+
paths:
10+
- "**.md"
11+
12+
jobs:
13+
build:
14+
name: Markdown linter
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v2
19+
- name: Lint Code Base
20+
uses: docker://github/super-linter:latest
21+
env:
22+
LINTER_RULES_PATH: .github
23+
VALIDATE_ALL_CODEBASE: true
24+
DEFAULT_BRANCH: master
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
VALIDATE_MD: true
27+
MARKDOWN_CONFIG_FILE: .markdownlint.yml
28+
VALIDATE_PROTOBUF: false
29+
VALIDATE_JSCPD: false
30+
# use Python Pylint as the only linter to avoid conflicts
31+
VALIDATE_PYTHON_BLACK: false
32+
VALIDATE_PYTHON_FLAKE8: false
33+
VALIDATE_PYTHON_ISORT: false
34+
VALIDATE_PYTHON_MYPY: false

CHANGELOG.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## Pending
2+
3+
### Breaking changes
4+
5+
- [\#30](https://github.com/arkworks-rs/crypto-primitives/pull/30) Refactor the Merkle tree to separate the leaf hash and two-to-one hash.
6+
7+
### Features
8+
9+
- [\#38](https://github.com/arkworks-rs/crypto-primitives/pull/38) Add a signature verification trait `SigVerifyGadget`.
10+
- [\#44](https://github.com/arkworks-rs/crypto-primitives/pull/44) Add basic ElGamal encryption gadgets.
11+
- [\#48](https://github.com/arkworks-rs/crypto-primitives/pull/48) Add `CanonicalSerialize` and `CanonicalDeserialize` to `Path` and `CRH` outputs.
12+
13+
### Improvements
14+
15+
### Bug fixes
16+
17+
## v0.2.0
18+
19+
### Breaking changes
20+
21+
### Features
22+
23+
- [\#2](https://github.com/arkworks-rs/crypto-primitives/pull/2) Add the `SNARK` gadget traits.
24+
- [\#3](https://github.com/arkworks-rs/crypto-primitives/pull/3) Add unchecked allocation for `ProofVar` and `VerifyingKeyVar`.
25+
- [\#4](https://github.com/arkworks-rs/crypto-primitives/pull/4) Add `verifier_size` to `SNARKGadget`.
26+
- [\#6](https://github.com/arkworks-rs/crypto-primitives/pull/6) Add `IntoIterator` for SNARK input gadgets.
27+
- [\#28](https://github.com/arkworks-rs/crypto-primitives/pull/28) Adds Poseidon CRH w/ constraints.
28+
29+
### Improvements
30+
31+
### Bug fixes
32+
33+
## v0.1.0 (Initial release of arkworks/crypto-primitives)

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,20 @@ This library is released under the MIT License and the Apache v2 License (see [L
1616
## Build guide
1717

1818
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:
19+
1920
```bash
2021
rustup install stable
2122
```
2223

2324
After that, use `cargo`, the standard Rust build tool, to build the library:
25+
2426
```bash
2527
git clone https://github.com/arkworks-rs/crypto-primitives.git
2628
cargo build --release
2729
```
2830

2931
This library comes with unit tests for each of the provided crates. Run the tests with:
32+
3033
```bash
3134
cargo test
3235
```
@@ -35,8 +38,8 @@ cargo test
3538

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

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

4144
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.
4245

cp-benches/Cargo.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ edition = "2018"
1313
################################# Dependencies ################################
1414

1515
[dev-dependencies]
16-
ark-ed-on-bls12-377 = { git = "https://github.com/arkworks-rs/curves/", default-features = false }
16+
ark-crypto-primitives = { path = "../" }
17+
ark-ed-on-bls12-377 = { version = "^0.2.0", default-features = false }
18+
ark-std = { version = "^0.2.0", default-features = false }
19+
1720
blake2 = { version = "0.9", default-features = false }
1821
criterion = "0.3.1"
19-
crypto-primitives = { path = "../crypto-primitives" }
2022

2123
################################# Benchmarks ##################################
2224

cp-benches/benches/crypto_primitives/comm.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#[macro_use]
22
extern crate criterion;
33

4-
use algebra::{ed_on_bls12_377::EdwardsProjective as Edwards, UniformRand};
4+
use ark_crypto_primitives::commitment::{pedersen::*, CommitmentScheme};
5+
use ark_ed_on_bls12_377::EdwardsProjective as Edwards;
6+
use ark_std::UniformRand;
57
use criterion::Criterion;
6-
use crypto_primitives::commitment::{pedersen::*, CommitmentScheme};
78

89
#[derive(Clone, PartialEq, Eq, Hash)]
910
pub struct CommWindow;
@@ -28,7 +29,7 @@ fn pedersen_comm_eval(c: &mut Criterion) {
2829
let input = vec![5u8; 128];
2930
c.bench_function("Pedersen Commitment Eval", move |b| {
3031
b.iter(|| {
31-
let rng = &mut rand::thread_rng();
32+
let rng = &mut ark_std::test_rng();
3233
let commitment_randomness = Randomness::rand(rng);
3334
Commitment::<Edwards, CommWindow>::commit(&parameters, &input, &commitment_randomness)
3435
.unwrap()

cp-benches/benches/crypto_primitives/crh.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#[macro_use]
22
extern crate criterion;
33

4-
use algebra::ed_on_bls12_377::EdwardsProjective as Edwards;
4+
use ark_crypto_primitives::crh::{
5+
pedersen::{Window, CRH as PedersenCRH},
6+
CRH,
7+
};
8+
use ark_ed_on_bls12_377::EdwardsProjective as Edwards;
59
use criterion::Criterion;
6-
use crypto_primitives::crh::{pedersen::*, FixedLengthCRH};
710

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

2528
fn pedersen_crh_eval(c: &mut Criterion) {
2629
let mut rng = &mut ark_std::test_rng();
27-
let parameters = CRH::<Edwards, HashWindow>::setup(&mut rng).unwrap();
30+
let parameters = PedersenCRH::<Edwards, HashWindow>::setup(&mut rng).unwrap();
2831
let input = vec![5u8; 128];
2932
c.bench_function("Pedersen CRH Eval", move |b| {
30-
b.iter(|| CRH::<Edwards, HashWindow>::evaluate(&parameters, &input).unwrap())
33+
b.iter(|| PedersenCRH::<Edwards, HashWindow>::evaluate(&parameters, &input).unwrap())
3134
});
3235
}
3336

cp-benches/benches/crypto_primitives/prf.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
use rand;
2-
31
#[macro_use]
42
extern crate criterion;
53

6-
use criterion::Criterion;
7-
use crypto_primitives::prf::*;
4+
use ark_crypto_primitives::prf::*;
85
use ark_std::rand::Rng;
6+
use criterion::Criterion;
97

108
fn blake2s_prf_eval(c: &mut Criterion) {
119
let rng = &mut ark_std::test_rng();

cp-benches/benches/crypto_primitives/signature.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#[macro_use]
22
extern crate criterion;
33

4-
use algebra::ed_on_bls12_377::EdwardsProjective as Edwards;
4+
use ark_crypto_primitives::signature::{schnorr::*, SignatureScheme};
5+
use ark_ed_on_bls12_377::EdwardsProjective as Edwards;
6+
use ark_std::rand::Rng;
57
use blake2::Blake2s;
68
use criterion::Criterion;
7-
use crypto_primitives::signature::{schnorr::*, SignatureScheme};
8-
use ark_std::rand::Rng;
99

1010
type SchnorrEdwards = Schnorr<Edwards, Blake2s>;
1111
fn schnorr_signature_setup(c: &mut Criterion) {
1212
c.bench_function("SchnorrEdwards: Setup", move |b| {
1313
b.iter(|| {
14-
let mut rng = &mut rand::thread_rng();
14+
let mut rng = &mut ark_std::test_rng();
1515
SchnorrEdwards::setup(&mut rng).unwrap()
1616
})
1717
});
@@ -23,7 +23,7 @@ fn schnorr_signature_keygen(c: &mut Criterion) {
2323

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

3838
c.bench_function("SchnorrEdwards: Sign", move |b| {
3939
b.iter(|| {
40-
let mut rng = &mut rand::thread_rng();
40+
let mut rng = &mut ark_std::test_rng();
4141
SchnorrEdwards::sign(&parameters, &sk, &message, &mut rng).unwrap()
4242
})
4343
});

scripts/linkify_changelog.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import fileinput
2+
import os
3+
import re
4+
import sys
5+
6+
# Set this to the name of the repo, if you don't want it to be read from the filesystem.
7+
# It assumes the changelog file is in the root of the repo.
8+
repo_name = ""
9+
10+
# This script goes through the provided file, and replaces any " \#<number>",
11+
# with the valid mark down formatted link to it. e.g.
12+
# " [\#number](https://github.com/arkworks-rs/template/pull/<number>)
13+
# Note that if the number is for a an issue, github will auto-redirect you when you click the link.
14+
# It is safe to run the script multiple times in succession.
15+
#
16+
# Example usage $ python3 linkify_changelog.py ../CHANGELOG.md
17+
changelog_path = sys.argv[1]
18+
if repo_name == "":
19+
path = os.path.abspath(changelog_path)
20+
components = path.split(os.path.sep)
21+
repo_name = components[-2]
22+
23+
for line in fileinput.input(inplace=True):
24+
line = re.sub(
25+
r"\- #([0-9]*)",
26+
r"- [\#\1](https://github.com/arkworks-rs/" + repo_name + r"/pull/\1)",
27+
line.rstrip(),
28+
)
29+
# edits the current file
30+
print(line)

src/crh/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::upper_case_acronyms)]
2+
13
use ark_ff::bytes::ToBytes;
24
use ark_std::hash::Hash;
35
use ark_std::rand::Rng;

src/crh/poseidon/mod.rs

+7-30
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<F: PrimeField, P: PoseidonRoundParams<F>> Poseidon<F, P> {
4949
let full_rounds_end = P::FULL_ROUNDS_END;
5050

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

5454
let mut round_keys_offset = 0;
5555

@@ -170,44 +170,21 @@ pub struct CRH<F: PrimeField, P: PoseidonRoundParams<F>> {
170170
params: PhantomData<P>,
171171
}
172172

173-
impl<F: PrimeField, P: PoseidonRoundParams<F>> CRH<F, P> {
174-
pub fn create_mds<R: Rng>(_rng: &mut R) -> Vec<Vec<F>> {
175-
let mds_matrix = Vec::new();
176-
mds_matrix
177-
}
178-
179-
pub fn create_round_consts<R: Rng>(_rng: &mut R) -> Vec<F> {
180-
let round_consts = Vec::new();
181-
round_consts
182-
}
183-
}
184-
185173
impl<F: PrimeField, P: PoseidonRoundParams<F>> CRHTrait for CRH<F, P> {
186174
const INPUT_SIZE_BITS: usize = 32;
187175
type Output = F;
188176
type Parameters = Poseidon<F, P>;
189177

190-
fn setup<R: Rng>(rng: &mut R) -> Result<Self::Parameters, Error> {
191-
// let time = start_timer!(|| format!(
192-
// "Poseidon::Setup: {} {}-bit windows; {{0,1}}^{{{}}} -> C",
193-
// W::NUM_WINDOWS,
194-
// W::WINDOW_SIZE,
195-
// W::NUM_WINDOWS * W::WINDOW_SIZE
196-
// ));
197-
198-
let mds = Self::create_mds(rng);
199-
let rc = Self::create_round_consts(rng);
200-
Ok(Self::Parameters {
201-
params: P::default(),
202-
round_keys: rc,
203-
mds_matrix: mds,
204-
})
178+
fn setup<R: Rng>(_rng: &mut R) -> Result<Self::Parameters, Error> {
179+
// automatic generation of parameters are not implemented yet
180+
// therefore, the developers must specify the parameters themselves
181+
unimplemented!()
205182
}
206183

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

247224
<Self as CRHTrait>::evaluate(parameters, &chained)

0 commit comments

Comments
 (0)