Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(decaf377): bump dep #3806

Merged
merged 24 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,541 changes: 698 additions & 843 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ cnidarium = { default-features = false, path = "crates/cn
cnidarium-component = { default-features = false, path = "crates/cnidarium-component" }
cometindex = { path = "crates/util/cometindex" }
criterion = { version = "0.4" }
decaf377 = { default-features = false, version = "0.5" }
decaf377 = { default-features = false, version = "0.10.1" }
decaf377-fmd = { path = "crates/crypto/decaf377-fmd" }
decaf377-ka = { path = "crates/crypto/decaf377-ka" }
decaf377-rdsa = { version = "0.9" }
decaf377-rdsa = { version = "0.11.0" }
derivative = { version = "2.2" }
directories = { version = "4.0.1" }
ed25519-consensus = { version = "2.1" }
Expand Down Expand Up @@ -199,7 +199,7 @@ penumbra-wallet = { path = "crates/wallet" }
penumbra-extension = { path = "crates/penumbra-extension", default-features = false }
pin-project = { version = "1.0.12" }
pin-project-lite = { version = "0.2.9" }
poseidon377 = { version = "0.6" }
poseidon377 = { version = "1.2.0" }
proptest = { version = "1" }
proptest-derive = { version = "0.3" }
prost = { version = "0.12.3" }
Expand Down Expand Up @@ -240,6 +240,7 @@ tower-service = { version = "0.3.2" }
tracing = { version = "0.1" }
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
url = { version = "2.2" }
getrandom = { version = "0.2", default-features = false, features = ["js"] }

# TODO(kate):
# temporarily point these dependencies to a tag in the penumbra-zone fork.
Expand Down
9 changes: 9 additions & 0 deletions crates/bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,16 @@ harness = false
name = "convert"
harness = false

[[bench]]
name = "decaf377"
harness = false

[[bench]]
name = "arkworks"
harness = false

[dependencies]
ark-bls12-377 = "0.4.0"
ark-ec = {workspace = true}
ark-ff = {workspace = true, default-features = false}
ark-groth16 = {workspace = true, default-features = false}
Expand Down
185 changes: 185 additions & 0 deletions crates/bench/benches/arkworks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
use ark_bls12_377::{Fq as ArkFq, Fr as ArkFr};
use ark_ff::fields::models::fp::{Fp256, Fp384};
use ark_ff::{Field, UniformRand};
use criterion::{black_box, criterion_group, criterion_main, Criterion};

// ------------------------------------------------ BLS12-377 Base Field Modulus Fq in Arkworks ------------------------------------------------

fn generate_fq_arkworks() -> ArkFq {
let mut rng = rand::thread_rng();
ArkFq::rand(&mut rng)
}

fn bench_base_field_addition(c: &mut Criterion) {
let mut x = generate_fq_arkworks();
let y = generate_fq_arkworks();

c.bench_function("arkworks:fq field addition", |b| {
b.iter(|| {
for _ in 0..1000 {
x = black_box(x) + black_box(y);
}
})
});
}

fn bench_base_field_subtraction(c: &mut Criterion) {
let mut x = generate_fq_arkworks();
let y = generate_fq_arkworks();

c.bench_function("arkworks: fq field subtraction", |b| {
b.iter(|| {
for _ in 0..1000 {
x = black_box(x) - black_box(y);
}
})
});
}

fn bench_base_field_mutliplication(c: &mut Criterion) {
let mut x = generate_fq_arkworks();
let y = generate_fq_arkworks();

c.bench_function("arkworks: fq field multiplication", |b| {
b.iter(|| {
for _ in 0..1000 {
x = black_box(x) * black_box(y);
}
})
});
}

fn bench_base_field_negation(c: &mut Criterion) {
let mut x = generate_fq_arkworks();
let y = generate_fq_arkworks();

c.bench_function("arkworks: fq field negation", |b| {
b.iter(|| {
for _ in 0..1000 {
x = black_box(x) + black_box(-y);
}
})
});
}

fn bench_base_field_square(c: &mut Criterion) {
let mut x = generate_fq_arkworks();
c.bench_function("arkworks: fq field squaring", |b| {
b.iter(|| {
for _ in 0..1000 {
x = Fp384::square(&x)
}
})
});
}

fn bench_base_field_inverse(c: &mut Criterion) {
let mut x = generate_fq_arkworks();

c.bench_function("arkworks: fq field inverse", |b| {
b.iter(|| {
for _ in 0..1000 {
x = Fp384::inverse(&x).expect("inverse")
}
})
});
}

// ------------------------------------------------ BLS12-377 Scalar Field Modulus Fr in Arkworks ------------------------------------------------

fn generate_fr_arkworks() -> ArkFr {
let mut rng = rand::thread_rng();
ArkFr::rand(&mut rng)
}

fn bench_scalar_field_addition(c: &mut Criterion) {
let mut x = generate_fr_arkworks();
let y = generate_fr_arkworks();

c.bench_function("arkworks: fr field addition", |b| {
b.iter(|| {
for _ in 0..1000 {
x = black_box(x) + black_box(y);
}
})
});
}

fn bench_scalar_field_subtraction(c: &mut Criterion) {
let mut x = generate_fr_arkworks();
let y = generate_fr_arkworks();

c.bench_function("arkworks: fr field subtraction", |b| {
b.iter(|| {
for _ in 0..1000 {
x = black_box(x) - black_box(y);
}
})
});
}

fn bench_scalar_field_mutliplication(c: &mut Criterion) {
let mut x = generate_fr_arkworks();
let y = generate_fr_arkworks();

c.bench_function("arkworks: fr field multiplication", |b| {
b.iter(|| {
for _ in 0..1000 {
x = black_box(x) * black_box(y);
}
})
});
}

fn bench_scalar_field_negation(c: &mut Criterion) {
let mut x = generate_fr_arkworks();
let y = generate_fr_arkworks();

c.bench_function("arkworks: fr field negation", |b| {
b.iter(|| {
for _ in 0..1000 {
x = black_box(x) + black_box(-y);
}
})
});
}

fn bench_scalar_field_square(c: &mut Criterion) {
let mut x = generate_fr_arkworks();
c.bench_function("arkworks: fr field squaring", |b| {
b.iter(|| {
for _ in 0..1000 {
x = Fp256::square(&x)
}
})
});
}

fn bench_scalar_field_inverse(c: &mut Criterion) {
let mut x = generate_fr_arkworks();

c.bench_function("arkworks: fr field inverse", |b| {
b.iter(|| {
for _ in 0..1000 {
x = Fp256::inverse(&x).expect("inverse")
}
})
});
}

criterion_group!(
benches,
bench_base_field_addition,
bench_base_field_subtraction,
bench_base_field_mutliplication,
bench_base_field_negation,
bench_base_field_square,
bench_base_field_inverse,
bench_scalar_field_addition,
bench_scalar_field_subtraction,
bench_scalar_field_mutliplication,
bench_scalar_field_negation,
bench_scalar_field_square,
bench_scalar_field_inverse
);
criterion_main!(benches);
3 changes: 1 addition & 2 deletions crates/bench/benches/convert.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use ark_ff::UniformRand;
use ark_relations::r1cs::{
ConstraintSynthesizer, ConstraintSystem, OptimizationGoal, SynthesisMode,
};
Expand All @@ -20,7 +19,7 @@ fn prove(r: Fq, s: Fq, public: ConvertProofPublic, private: ConvertProofPrivate)

fn dummy_instance() -> (ConvertProofPublic, ConvertProofPrivate) {
let amount = Amount::from(1u64);
let balance_blinding = Fr::from(1);
let balance_blinding = Fr::from(1u64);
let from = *STAKING_TOKEN_ASSET_ID;
let to = *STAKING_TOKEN_ASSET_ID;
let rate = U128x128::from(1u64);
Expand Down
Loading
Loading