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

Remove powers-of-2 restriction on cohort size #134

Merged

Conversation

piotr-roslaniec
Copy link

@piotr-roslaniec piotr-roslaniec commented Jun 26, 2023

Type of PR:

  • Feature

Required reviews:

  • 2

What this does:

  • Adds benchmarks to compare the performance of MixedRadixEvaluationDomain (without constraints on the number of coefficients) and Radix2EvaluationDomain (number of coefficients must be a power of two)
  • Replaces usage of Radix2EvaluationDomain with GeneralEvaluationDomain (automatically select domain size) in ferveo

Issues fixed/closed:

Why it's needed:

Explain how this PR fits in the greater context of the NuCypher Network.
E.g., if this PR address a nucypher/productdev issue, let reviewers know!

Notes for reviewers:

Benchmarking results

lines
violin

@codecov-commenter
Copy link

codecov-commenter commented Jun 26, 2023

Codecov Report

Merging #134 (0381d67) into main (8dc57d3) will increase coverage by 0.13%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #134      +/-   ##
==========================================
+ Coverage   78.66%   78.80%   +0.13%     
==========================================
  Files          24       24              
  Lines        4880     4865      -15     
==========================================
- Hits         3839     3834       -5     
+ Misses       1041     1031      -10     
Impacted Files Coverage Δ
ferveo/src/bindings_python.rs 54.89% <ø> (+0.60%) ⬆️
ferveo/src/lib.rs 97.40% <ø> (ø)
ferveo/src/utils.rs 93.75% <ø> (-0.99%) ⬇️
ferveo/src/api.rs 88.79% <100.00%> (ø)
ferveo/src/dkg.rs 96.12% <100.00%> (+0.63%) ⬆️
ferveo/src/pvss.rs 91.68% <100.00%> (ø)

@piotr-roslaniec piotr-roslaniec marked this pull request as ready for review June 26, 2023 13:07
@piotr-roslaniec piotr-roslaniec changed the base branch from main to development July 3, 2023 09:49
@piotr-roslaniec piotr-roslaniec changed the base branch from development to pk-static-bytes July 3, 2023 13:51
Copy link
Member

@cygnusv cygnusv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this would be more painful! Great work @piotr-roslaniec, as usual 💪

)
.expect("unable to construct domain");
let domain =
ark_poly::MixedRadixEvaluationDomain::<E::ScalarField>::new(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! That's so clean.

let rng = &mut StdRng::seed_from_u64(0);
let s = ark_bls12_381::Fr::from_random_bytes(&[0u8; 32]).unwrap();

for shares_num in NUM_SHARES_CASES {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is benchmarking the speed of num shares that are powers of 2 for Radix2 vs MixedRadix? Cool.

As an aside. Do we have a test somewhere for a non-power of 2 number of shares? Basically, a test that confirms that the non-powers of 2 work appropriately.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't consider this kind of test to be interesting before. I did a manual test (in REPL) before submitting the PR and that lulled me into a false sense of correctness. Now that I followed up on your suggestion, it turns out only the simple variant works for a non-power-of-two number of shares.

I will post the changes here and investigate the issue with the precomputed variant.

Thanks for catching this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bug has been found and fixed. Please see my comment below.

);
assert!(result.is_err());
// Works for both power of 2 and non-power of 2
for shares_num in [4, 7] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to see - 🔥

Comment on lines -241 to +246
let domain_points: Vec<_> = dkg.0.domain.elements().collect();
let domain_points: Vec<_> = dkg
.0
.domain
.elements()
.take(dkg.0.dkg_params.shares_num as usize)
.collect();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the root cause of the issue found by unit tests. The domain may have an arbitrary size, but we must use at most shares_num domain points.

Copy link
Member

@derekpierre derekpierre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎸

@piotr-roslaniec piotr-roslaniec changed the base branch from pk-static-bytes to development July 6, 2023 14:38
@piotr-roslaniec piotr-roslaniec merged commit 2338213 into nucypher:development Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

Remove powers-of-2 restriction on cohort size
4 participants