Browse Source

Add GHA, small clean

master
arnau 3 years ago
committed by arnaucube
parent
commit
df8530c24d
6 changed files with 22 additions and 28 deletions
  1. +13
    -0
      .github/workflows/rust.yml
  2. +0
    -9
      .travis.yml
  3. +1
    -1
      README.md
  4. +1
    -1
      benches/bench_mimc_hash.rs
  5. +0
    -3
      gen_constants/src/main.rs
  6. +7
    -14
      src/lib.rs

+ 13
- 0
.github/workflows/rust.yml

@ -0,0 +1,13 @@
name: Test
on: [push, pull_request]
env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose

+ 0
- 9
.travis.yml

@ -1,9 +0,0 @@
language: rust
rust:
- stable
cache:
- cargo
script:
- RUST_BACKTRACE=1 cargo test --all

+ 1
- 1
README.md

@ -1,4 +1,4 @@
# mimc-rs [![Crates.io](https://img.shields.io/crates/v/mimc-rs.svg)](https://crates.io/crates/mimc-rs) [![Build Status](https://travis-ci.org/arnaucube/mimc-rs.svg?branch=master)](https://travis-ci.org/arnaucube/mimc-rs)
# mimc-rs [![Crates.io](https://img.shields.io/crates/v/mimc-rs.svg)](https://crates.io/crates/mimc-rs) [![Test](https://github.com/arnaucube/mimc-rs/workflows/Test/badge.svg)](https://github.com/arnaucube/mimc-rs/actions?query=workflow%3ATest)
MIMC7 hash implementation in Rust, a zkSNARK friendly hash function. MIMC7 hash implementation in Rust, a zkSNARK friendly hash function.
https://eprint.iacr.org/2016/492.pdf https://eprint.iacr.org/2016/492.pdf

+ 1
- 1
benches/bench_mimc_hash.rs

@ -20,7 +20,7 @@ fn criterion_benchmark(c: &mut Criterion) {
big_arr.push(b2.clone()); big_arr.push(b2.clone());
let mimc7 = Mimc7::new(); let mimc7 = Mimc7::new();
c.bench_function("hash", |b| b.iter(|| mimc7.hash(big_arr.clone()).unwrap()));
c.bench_function("hash", |b| b.iter(|| mimc7.hash(big_arr.clone())));
} }
criterion_group!(benches, criterion_benchmark); criterion_group!(benches, criterion_benchmark);

+ 0
- 3
gen_constants/src/main.rs

@ -90,9 +90,6 @@ fn main() {
println!(" {:?},", c.cts[i].to_string()); println!(" {:?},", c.cts[i].to_string());
} }
println!("];"); println!("];");
println!("let r: Fr = Fr::from_str(");
println!(" {:?},", c.r.to_string());
println!(").unwrap();");
println!("let n_rounds: i64 = {:?};", c.n_rounds); println!("let n_rounds: i64 = {:?};", c.n_rounds);
} }

+ 7
- 14
src/lib.rs

@ -9,7 +9,6 @@ use ff::*;
pub struct Fr(FrRepr); pub struct Fr(FrRepr);
pub struct Constants { pub struct Constants {
r: Fr,
n_rounds: i64, n_rounds: i64,
cts: Vec<Fr>, cts: Vec<Fr>,
} }
@ -109,10 +108,6 @@ pub fn load_constants() -> Constants {
"18979889247746272055963929241596362599320706910852082477600815822482192194401", "18979889247746272055963929241596362599320706910852082477600815822482192194401",
"13602139229813231349386885113156901793661719180900395818909719758150455500533", "13602139229813231349386885113156901793661719180900395818909719758150455500533",
]; ];
let r: Fr = Fr::from_str(
"21888242871839275222246405745257275088548364400416034343698204186575808495617",
)
.unwrap();
let n_rounds: i64 = 91; let n_rounds: i64 = 91;
let mut cts: Vec<Fr> = Vec::new(); let mut cts: Vec<Fr> = Vec::new();
@ -121,7 +116,6 @@ pub fn load_constants() -> Constants {
cts.push(n); cts.push(n);
} }
Constants { Constants {
r: r,
n_rounds: n_rounds, n_rounds: n_rounds,
cts: cts, cts: cts,
} }
@ -159,14 +153,13 @@ impl Mimc7 {
t.add_assign(&k); t.add_assign(&k);
t.add_assign(&self.constants.cts[i]); t.add_assign(&self.constants.cts[i]);
} }
let mut t5 = t.clone();
t5.mul_assign(&t);
t5.mul_assign(&t);
t5.mul_assign(&t);
t5.mul_assign(&t);
t5.mul_assign(&t);
t5.mul_assign(&t);
h = t5.clone();
let mut t2 = t.clone();
t2.square();
let mut t7 = t2.clone();
t7.square();
t7.mul_assign(&t2);
t7.mul_assign(&t);
h = t7.clone();
} }
h.add_assign(&k); h.add_assign(&k);
h h

Loading…
Cancel
Save