-
Notifications
You must be signed in to change notification settings - Fork 41
feat: correlate governancethreshold with reconstructionthreshold #3578
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
Changes from all commits
02dd798
44e9e76
7d86856
b33f455
02c5313
a378c56
3da1652
aeed6e7
7257a16
a20a7a8
1afd958
db47b85
0cf1b53
27e40bf
7878ac8
1f28966
7bca4d8
263bc8d
f45ebf5
c8fec49
6e1ce47
5056109
5f5af82
fbf22be
b310e84
ca8b199
c34a13a
da2d190
7458432
4f52bdd
29613b8
3b329e2
f168468
cd557e1
e769a53
df26736
876bcfe
fc57a33
484d40e
ec871da
ee76a11
6a4fa9e
0ef09e5
bc928d4
6da939c
e6f5a9a
6c2a728
ceff551
e72e801
c1d3625
7d46e93
187de2a
c7b3efb
37465bd
c9ab983
105a449
01ffb27
afbe6b8
d8f7e81
f455d91
5e97933
0d6e0f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,15 +3,18 @@ use crate::{ | |
| crypto_shared::types::{PublicKeyExtended, serializable::SerializableEdwardsPoint}, | ||
| primitives::{ | ||
| participants::{ParticipantInfo, Participants}, | ||
| thresholds::{ProposedThresholdParameters, Threshold, ThresholdParameters}, | ||
| thresholds::{ | ||
| ProposedThresholdParameters, Threshold, ThresholdParameters, | ||
| governance_threshold_lower_relative_bound, governance_threshold_upper_relative_bound, | ||
| }, | ||
| }, | ||
| }; | ||
| use curve25519_dalek::edwards::CompressedEdwardsY; | ||
| use near_account_id::AccountId; | ||
| use near_mpc_contract_interface::types::{ | ||
| DomainConfig, DomainId, DomainPurpose, Protocol, ReconstructionThreshold, | ||
| }; | ||
| use rand::{Rng, distributions::Uniform}; | ||
| use rand::{Rng, SeedableRng, distributions::Uniform, rngs::StdRng}; | ||
| use std::collections::BTreeMap; | ||
| // Re-export for convenience | ||
|
|
||
|
|
@@ -129,10 +132,6 @@ pub fn gen_participant(i: usize) -> (AccountId, ParticipantInfo) { | |
| ) | ||
| } | ||
|
|
||
| pub fn min_thrershold(n: usize) -> usize { | ||
| ((n as f64) * 0.6).ceil() as usize | ||
| } | ||
|
|
||
| pub fn gen_accounts_and_info(n: usize) -> BTreeMap<AccountId, ParticipantInfo> { | ||
| (0..n).map(gen_participant).collect() | ||
| } | ||
|
|
@@ -157,9 +156,11 @@ pub fn gen_threshold_params(max_n: usize) -> ThresholdParameters { | |
| // Lower bound is 3 (not 2) so the produced parameters are compatible with | ||
| // every protocol — `DamgardEtAl` requires `n >= 2t - 1`, which forces | ||
| // `n >= 3` even at the minimum `t = 2`. | ||
| let n: usize = rand::thread_rng().gen_range(3..max_n + 1); | ||
| let k_min = min_thrershold(n); | ||
| let k = rand::thread_rng().gen_range(k_min..n + 1); | ||
| let mut rng = StdRng::seed_from_u64(42); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. technically this should be a parameter to the function, but for the sake of keeping this simple we can leave it here
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As you said, it's simpler this way
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is an improvement without passing the RNG as a parameter, because this is a pretty low-level helper method, so we will now generate the exact same threshold params for any given @SimonRastikian please modify in this PR or open a follow-up for this. |
||
| let n: usize = rng.gen_range(3..max_n + 1); | ||
| let k_min = governance_threshold_lower_relative_bound(n as u64) as usize; | ||
| let k_max = governance_threshold_upper_relative_bound(n as u64) as usize; | ||
| let k = rng.gen_range(k_min..k_max + 1); | ||
| ThresholdParameters::new(gen_participants(n), Threshold::new(k as u64)).unwrap() | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.