Skip to content

Commit

Permalink
Explicitly rename DKG PublicKeys to avoid confusion with Validator PKs
Browse files Browse the repository at this point in the history
  • Loading branch information
cygnusv committed Sep 23, 2024
1 parent 90c0d2c commit 966e265
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 37 deletions.
2 changes: 1 addition & 1 deletion ferveo-tdec/benches/tpke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct SetupShared {
shares_num: usize,
msg: Vec<u8>,
aad: Vec<u8>,
pubkey: PublicKey<E>,
pubkey: DkgPublicKey<E>,
privkey: PrivateKeyShare<E>,
ciphertext: Ciphertext<E>,
shared_secret: SharedSecret<E>,
Expand Down
4 changes: 2 additions & 2 deletions ferveo-tdec/src/ciphertext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -98,7 +98,7 @@ impl<E: Pairing> CiphertextHeader<E> {
pub fn encrypt<E: Pairing>(
message: SecretBox<Vec<u8>>,
aad: &[u8],
pubkey: &PublicKey<E>,
pubkey: &DkgPublicKey<E>,
rng: &mut impl rand::Rng,
) -> Result<Ciphertext<E>> {
// r
Expand Down
2 changes: 1 addition & 1 deletion ferveo-tdec/src/key_share.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use zeroize::{Zeroize, ZeroizeOnDrop};

#[serde_as]
#[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct PublicKey<E: Pairing>(
pub struct DkgPublicKey<E: Pairing>(
#[serde_as(as = "serialization::SerdeAs")] pub E::G1Affine,
);

Expand Down
6 changes: 3 additions & 3 deletions ferveo-tdec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub mod test_common {
threshold: usize,
rng: &mut impl rand::Rng,
) -> (
PublicKey<E>,
DkgPublicKey<E>,
PrivateKeyShare<E>,
Vec<PrivateDecryptionContextSimple<E>>,
) {
Expand Down Expand Up @@ -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,
)
Expand All @@ -189,7 +189,7 @@ pub mod test_common {
threshold: usize,
rng: &mut impl rand::Rng,
) -> (
PublicKey<E>,
DkgPublicKey<E>,
PrivateKeyShare<E>,
Vec<PrivateDecryptionContextSimple<E>>,
) {
Expand Down
25 changes: 13 additions & 12 deletions ferveo/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use crate::{
PubliclyVerifiableSS, Result,
};

pub type PublicKey = ferveo_common::PublicKey<E>;
pub type Keypair = ferveo_common::Keypair<E>;
pub type ValidatorPublicKey = ferveo_common::PublicKey<E>;
pub type ValidatorKeypair = ferveo_common::Keypair<E>;
pub type Validator = crate::Validator<E>;
pub type Transcript = PubliclyVerifiableSS<E>;
pub type ValidatorMessage = (Validator, Transcript);
Expand Down Expand Up @@ -142,13 +142,13 @@ impl From<bindings_wasm::FerveoVariant> for FerveoVariant {
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct DkgPublicKey(
#[serde(bound(
serialize = "ferveo_tdec::PublicKey<E>: Serialize",
deserialize = "ferveo_tdec::PublicKey<E>: DeserializeOwned"
serialize = "ferveo_tdec::DkgPublicKey<E>: Serialize",
deserialize = "ferveo_tdec::DkgPublicKey<E>: DeserializeOwned"
))]
pub(crate) ferveo_tdec::PublicKey<E>,
pub(crate) ferveo_tdec::DkgPublicKey<E>,
);

// 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<GenericArray<u8, U48>> {
let as_bytes = to_bytes(&self.0 .0)?;
Expand All @@ -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 {
Expand All @@ -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))
}
}

Expand Down Expand Up @@ -304,7 +304,7 @@ impl AggregatedTranscript {
dkg: &Dkg,
ciphertext_header: &CiphertextHeader,
aad: &[u8],
validator_keypair: &Keypair,
validator_keypair: &ValidatorKeypair,
selected_validators: &[Validator],
) -> Result<DecryptionSharePrecomputed> {
let selected_domain_points = selected_validators
Expand All @@ -330,7 +330,7 @@ impl AggregatedTranscript {
dkg: &Dkg,
ciphertext_header: &CiphertextHeader,
aad: &[u8],
validator_keypair: &Keypair,
validator_keypair: &ValidatorKeypair,
) -> Result<DecryptionShareSimple> {
let share = self.0.aggregate.create_decryption_share_simple(
&ciphertext_header.0,
Expand Down Expand Up @@ -388,7 +388,8 @@ mod test_ferveo_api {
test_common::{gen_address, gen_keypairs, AAD, MSG, TAU},
};

type TestInputs = (Vec<ValidatorMessage>, Vec<Validator>, Vec<Keypair>);
type TestInputs =
(Vec<ValidatorMessage>, Vec<Validator>, Vec<ValidatorKeypair>);

fn make_test_inputs(
rng: &mut StdRng,
Expand Down Expand Up @@ -816,7 +817,7 @@ mod test_ferveo_api {
) -> (
Vec<ValidatorMessage>,
Vec<Validator>,
Vec<Keypair>,
Vec<ValidatorKeypair>,
Vec<Dkg>,
CiphertextHeader,
SharedSecret,
Expand Down
10 changes: 5 additions & 5 deletions ferveo/src/bindings_python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,36 +352,36 @@ 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);

#[pymethods]
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<Self> {
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 {
FerveoPublicKey(self.0.public_key())
}
}

type InnerPublicKey = api::PublicKey;
type InnerPublicKey = api::ValidatorPublicKey;

#[pyclass(module = "ferveo")]
#[derive(
Expand Down
12 changes: 6 additions & 6 deletions ferveo/src/bindings_wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ pub struct DecryptionSharePrecomputed(

generate_common_methods!(DecryptionSharePrecomputed);

type InnerPublicKey = api::PublicKey;
type InnerPublicKey = api::ValidatorPublicKey;

#[wasm_bindgen]
#[derive(
Expand Down Expand Up @@ -582,15 +582,15 @@ impl AggregatedTranscript {

#[wasm_bindgen]
#[derive(Serialize, Deserialize)]
pub struct Keypair(api::Keypair);
pub struct Keypair(api::ValidatorKeypair);

generate_common_methods!(Keypair);

#[wasm_bindgen]
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")]
Expand All @@ -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<Keypair> {
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))
}
}
Expand Down
8 changes: 4 additions & 4 deletions ferveo/src/pvss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,10 @@ pub struct AggregatedTranscript<E: Pairing> {
))]
pub aggregate: PubliclyVerifiableSS<E, Aggregated>,
#[serde(bound(
serialize = "ferveo_tdec::PublicKey<E>: Serialize",
deserialize = "ferveo_tdec::PublicKey<E>: DeserializeOwned"
serialize = "ferveo_tdec::DkgPublicKey<E>: Serialize",
deserialize = "ferveo_tdec::DkgPublicKey<E>: DeserializeOwned"
))]
pub public_key: ferveo_tdec::PublicKey<E>,
pub public_key: ferveo_tdec::DkgPublicKey<E>,
}

impl<E: Pairing> AggregatedTranscript<E> {
Expand All @@ -454,7 +454,7 @@ impl<E: Pairing> AggregatedTranscript<E> {
.map(|pvss| pvss.coeffs[0].into_group())
.sum::<E::G1>()
.into_affine();
let public_key = ferveo_tdec::PublicKey::<E>(public_key);
let public_key = ferveo_tdec::DkgPublicKey::<E>(public_key);
Ok(AggregatedTranscript {
aggregate,
public_key,
Expand Down
6 changes: 3 additions & 3 deletions ferveo/src/validator.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -49,15 +49,15 @@ pub struct Validator<E: Pairing> {
/// The established address of the validator
pub address: EthereumAddress,
/// The Public key
pub public_key: PublicKey<E>,
pub public_key: ValidatorPublicKey<E>,
/// The index of the validator in the given ritual
pub share_index: u32,
}

impl<E: Pairing> Validator<E> {
pub fn new(
address: String,
public_key: PublicKey<E>,
public_key: ValidatorPublicKey<E>,
share_index: u32,
) -> Result<Self, EthereumAddressParseError> {
Ok(Self {
Expand Down

0 comments on commit 966e265

Please sign in to comment.