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

Prefer the Pow trait #179

Draft
wants to merge 25 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
bf9acac
Synthetic benchmark for exponentiation with known totient
dvdplm Jan 8, 2025
a6e4168
Initial benchmark for Fac proof
dvdplm Jan 8, 2025
936fceb
Init tracing for FacProof benches
dvdplm Jan 16, 2025
3d8ebf0
Add test that exercise the ser-/deserialization of FacProof
dvdplm Jan 16, 2025
72355d1
Add benchmark for AffG
dvdplm Jan 17, 2025
e225fb2
mod.rs is not allowed and other clippy fixes
dvdplm Jan 17, 2025
0c78a5c
Allow formatting args in string literals
dvdplm Jan 17, 2025
0d748b7
Benchmark for DecProof construction and verification
dvdplm Jan 17, 2025
0e9b77c
Add Enc proof
dvdplm Jan 17, 2025
c310e31
Add Paillier Mul proof benchmark
dvdplm Jan 17, 2025
b6c79c9
Clippy fixes
dvdplm Jan 17, 2025
6f88bef
moar clippy crap
dvdplm Jan 17, 2025
7cf86ec
Add benches for Prm and Sch proofs
dvdplm Jan 17, 2025
30cc953
Remove workaround for broken/quirky clippy on nightly (https://github…
dvdplm Jan 20, 2025
5eedb88
Prm proofs are broken for now
dvdplm Jan 20, 2025
d45d19c
Appease clippy
dvdplm Jan 20, 2025
05d714b
Don't use a PublicSigned for PrmProof
dvdplm Jan 20, 2025
6ad3132
Merge branch 'master' into dp-zk-proof-benches
dvdplm Jan 21, 2025
58d9fb4
Re-enable Prm benchmark
dvdplm Jan 21, 2025
c5bde71
Upgrade to crypto-bigint rc.8 (#177)
dvdplm Jan 23, 2025
1acdee2
Add a changelog reference
fjarri Jan 23, 2025
f003eaa
Replace the Exponentiable trait with Pow
dvdplm Jan 23, 2025
8842d50
Move impls into a macro, make the wrapper types pub
dvdplm Jan 23, 2025
8dfe504
cleanup
dvdplm Jan 23, 2025
43d6bf7
Prefer pow()
dvdplm Jan 24, 2025
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
rust:
- 1.81.0 # MSRV
- 1.83.0 # MSRV
- stable
target:
- wasm32-unknown-unknown
Expand Down Expand Up @@ -59,7 +59,7 @@ jobs:
matrix:
include:
- target: x86_64-unknown-linux-gnu
rust: 1.81.0 # MSRV
rust: 1.83.0 # MSRV
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@v1
Expand All @@ -77,7 +77,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.81.0 # MSRV
toolchain: 1.83.0 # MSRV
components: clippy
override: true
profile: minimal
Expand Down
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [0.3.0] - in development

- Switch the protocol framework to `manul`. ([#156])

- Bumped MSRV to 1.83 ([#176])

[#156]: https://github.com/entropyxyz/synedrion/pull/156
[#176]: https://github.com/entropyxyz/synedrion/pull/176


## [0.2.0] - 2024-11-17

- Signature and elliptic curve dependencies reset back to stable versions. (#[154])
- Signature and elliptic curve dependencies reset back to stable versions. ([#154])


[#154]: https://github.com/entropyxyz/synedrion/pull/154
Expand Down
41 changes: 34 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 18 additions & 2 deletions synedrion/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "synedrion"
authors = ['Entropy Cryptography <[email protected]>']
version = "0.3.0-dev"
edition = "2021"
rust-version = "1.81"
rust-version = "1.83"
license = "AGPL-3.0-or-later"
description = "Threshold signing library based on Canetti-Gennaro-Goldfeder-Makriyannis-Peled '21 scheme"
repository = "https://github.com/entropyxyz/synedrion"
Expand All @@ -26,7 +26,7 @@ tracing = { version = "0.1.41", default-features = false }

# Note: `alloc` is needed for `crytpto-bigint`'s dependency `serdect` to be able
# to serialize Uints in human-readable formats.
crypto-bigint = { version = "0.6.0-rc.6", default-features = false, features = [
crypto-bigint = { version = "0.6.0-rc.8", default-features = false, features = [
"serde",
"alloc",
"rand_core",
Expand All @@ -38,6 +38,7 @@ serde = { version = "1", default-features = false, features = ["derive"] }
serde-encoded-bytes = { version = "0.1", default-features = false, features = ["hex", "base64"] }
bincode = { version = "2.0.0-rc.3", default-features = false, features = ["serde", "alloc"] }
displaydoc = { version = "0.2", default-features = false }
criterion = { version = "0.5", optional = true }

[dev-dependencies]
manul = { version = "0.1", features = ["dev"] }
Expand All @@ -50,9 +51,24 @@ k256 = { version = "0.13", default-features = false, features = ["ecdsa", "arith
impls = "1"
hex = { version = "0.4", default-features = false, features = ["alloc"] }
test-log = { version = "0.2.16", default-features = false, features = ["trace", "color"] }
tracing-subscriber = "0.3.19"

[features]
private_benches = ["criterion"]

[[bench]]
bench = true
name = "bench"
harness = false
path = "benches/bench.rs"

[[bench]]
bench = true
name = "pow"
harness = false
path = "benches/pow.rs"

[[bench]]
bench = true
name = "zk_proofs"
harness = false
125 changes: 125 additions & 0 deletions synedrion/benches/pow.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
use criterion::{black_box, criterion_group, criterion_main, BatchSize, Criterion};
use crypto_bigint::{
modular::{MontyForm, MontyParams},
NonZero, Odd, Random, Uint, U1024, U2048, U256, U4096, U512,
};
use crypto_primes::RandomPrimeWithRng;
use rand::SeedableRng;

fn bench_pow_known_totient_512(c: &mut Criterion) {
let mut group = c.benchmark_group("modpow, 512^1024");

let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(1234567890);
let p: U512 = (U256::generate_prime_with_rng(&mut rng, U256::BITS), U256::ZERO).into();
let q: U512 = (U256::generate_prime_with_rng(&mut rng, U256::BITS), U256::ZERO).into();
let m: U512 = p * q;
let totient = (p - U512::ONE) * (q - U512::ONE);
let prms = MontyParams::new_vartime(Odd::new(m).unwrap());

group.bench_function("vanilla", |b| {
let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(1234567890);
b.iter_batched(
|| {
let x = U512::random(&mut rng);
let x = MontyForm::new(&x, prms);
let exponent = U1024::random(&mut rng);
(x, exponent)
},
|(x, exponent)| black_box(x.pow(&exponent)),
BatchSize::SmallInput,
);
});

group.bench_function("known totient", |b| {
let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(1234567890);
b.iter_batched(
|| {
let x = U512::random(&mut rng);
let x = MontyForm::new(&x, prms);
let exponent = U1024::random(&mut rng);
let exponent = Uint::rem_wide_vartime(exponent.split(), &NonZero::new(totient).unwrap());
(x, exponent)
},
|(x, exponent)| black_box(x.pow(&exponent)),
BatchSize::SmallInput,
);
});

group.bench_function("known totient (not ammortized)", |b| {
let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(1234567890);
b.iter_batched(
|| {
let x = U512::random(&mut rng);
let x = MontyForm::new(&x, prms);
let exponent = U1024::random(&mut rng);
(x, exponent)
},
|(x, exponent)| {
let exponent = Uint::rem_wide_vartime(exponent.split(), &NonZero::new(totient).unwrap());
black_box(x.pow(&exponent))
},
BatchSize::SmallInput,
);
});
}

// Our production parameters use 1024-bit primes resulting in 2048-bit moduli
fn bench_pow_known_totient_2048(c: &mut Criterion) {
let mut group = c.benchmark_group("modpow, 2048^4096");

let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(1234567890);
let p: U2048 = (U1024::generate_prime_with_rng(&mut rng, U1024::BITS), U1024::ZERO).into();
let q: U2048 = (U1024::generate_prime_with_rng(&mut rng, U1024::BITS), U1024::ZERO).into();
let m: U2048 = p * q;
let totient = (p - U2048::ONE) * (q - U2048::ONE);
let prms = MontyParams::new_vartime(Odd::new(m).unwrap());

group.bench_function("vanilla", |b| {
let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(1234567890);
b.iter_batched(
|| {
let x = U2048::random(&mut rng);
let x = MontyForm::new(&x, prms);
let exponent = U4096::random(&mut rng);
(x, exponent)
},
|(x, exponent)| black_box(x.pow(&exponent)),
BatchSize::SmallInput,
);
});

group.bench_function("known totient", |b| {
let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(1234567890);
b.iter_batched(
|| {
let x = U2048::random(&mut rng);
let x = MontyForm::new(&x, prms);
let exponent = U4096::random(&mut rng);
let exponent = Uint::rem_wide_vartime(exponent.split(), &NonZero::new(totient).unwrap());
(x, exponent)
},
|(x, exponent)| black_box(x.pow(&exponent)),
BatchSize::SmallInput,
);
});

group.bench_function("known totient (not ammortized)", |b| {
let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(1234567890);
b.iter_batched(
|| {
let x = U2048::random(&mut rng);
let x = MontyForm::new(&x, prms);
let exponent = U4096::random(&mut rng);
(x, exponent)
},
|(x, exponent)| {
let exponent = Uint::rem_wide_vartime(exponent.split(), &NonZero::new(totient).unwrap());
black_box(x.pow(&exponent))
},
BatchSize::SmallInput,
);
});
}
criterion_group!(benches, bench_pow_known_totient_512, bench_pow_known_totient_2048);

criterion_main!(benches);
Loading
Loading