Skip to content

Commit

Permalink
update ecgfp5
Browse files Browse the repository at this point in the history
  • Loading branch information
doutv committed Jun 5, 2024
1 parent df45be3 commit 242a3fd
Show file tree
Hide file tree
Showing 16 changed files with 296 additions and 316 deletions.
1 change: 1 addition & 0 deletions ecgfp5/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ num = "0.4"
itertools = "0.10"
serde = "1"
rand = { version = "0.8.5", default-features = false, features = ["getrandom"] }
hex = "0.4.3"

[dev-dependencies]
rand = { version = "0.8.5", features = ["min_const_gen"] }
Expand Down
3 changes: 1 addition & 2 deletions ecgfp5/benches/curve.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use criterion::{black_box, criterion_group, criterion_main, BatchSize, Criterion};
use plonky2_ecgfp5::curve::curve::Point;
use plonky2_ecgfp5::curve::scalar_field::Scalar;
use plonky2_ecgfp5::curve::{curve::Point, scalar_field::Scalar};
use plonky2_field::types::Sample;

pub fn bench_curve(c: &mut Criterion) {
Expand Down
41 changes: 6 additions & 35 deletions ecgfp5/benches/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ pub fn bench_scalar(c: &mut Criterion) {
});

c.bench_function("square", |b| {
b.iter_batched(
|| Scalar::rand(),
|x| black_box(x.square()),
BatchSize::SmallInput,
)
b.iter_batched(|| Scalar::rand(), |x| black_box(x.square()), BatchSize::SmallInput)
});

c.bench_function("try_inverse", |b| {
Expand All @@ -42,64 +38,39 @@ pub fn bench_scalar(c: &mut Criterion) {

c.bench_function("batch_multiplicative_inverse-tiny", |b| {
b.iter_batched(
|| {
(0..2)
.into_iter()
.map(|_| Scalar::rand())
.collect::<Vec<_>>()
},
|| (0..2).into_iter().map(|_| Scalar::rand()).collect::<Vec<_>>(),
|x| Scalar::batch_multiplicative_inverse(&x),
BatchSize::SmallInput,
)
});

c.bench_function("batch_multiplicative_inverse-small", |b| {
b.iter_batched(
|| {
(0..4)
.into_iter()
.map(|_| Scalar::rand())
.collect::<Vec<_>>()
},
|| (0..4).into_iter().map(|_| Scalar::rand()).collect::<Vec<_>>(),
|x| Scalar::batch_multiplicative_inverse(&x),
BatchSize::SmallInput,
)
});

c.bench_function("batch_multiplicative_inverse-medium", |b| {
b.iter_batched(
|| {
(0..16)
.into_iter()
.map(|_| Scalar::rand())
.collect::<Vec<_>>()
},
|| (0..16).into_iter().map(|_| Scalar::rand()).collect::<Vec<_>>(),
|x| Scalar::batch_multiplicative_inverse(&x),
BatchSize::SmallInput,
)
});

c.bench_function("batch_multiplicative_inverse-large", |b| {
b.iter_batched(
|| {
(0..256)
.into_iter()
.map(|_| Scalar::rand())
.collect::<Vec<_>>()
},
|| (0..256).into_iter().map(|_| Scalar::rand()).collect::<Vec<_>>(),
|x| Scalar::batch_multiplicative_inverse(&x),
BatchSize::LargeInput,
)
});

c.bench_function("batch_multiplicative_inverse-huge", |b| {
b.iter_batched(
|| {
(0..65536)
.into_iter()
.map(|_| Scalar::rand())
.collect::<Vec<_>>()
},
|| (0..65536).into_iter().map(|_| Scalar::rand()).collect::<Vec<_>>(),
|x| Scalar::batch_multiplicative_inverse(&x),
BatchSize::LargeInput,
)
Expand Down
6 changes: 1 addition & 5 deletions ecgfp5/examples/ecdsa_sig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,7 @@ pub fn main() {
// build circuit
builder.print_gate_counts(0);
let circuit = builder.build::<C>();
let CircuitData {
prover_only,
common,
verifier_only: _,
} = &circuit;
let CircuitData { prover_only, common, verifier_only: _ } = &circuit;

let pw = PartialWitness::new();
let mut timing = TimingTree::new("prove", Level::Debug);
Expand Down
6 changes: 1 addition & 5 deletions ecgfp5/examples/point_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ pub fn main() {
let mut pw = PartialWitness::new();
pw.set_curve_target(sum, expected.to_weierstrass());

let CircuitData {
prover_only,
common,
verifier_only: _,
} = &circuit;
let CircuitData { prover_only, common, verifier_only: _ } = &circuit;

let mut timing = TimingTree::new("prove", Level::Debug);
let proof = prove(prover_only, common, pw, &mut timing).expect("prover failed");
Expand Down
12 changes: 2 additions & 10 deletions ecgfp5/examples/scalar_mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ pub fn main() {
let mut pw = PartialWitness::new();
pw.set_curve_target(prod, prod_expected.to_weierstrass());

let CircuitData {
prover_only,
common,
verifier_only: _,
} = &circuit;
let CircuitData { prover_only, common, verifier_only: _ } = &circuit;

let mut timing = TimingTree::new("prove", Level::Debug);
let proof = prove(prover_only, common, pw, &mut timing).expect("prover failed");
Expand Down Expand Up @@ -81,11 +77,7 @@ pub fn main() {
let mut pw = PartialWitness::new();
pw.set_curve_target(prod, prod_expected.to_weierstrass());

let CircuitData {
prover_only,
common,
verifier_only: _,
} = &circuit;
let CircuitData { prover_only, common, verifier_only: _ } = &circuit;

let mut timing = TimingTree::new("prove", Level::Debug);
let proof = prove(prover_only, common, pw, &mut timing).expect("prover failed");
Expand Down
6 changes: 1 addition & 5 deletions ecgfp5/examples/schnorr_sig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ pub fn main() {
// build circuit
builder.print_gate_counts(0);
let circuit = builder.build::<C>();
let CircuitData {
prover_only,
common,
verifier_only: _,
} = &circuit;
let CircuitData { prover_only, common, verifier_only: _ } = &circuit;

let pw = PartialWitness::new();
let mut timing = TimingTree::new("prove", Level::Debug);
Expand Down
7 changes: 7 additions & 0 deletions ecgfp5/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This project uses rustfmt to format source code. Run `cargo +nightly fmt [-- --check].
# https://github.com/rust-lang/rustfmt/blob/master/Configurations.md

# Break complex but short statements a bit less.
use_small_heuristics = "Max"

imports_granularity = "Crate"
3 changes: 1 addition & 2 deletions ecgfp5/src/curve/base_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ mod tests {
use rand::thread_rng;

use super::*;
use crate::curve::base_field::SquareRoot;
use crate::curve::test_utils::gfp5_random_non_square;
use crate::curve::{base_field::SquareRoot, test_utils::gfp5_random_non_square};

#[test]
fn test_legendre() {
Expand Down
Loading

0 comments on commit 242a3fd

Please sign in to comment.