mirror of
https://github.com/arnaucube/babyjubjub-ark.git
synced 2026-01-13 17:21:29 +01:00
Update sign&verify (poseidon) to last optimization
(On a Intel(R) Core(TM) i7-8705G CPU @ 3.10GHz, with 32 GB of RAM) - before: ``` sign_poseidon time: [383.01 ms 384.46 ms 385.98 ms] verify_poseidon time: [250.56 ms 251.46 ms 252.43 ms] ``` - current: ``` sign_poseidon time: [973.38 us 973.83 us 974.41 us] verify_poseidon time: [835.34 us 839.94 us 845.29 us] ``` sign_poseidon: `394x` improvement verify_poseidon: `300x` improvement
This commit is contained in:
@@ -7,20 +7,11 @@ use ff::*;
|
||||
|
||||
extern crate num;
|
||||
extern crate num_bigint;
|
||||
use num_bigint::BigInt;
|
||||
use num_bigint::{BigInt, ToBigInt};
|
||||
|
||||
use babyjubjub_rs::{utils, Point};
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
// let x: BigInt = BigInt::parse_bytes(
|
||||
// b"17777552123799933955779906779655732241715742912184938656739573121738514868268",
|
||||
// 10,
|
||||
// )
|
||||
// .unwrap();
|
||||
// c.bench_function("modulus", |b| {
|
||||
// b.iter(|| utils::modulus(&x, &babyjubjub_rs::Q))
|
||||
// });
|
||||
|
||||
let p: Point = Point {
|
||||
x: babyjubjub_rs::Fr::from_str(
|
||||
"17777552123799933955779906779655732241715742912184938656739573121738514868268",
|
||||
@@ -30,11 +21,13 @@ fn criterion_benchmark(c: &mut Criterion) {
|
||||
"2626589144620713026669568689430873010625803728049924121243784502389097019475",
|
||||
)
|
||||
.unwrap(),
|
||||
z: babyjubjub_rs::Fr::one(),
|
||||
};
|
||||
let q = p.clone();
|
||||
|
||||
c.bench_function("add", |b| b.iter(|| p.add(&q)));
|
||||
let p_projective = p.projective();
|
||||
let q_projective = q.projective();
|
||||
|
||||
c.bench_function("add", |b| b.iter(|| p_projective.add(&q_projective)));
|
||||
let r: BigInt = BigInt::parse_bytes(b"3", 10).unwrap();
|
||||
c.bench_function("mul_scalar_small", |b| b.iter(|| p.mul_scalar(&r)));
|
||||
let r: BigInt = BigInt::parse_bytes(
|
||||
@@ -44,22 +37,22 @@ fn criterion_benchmark(c: &mut Criterion) {
|
||||
.unwrap();
|
||||
c.bench_function("mul_scalar", |b| b.iter(|| p.mul_scalar(&r)));
|
||||
|
||||
// c.bench_function("compress", |b| b.iter(|| p.compress()));
|
||||
// let p_comp = p.compress();
|
||||
// c.bench_function("decompress", |b| {
|
||||
// b.iter(|| babyjubjub_rs::decompress_point(p_comp))
|
||||
// });
|
||||
c.bench_function("point compress", |b| b.iter(|| p.compress()));
|
||||
let p_comp = p.compress();
|
||||
c.bench_function("point decompress", |b| {
|
||||
b.iter(|| babyjubjub_rs::decompress_point(p_comp))
|
||||
});
|
||||
|
||||
// let sk = babyjubjub_rs::new_key();
|
||||
// let pk = sk.public().unwrap();
|
||||
// let msg = 5.to_bigint().unwrap();
|
||||
// c.bench_function("sign_poseidon", |b| {
|
||||
// b.iter(|| sk.sign_poseidon(msg.clone()))
|
||||
// });
|
||||
// let sig = sk.sign_poseidon(msg.clone()).unwrap();
|
||||
// c.bench_function("verify_poseidon", |b| {
|
||||
// b.iter(|| babyjubjub_rs::verify_poseidon(pk.clone(), sig.clone(), msg.clone()))
|
||||
// });
|
||||
let sk = babyjubjub_rs::new_key();
|
||||
let pk = sk.public().unwrap();
|
||||
let msg = 5.to_bigint().unwrap();
|
||||
c.bench_function("sign_poseidon", |b| {
|
||||
b.iter(|| sk.sign_poseidon(msg.clone()))
|
||||
});
|
||||
let sig = sk.sign_poseidon(msg.clone()).unwrap();
|
||||
c.bench_function("verify_poseidon", |b| {
|
||||
b.iter(|| babyjubjub_rs::verify_poseidon(pk.clone(), sig.clone(), msg.clone()))
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_benchmark);
|
||||
|
||||
Reference in New Issue
Block a user