From 966e2654d2fe496677275c7854748b184a531402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=BA=C3=B1ez?= Date: Mon, 23 Sep 2024 19:03:41 +0200 Subject: [PATCH] Explicitly rename DKG PublicKeys to avoid confusion with Validator PKs --- ferveo-tdec/benches/tpke.rs | 2 +- ferveo-tdec/src/ciphertext.rs | 4 ++-- ferveo-tdec/src/key_share.rs | 2 +- ferveo-tdec/src/lib.rs | 6 +++--- ferveo/src/api.rs | 25 +++++++++++++------------ ferveo/src/bindings_python.rs | 10 +++++----- ferveo/src/bindings_wasm.rs | 12 ++++++------ ferveo/src/pvss.rs | 8 ++++---- ferveo/src/validator.rs | 6 +++--- 9 files changed, 38 insertions(+), 37 deletions(-) diff --git a/ferveo-tdec/benches/tpke.rs b/ferveo-tdec/benches/tpke.rs index 25672b70..e5c7069a 100644 --- a/ferveo-tdec/benches/tpke.rs +++ b/ferveo-tdec/benches/tpke.rs @@ -20,7 +20,7 @@ struct SetupShared { shares_num: usize, msg: Vec, aad: Vec, - pubkey: PublicKey, + pubkey: DkgPublicKey, privkey: PrivateKeyShare, ciphertext: Ciphertext, shared_secret: SharedSecret, diff --git a/ferveo-tdec/src/ciphertext.rs b/ferveo-tdec/src/ciphertext.rs index 6d33946c..f110515f 100644 --- a/ferveo-tdec/src/ciphertext.rs +++ b/ferveo-tdec/src/ciphertext.rs @@ -14,7 +14,7 @@ use sha2::{digest::Digest, Sha256}; use zeroize::ZeroizeOnDrop; use crate::{ - htp_bls12381_g2, Error, PrivateKeyShare, PublicKey, Result, SecretBox, + htp_bls12381_g2, DkgPublicKey, Error, PrivateKeyShare, Result, SecretBox, SharedSecret, }; @@ -98,7 +98,7 @@ impl CiphertextHeader { pub fn encrypt( message: SecretBox>, aad: &[u8], - pubkey: &PublicKey, + pubkey: &DkgPublicKey, rng: &mut impl rand::Rng, ) -> Result> { // r diff --git a/ferveo-tdec/src/key_share.rs b/ferveo-tdec/src/key_share.rs index 07ea070a..d638cd34 100644 --- a/ferveo-tdec/src/key_share.rs +++ b/ferveo-tdec/src/key_share.rs @@ -9,7 +9,7 @@ use zeroize::{Zeroize, ZeroizeOnDrop}; #[serde_as] #[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct PublicKey( +pub struct DkgPublicKey( #[serde_as(as = "serialization::SerdeAs")] pub E::G1Affine, ); diff --git a/ferveo-tdec/src/lib.rs b/ferveo-tdec/src/lib.rs index 6cdb160e..5fffe02b 100644 --- a/ferveo-tdec/src/lib.rs +++ b/ferveo-tdec/src/lib.rs @@ -77,7 +77,7 @@ pub mod test_common { threshold: usize, rng: &mut impl rand::Rng, ) -> ( - PublicKey, + DkgPublicKey, PrivateKeyShare, Vec>, ) { @@ -178,7 +178,7 @@ pub mod test_common { } ( - PublicKey(group_pubkey.into()), + DkgPublicKey(group_pubkey.into()), PrivateKeyShare(group_privkey.into()), // TODO: Not the correct type, but whatever private_contexts, ) @@ -189,7 +189,7 @@ pub mod test_common { threshold: usize, rng: &mut impl rand::Rng, ) -> ( - PublicKey, + DkgPublicKey, PrivateKeyShare, Vec>, ) { diff --git a/ferveo/src/api.rs b/ferveo/src/api.rs index abd388cc..5cfd525b 100644 --- a/ferveo/src/api.rs +++ b/ferveo/src/api.rs @@ -27,8 +27,8 @@ use crate::{ PubliclyVerifiableSS, Result, }; -pub type PublicKey = ferveo_common::PublicKey; -pub type Keypair = ferveo_common::Keypair; +pub type ValidatorPublicKey = ferveo_common::PublicKey; +pub type ValidatorKeypair = ferveo_common::Keypair; pub type Validator = crate::Validator; pub type Transcript = PubliclyVerifiableSS; pub type ValidatorMessage = (Validator, Transcript); @@ -142,13 +142,13 @@ impl From for FerveoVariant { #[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] pub struct DkgPublicKey( #[serde(bound( - serialize = "ferveo_tdec::PublicKey: Serialize", - deserialize = "ferveo_tdec::PublicKey: DeserializeOwned" + serialize = "ferveo_tdec::DkgPublicKey: Serialize", + deserialize = "ferveo_tdec::DkgPublicKey: DeserializeOwned" ))] - pub(crate) ferveo_tdec::PublicKey, + pub(crate) ferveo_tdec::DkgPublicKey, ); -// TODO: Consider moving these implementation details to ferveo_tdec::PublicKey +// TODO: Consider moving these implementation details to ferveo_tdec::DkgPublicKey impl DkgPublicKey { pub fn to_bytes(&self) -> Result> { let as_bytes = to_bytes(&self.0 .0)?; @@ -165,7 +165,7 @@ impl DkgPublicKey { ) })?; let pk: G1Affine = from_bytes(&bytes)?; - Ok(DkgPublicKey(ferveo_tdec::PublicKey(pk))) + Ok(DkgPublicKey(ferveo_tdec::DkgPublicKey(pk))) } pub fn serialized_size() -> usize { @@ -177,7 +177,7 @@ impl DkgPublicKey { pub fn random() -> Self { let mut rng = thread_rng(); let g1 = G1Affine::rand(&mut rng); - Self(ferveo_tdec::PublicKey(g1)) + Self(ferveo_tdec::DkgPublicKey(g1)) } } @@ -304,7 +304,7 @@ impl AggregatedTranscript { dkg: &Dkg, ciphertext_header: &CiphertextHeader, aad: &[u8], - validator_keypair: &Keypair, + validator_keypair: &ValidatorKeypair, selected_validators: &[Validator], ) -> Result { let selected_domain_points = selected_validators @@ -330,7 +330,7 @@ impl AggregatedTranscript { dkg: &Dkg, ciphertext_header: &CiphertextHeader, aad: &[u8], - validator_keypair: &Keypair, + validator_keypair: &ValidatorKeypair, ) -> Result { let share = self.0.aggregate.create_decryption_share_simple( &ciphertext_header.0, @@ -388,7 +388,8 @@ mod test_ferveo_api { test_common::{gen_address, gen_keypairs, AAD, MSG, TAU}, }; - type TestInputs = (Vec, Vec, Vec); + type TestInputs = + (Vec, Vec, Vec); fn make_test_inputs( rng: &mut StdRng, @@ -816,7 +817,7 @@ mod test_ferveo_api { ) -> ( Vec, Vec, - Vec, + Vec, Vec, CiphertextHeader, SharedSecret, diff --git a/ferveo/src/bindings_python.rs b/ferveo/src/bindings_python.rs index 8fbf6222..14bcfc3f 100644 --- a/ferveo/src/bindings_python.rs +++ b/ferveo/src/bindings_python.rs @@ -352,7 +352,7 @@ generate_bytes_serialization!(SharedSecret); #[pyclass(module = "ferveo")] #[derive(derive_more::From, derive_more::AsRef)] -pub struct Keypair(api::Keypair); +pub struct Keypair(api::ValidatorKeypair); generate_bytes_serialization!(Keypair); @@ -360,20 +360,20 @@ generate_bytes_serialization!(Keypair); impl Keypair { #[staticmethod] pub fn random() -> Self { - Self(api::Keypair::random()) + Self(api::ValidatorKeypair::random()) } #[staticmethod] pub fn from_secure_randomness(secure_randomness: &[u8]) -> PyResult { let keypair = - api::Keypair::from_secure_randomness(secure_randomness) + api::ValidatorKeypair::from_secure_randomness(secure_randomness) .map_err(|err| FerveoPythonError::Other(err.to_string()))?; Ok(Self(keypair)) } #[staticmethod] pub fn secure_randomness_size() -> usize { - api::Keypair::secure_randomness_size() + api::ValidatorKeypair::secure_randomness_size() } pub fn public_key(&self) -> FerveoPublicKey { @@ -381,7 +381,7 @@ impl Keypair { } } -type InnerPublicKey = api::PublicKey; +type InnerPublicKey = api::ValidatorPublicKey; #[pyclass(module = "ferveo")] #[derive( diff --git a/ferveo/src/bindings_wasm.rs b/ferveo/src/bindings_wasm.rs index 0b369874..2995541a 100644 --- a/ferveo/src/bindings_wasm.rs +++ b/ferveo/src/bindings_wasm.rs @@ -206,7 +206,7 @@ pub struct DecryptionSharePrecomputed( generate_common_methods!(DecryptionSharePrecomputed); -type InnerPublicKey = api::PublicKey; +type InnerPublicKey = api::ValidatorPublicKey; #[wasm_bindgen] #[derive( @@ -582,7 +582,7 @@ impl AggregatedTranscript { #[wasm_bindgen] #[derive(Serialize, Deserialize)] -pub struct Keypair(api::Keypair); +pub struct Keypair(api::ValidatorKeypair); generate_common_methods!(Keypair); @@ -590,7 +590,7 @@ generate_common_methods!(Keypair); impl Keypair { #[wasm_bindgen(getter, js_name = "secureRandomnessSize")] pub fn secure_randomness_size() -> usize { - api::Keypair::secure_randomness_size() + api::ValidatorKeypair::secure_randomness_size() } #[wasm_bindgen(getter, js_name = "publicKey")] @@ -600,14 +600,14 @@ impl Keypair { #[wasm_bindgen] pub fn random() -> Self { - Self(api::Keypair::new(&mut thread_rng())) + Self(api::ValidatorKeypair::new(&mut thread_rng())) } #[wasm_bindgen(js_name = "fromSecureRandomness")] pub fn from_secure_randomness(bytes: &[u8]) -> JsResult { set_panic_hook(); - let keypair = - api::Keypair::from_secure_randomness(bytes).map_err(map_js_err)?; + let keypair = api::ValidatorKeypair::from_secure_randomness(bytes) + .map_err(map_js_err)?; Ok(Self(keypair)) } } diff --git a/ferveo/src/pvss.rs b/ferveo/src/pvss.rs index 877f5108..f340d000 100644 --- a/ferveo/src/pvss.rs +++ b/ferveo/src/pvss.rs @@ -438,10 +438,10 @@ pub struct AggregatedTranscript { ))] pub aggregate: PubliclyVerifiableSS, #[serde(bound( - serialize = "ferveo_tdec::PublicKey: Serialize", - deserialize = "ferveo_tdec::PublicKey: DeserializeOwned" + serialize = "ferveo_tdec::DkgPublicKey: Serialize", + deserialize = "ferveo_tdec::DkgPublicKey: DeserializeOwned" ))] - pub public_key: ferveo_tdec::PublicKey, + pub public_key: ferveo_tdec::DkgPublicKey, } impl AggregatedTranscript { @@ -454,7 +454,7 @@ impl AggregatedTranscript { .map(|pvss| pvss.coeffs[0].into_group()) .sum::() .into_affine(); - let public_key = ferveo_tdec::PublicKey::(public_key); + let public_key = ferveo_tdec::DkgPublicKey::(public_key); Ok(AggregatedTranscript { aggregate, public_key, diff --git a/ferveo/src/validator.rs b/ferveo/src/validator.rs index f0d88e49..fb55f3bc 100644 --- a/ferveo/src/validator.rs +++ b/ferveo/src/validator.rs @@ -1,7 +1,7 @@ use std::{collections::HashSet, fmt::Display, str::FromStr}; use ark_ec::pairing::Pairing; -use ferveo_common::PublicKey; +use ferveo_common::PublicKey as ValidatorPublicKey; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -49,7 +49,7 @@ pub struct Validator { /// The established address of the validator pub address: EthereumAddress, /// The Public key - pub public_key: PublicKey, + pub public_key: ValidatorPublicKey, /// The index of the validator in the given ritual pub share_index: u32, } @@ -57,7 +57,7 @@ pub struct Validator { impl Validator { pub fn new( address: String, - public_key: PublicKey, + public_key: ValidatorPublicKey, share_index: u32, ) -> Result { Ok(Self {