Skip to content

Commit

Permalink
refactor(decaf377): bump dep (#3806)
Browse files Browse the repository at this point in the history
## Describe your changes
Updates the `decaf377`, `decaf377-rdsa`, and `poseidon377` dep versions 

## Issue ticket number and link
References #3676 and
consumes changes in #3678. unblocked by
penumbra-zone/decaf377#101

## Checklist before requesting a review
- [x] If this code contains consensus-breaking changes, I have added the
"consensus-breaking" label. Otherwise, I declare my belief that there
are not consensus-breaking changes, for the following reason:

---------

Co-authored-by: Lucas Meier <lucas@cronokirby.com>
  • Loading branch information
TalDerei and cronokirby committed Jul 10, 2024
1 parent 6f90647 commit c1d7a84
Show file tree
Hide file tree
Showing 101 changed files with 1,358 additions and 1,118 deletions.
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

0 comments on commit c1d7a84

Please sign in to comment.