-
Notifications
You must be signed in to change notification settings - Fork 13
Faster RP commits with multi-exponentiation #184
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
Closed
Closed
Changes from 29 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
bf9acac
Synthetic benchmark for exponentiation with known totient
dvdplm a6e4168
Initial benchmark for Fac proof
dvdplm 936fceb
Init tracing for FacProof benches
dvdplm 3d8ebf0
Add test that exercise the ser-/deserialization of FacProof
dvdplm 72355d1
Add benchmark for AffG
dvdplm e225fb2
mod.rs is not allowed and other clippy fixes
dvdplm 0c78a5c
Allow formatting args in string literals
dvdplm 0d748b7
Benchmark for DecProof construction and verification
dvdplm 0e9b77c
Add Enc proof
dvdplm c310e31
Add Paillier Mul proof benchmark
dvdplm b6c79c9
Clippy fixes
dvdplm 6f88bef
moar clippy crap
dvdplm 7cf86ec
Add benches for Prm and Sch proofs
dvdplm 30cc953
Remove workaround for broken/quirky clippy on nightly (https://github…
dvdplm 5eedb88
Prm proofs are broken for now
dvdplm d45d19c
Appease clippy
dvdplm 05d714b
Don't use a PublicSigned for PrmProof
dvdplm 6ad3132
Merge branch 'master' into dp-zk-proof-benches
dvdplm 58d9fb4
Re-enable Prm benchmark
dvdplm df1f717
Merge branch 'master' into dp-zk-proof-benches
dvdplm c3d0d4f
Use multi-exponentiation in ZK proofs
dvdplm 5ab592a
CHANGELOG
dvdplm d58011e
Extract common code
dvdplm 17c2aa6
Justify inversions
dvdplm 7019228
Docs for PublicModulus
dvdplm 80c49a3
Remove clippy too many args left-over since refactor
dvdplm 2f97af2
Merge branch 'master' into dp-faster-commit-with-multi-exp-bis
dvdplm e812282
Merge branch 'master' into dp-faster-commit-with-multi-exp-bis
dvdplm 9091fdf
Remove old ZK proofs
dvdplm d1c3014
Remove unneeded ser/deser test
dvdplm 93dd378
No need for `pub`, `pub(crate)` is enough.
dvdplm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fjarri I left these in, but they are not particularly useful long-term I think. I wrote them to check on progress as I was changing code, but I think we should remove them now.