From 46d42ab0a45e8a0a62d27fd747c7381cf9c4c03a Mon Sep 17 00:00:00 2001 From: James Campbell Date: Mon, 30 Jan 2023 10:42:43 +0100 Subject: [PATCH 1/2] Remove `window`, `my_partition` and `retry_after` from codebase --- ferveo/benches/benchmarks/pvdkg.rs | 1 - ferveo/examples/pvdkg.rs | 1 - ferveo/src/dkg.rs | 1 - ferveo/src/dkg/pv.rs | 72 +----------------------------- 4 files changed, 1 insertion(+), 74 deletions(-) diff --git a/ferveo/benches/benchmarks/pvdkg.rs b/ferveo/benches/benchmarks/pvdkg.rs index 82600589..e0acd5e7 100644 --- a/ferveo/benches/benchmarks/pvdkg.rs +++ b/ferveo/benches/benchmarks/pvdkg.rs @@ -71,7 +71,6 @@ pub fn setup_dkg( tau: 0, security_threshold: shares_num / 3, shares_num, - retry_after: 2, }, &me, keypairs[validator], diff --git a/ferveo/examples/pvdkg.rs b/ferveo/examples/pvdkg.rs index 82968d1c..be2e92c5 100644 --- a/ferveo/examples/pvdkg.rs +++ b/ferveo/examples/pvdkg.rs @@ -45,7 +45,6 @@ pub fn setup_dkg( tau: 0, security_threshold: shares_num / 3, shares_num, - retry_after: 1, }, &me, keypairs[validator], diff --git a/ferveo/src/dkg.rs b/ferveo/src/dkg.rs index 93aebf7f..27675660 100644 --- a/ferveo/src/dkg.rs +++ b/ferveo/src/dkg.rs @@ -27,7 +27,6 @@ pub struct Params { pub tau: u64, pub security_threshold: u32, pub shares_num: u32, - pub retry_after: u32, // TODO: Remove. Not relevant in our scheme. } #[derive(Clone, Debug, Eq, PartialEq)] diff --git a/ferveo/src/dkg/pv.rs b/ferveo/src/dkg/pv.rs index ec90673a..66f32e79 100644 --- a/ferveo/src/dkg/pv.rs +++ b/ferveo/src/dkg/pv.rs @@ -19,7 +19,6 @@ pub struct PubliclyVerifiableDkg { pub domain: ark_poly::Radix2EvaluationDomain, pub state: DkgState, pub me: usize, - pub window: (u32, u32), } impl PubliclyVerifiableDkg { @@ -48,9 +47,6 @@ impl PubliclyVerifiableDkg { let validators = make_validators(validators); - // TODO: Remove my_partition - let my_partition = - params.retry_after * (2 * me as u32 / params.retry_after); Ok(Self { session_keypair, params, @@ -66,8 +62,6 @@ impl PubliclyVerifiableDkg { }, me, validators, - // TODO: Remove window - window: (my_partition, my_partition + params.retry_after), }) } @@ -81,18 +75,7 @@ impl PubliclyVerifiableDkg { if !self.vss.contains_key(&(self.me as u32)) => { *block += 1; - // if our scheduled window begins, issue PVSS - if self.window.0 + 1 == *block { - PvssScheduler::Issue - } else if &self.window.1 < block { - // reset the window during which we try to get our - // PVSS on chain - *block = self.window.0 + 1; - // reissue PVSS - PvssScheduler::Issue - } else { - PvssScheduler::Wait - } + PvssScheduler::Wait } _ => PvssScheduler::Wait, } @@ -302,7 +285,6 @@ pub(crate) mod test_common { tau: 0, security_threshold, shares_num, - retry_after: 2, }, &me, keypairs[my_index], @@ -373,7 +355,6 @@ mod test_dkg_init { tau: 0, security_threshold: 4, shares_num: 8, - retry_after: 2, }, &ExternalValidator:: { address: "non-existant-validator".into(), @@ -387,16 +368,6 @@ mod test_dkg_init { "could not find this validator in the provided validator set" ) } - - /// Test that the windows of a validator are correctly - /// computed from the `retry_after` param - #[test] - fn test_validator_windows() { - for i in 0..4_u32 { - let dkg = setup_dkg(i as usize); - assert_eq!(dkg.window, (2 * i, 2 * i + 2)); - } - } } /// Test the dealing phase of the DKG @@ -612,19 +583,6 @@ mod test_dealing { assert!(matches!(dkg.state, DkgState::Dealt)) } - /// Check that if a validators window has not arrived, - /// the DKG advises us to wait - #[test] - fn test_pvss_wait_before_window() { - let mut dkg = setup_dkg(1); - if let DkgState::Sharing { block, .. } = dkg.state { - assert!(dkg.window.0 > block); - } else { - panic!("Test failed"); - } - assert_eq!(dkg.increase_block(), PvssScheduler::Wait); - } - /// Test that the DKG advises us to not issue a PVSS transcript /// if we are not in state [`DkgState::Sharing{..}`] #[test] @@ -655,35 +613,7 @@ mod test_dealing { assert!(dkg.apply_message(sender, pvss).is_ok()); assert_eq!(dkg.increase_block(), PvssScheduler::Wait); } - - /// Test that if our own PVSS transcript is not on chain - /// after the retry window, the DKG advises us to issue again. - #[test] - fn test_pvss_reissue() { - let mut dkg = setup_dkg(0); - dkg.state = DkgState::Sharing { - accumulated_shares: 0, - block: 2, - }; - assert_eq!(dkg.increase_block(), PvssScheduler::Issue); - assert_eq!(dkg.increase_block(), PvssScheduler::Wait); - } - - /// Test that we are only advised to issue a PVSS at the - /// beginning of our window, not for every block in it - #[test] - fn test_pvss_wait_middle_of_window() { - let mut dkg = setup_dkg(0); - assert_eq!(dkg.increase_block(), PvssScheduler::Issue); - if let DkgState::Sharing { block, .. } = dkg.state { - assert!(dkg.window.0 < block && block < dkg.window.1); - } else { - panic!("Test failed"); - } - assert_eq!(dkg.increase_block(), PvssScheduler::Wait); - } } - /// Test aggregating transcripts into final key #[cfg(test)] mod test_aggregation { From c20ac5ec71b56336bfcccd3d308b32643122f3c7 Mon Sep 17 00:00:00 2001 From: James Campbell Date: Mon, 30 Jan 2023 16:00:02 +0100 Subject: [PATCH 2/2] Convert `api` and `serialization` to features --- Cargo.toml | 2 +- tpke/Cargo.toml | 4 ++++ tpke/src/lib.rs | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 72edf305..797176b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,4 +23,4 @@ debug = true [profile.release] debug = true lto = true -codegen-units = 1 +codegen-units = 1 \ No newline at end of file diff --git a/tpke/Cargo.toml b/tpke/Cargo.toml index 247de9f3..dc0198d6 100644 --- a/tpke/Cargo.toml +++ b/tpke/Cargo.toml @@ -49,3 +49,7 @@ harness = false [profile.release] opt-level = 3 lto = true + +[features] +api = [] +serialization = [] \ No newline at end of file diff --git a/tpke/src/lib.rs b/tpke/src/lib.rs index 2e482500..50262f52 100644 --- a/tpke/src/lib.rs +++ b/tpke/src/lib.rs @@ -30,8 +30,10 @@ pub use decryption::*; pub use key_share::*; pub use refresh::*; -// TODO: Turn into a crate features +#[cfg(feature = "api")] pub mod api; + +#[cfg(feature = "serialization")] pub mod serialization; pub trait ThresholdEncryptionParameters {