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

Merge main and auxiliary Paillier key and ring-Pedersen parameters #42

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 9 additions & 66 deletions synedrion/src/cggmp21/protocols/auxiliary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,13 @@ enum KeyRefreshErrorEnum<P: SchemeParams> {
#[serde(bound(serialize = "PrmProof<P>: Serialize"))]
#[serde(bound(deserialize = "PrmProof<P>: for<'x> Deserialize<'x>"))]
pub struct FullData<P: SchemeParams> {
xs_public: Vec<Point>, // $\bm{X}_i$
sch_commitments_x: Vec<SchCommitment>, // $\bm{A}_i$
el_gamal_pk: Point, // $Y_i$,
el_gamal_commitment: SchCommitment, // $B_i$
paillier_pk: PublicKeyPaillier<P::Paillier>, // $N_i$
aux_paillier_pk: PublicKeyPaillier<P::Paillier>, // $\hat{N}_i$
rp_params: RPParams<P::Paillier>, // $s_i$ and $t_i$
prm_proof: PrmProof<P>, // $\hat{\psi}_i$
aux_rp_params: RPParams<P::Paillier>, // setup parameters($s_i$ and $t_i$ for $\hat{N}$)
aux_prm_proof: PrmProof<P>, // a proof for the setup parameters
xs_public: Vec<Point>, // $\bm{X}_i$
sch_commitments_x: Vec<SchCommitment>, // $\bm{A}_i$
el_gamal_pk: Point, // $Y_i$,
el_gamal_commitment: SchCommitment, // $B_i$
paillier_pk: PublicKeyPaillier<P::Paillier>, // $N_i$
rp_params: RPParams<P::Paillier>, // $s_i$ and $t_i$
prm_proof: PrmProof<P>, // $\hat{\psi}_i$
#[serde(with = "serde_bytes::as_base64")]
rho_bits: Box<[u8]>, // $\rho_i$
#[serde(with = "serde_bytes::as_base64")]
Expand All @@ -83,14 +80,11 @@ pub struct FullData<P: SchemeParams> {
pub struct FullDataPrecomp<P: SchemeParams> {
data: FullData<P>,
paillier_pk: PublicKeyPaillierPrecomputed<P::Paillier>, // $N_i$
aux_paillier_pk: PublicKeyPaillierPrecomputed<P::Paillier>, // $\hat{N}_i$
rp_params: RPParamsMod<P::Paillier>, // $s_i$ and $t_i$
aux_rp_params: RPParamsMod<P::Paillier>, // setup parameters($s_i$ and $t_i$ for $\hat{N}$)
}

struct Context<P: SchemeParams> {
paillier_sk: SecretKeyPaillierPrecomputed<P::Paillier>,
aux_paillier_sk: SecretKeyPaillierPrecomputed<P::Paillier>,
el_gamal_sk: Scalar,
xs_secret: Vec<Scalar>,
el_gamal_proof_secret: SchSecret,
Expand All @@ -109,11 +103,8 @@ impl<P: SchemeParams> Hashable for FullData<P> {
.chain(&self.el_gamal_pk)
.chain(&self.el_gamal_commitment)
.chain(&self.paillier_pk)
.chain(&self.aux_paillier_pk)
.chain(&self.rp_params)
.chain(&self.prm_proof)
.chain(&self.aux_rp_params)
.chain(&self.aux_prm_proof)
.chain(&self.rho_bits)
.chain(&self.u_bits)
}
Expand Down Expand Up @@ -160,21 +151,9 @@ impl<P: SchemeParams> FirstRound for Round1<P> {
let rp_secret = RPSecret::random(rng, &paillier_sk);
let rp_params = RPParamsMod::random_with_secret(rng, &rp_secret, paillier_pk);

// CHECK: This is not a part of the KeyRefresh/Aux protocol in Fig.6, but according to
// "Generating the Setup Parameter for the Range Proofs" in Section 2.3,
// the verifier generates the auxiliary RP params (and the corresponding
// P^{mod} and P^{prm} proofs), so this seems like the right place to do it.
let aux_paillier_sk = SecretKeyPaillier::<P::Paillier>::random(rng).to_precomputed();
let aux_paillier_pk = aux_paillier_sk.public_key();
let aux_rp_secret = RPSecret::random(rng, &aux_paillier_sk);
let aux_rp_params = RPParamsMod::random_with_secret(rng, &aux_rp_secret, aux_paillier_pk);

let aux = (&shared_randomness, &party_idx);
let prm_proof = PrmProof::<P>::random(rng, &paillier_sk, &rp_secret, &rp_params, &aux);

let aux_prm_proof =
PrmProof::<P>::random(rng, &aux_paillier_sk, &aux_rp_secret, &aux_rp_params, &aux);

// $\tau_j$
let sch_secrets_x: Vec<SchSecret> =
(0..num_parties).map(|_| SchSecret::random(rng)).collect();
Expand All @@ -191,26 +170,20 @@ impl<P: SchemeParams> FirstRound for Round1<P> {
el_gamal_pk,
el_gamal_commitment,
paillier_pk: paillier_pk.to_minimal(),
aux_paillier_pk: aux_paillier_pk.to_minimal(),
rp_params: rp_params.retrieve(),
aux_rp_params: aux_rp_params.retrieve(),
prm_proof,
aux_prm_proof,
rho_bits: rho_bits.clone(),
u_bits: u_bits.clone(),
};

let data_precomp = FullDataPrecomp {
data,
paillier_pk: paillier_pk.clone(),
aux_paillier_pk: aux_paillier_pk.clone(),
rp_params,
aux_rp_params,
};

let context = Context {
paillier_sk,
aux_paillier_sk,
el_gamal_sk,
xs_secret,
sch_secrets_x,
Expand Down Expand Up @@ -378,20 +351,10 @@ impl<P: SchemeParams> BroadcastRound for Round2<P> {
)));
}

let aux_paillier_pk = msg.data.aux_paillier_pk.to_precomputed();
let aux_rp_params = msg.data.aux_rp_params.to_mod(&aux_paillier_pk);
if !msg.data.aux_prm_proof.verify(&aux_rp_params, &aux) {
return Err(ReceiveError::Provable(KeyRefreshError(
KeyRefreshErrorEnum::Round2("PRM verification (setup parameters) failed".into()),
)));
}

Ok(FullDataPrecomp {
data: msg.data,
paillier_pk,
aux_paillier_pk,
rp_params,
aux_rp_params,
})
}
}
Expand Down Expand Up @@ -426,7 +389,6 @@ pub struct Round3<P: SchemeParams> {
rho: Box<[u8]>,
datas: HoleVec<FullDataPrecomp<P>>,
mod_proof: ModProof<P>,
aux_mod_proof: ModProof<P>,
sch_proof_y: SchProof,
}

Expand All @@ -439,7 +401,6 @@ pub struct Round3<P: SchemeParams> {
Ciphertext<P::Paillier>: for<'x> Deserialize<'x>"))]
pub struct FullData2<P: SchemeParams> {
mod_proof: ModProof<P>, // `psi_j`
aux_mod_proof: ModProof<P>, // $P^{mod}$ for the setup parameters
fac_proof: FacProof<P>, // `phi_j,i`
sch_proof_y: SchProof, // `pi_i`
paillier_enc_x: Ciphertext<P::Paillier>, // `C_j,i`
Expand All @@ -463,8 +424,6 @@ impl<P: SchemeParams> Round3<P> {
let aux = (&context.shared_randomness, &rho, &context.party_idx);
let mod_proof = ModProof::random(rng, &context.paillier_sk, &aux);

let aux_mod_proof = ModProof::random(rng, &context.aux_paillier_sk, &aux);

let sch_proof_y = SchProof::new(
&context.el_gamal_proof_secret,
&context.el_gamal_sk,
Expand All @@ -478,7 +437,6 @@ impl<P: SchemeParams> Round3<P> {
datas,
rho,
mod_proof,
aux_mod_proof,
sch_proof_y,
}
}
Expand Down Expand Up @@ -525,7 +483,7 @@ impl<P: SchemeParams> DirectRound for Round3<P> {
let fac_proof = FacProof::random(
rng,
&self.context.paillier_sk,
&self.datas.get(idx).unwrap().aux_rp_params,
&self.datas.get(idx).unwrap().rp_params,
&aux,
);

Expand All @@ -543,7 +501,6 @@ impl<P: SchemeParams> DirectRound for Round3<P> {

let data2 = FullData2 {
mod_proof: self.mod_proof.clone(),
aux_mod_proof: self.aux_mod_proof.clone(),
fac_proof,
sch_proof_y: self.sch_proof_y.clone(),
paillier_enc_x: ciphertext,
Expand Down Expand Up @@ -590,21 +547,9 @@ impl<P: SchemeParams> DirectRound for Round3<P> {
)));
}

if !msg
.data2
.aux_mod_proof
.verify(&sender_data.aux_paillier_pk, &aux)
{
return Err(ReceiveError::Provable(KeyRefreshError(
KeyRefreshErrorEnum::Round3(
"Mod proof (setup parameters) verification failed".into(),
),
)));
}

if !msg.data2.fac_proof.verify(
&sender_data.paillier_pk,
&self.context.data_precomp.aux_rp_params,
&self.context.data_precomp.rp_params,
&aux,
) {
return Err(ReceiveError::Provable(KeyRefreshError(
Expand Down Expand Up @@ -665,9 +610,7 @@ impl<P: SchemeParams> FinalizableToResult for Round3<P> {
.map(|data| PublicAuxInfo {
el_gamal_pk: data.data.el_gamal_pk,
paillier_pk: data.paillier_pk.to_minimal(),
aux_paillier_pk: data.aux_paillier_pk.to_minimal(),
rp_params: data.rp_params.retrieve(),
aux_rp_params: data.aux_rp_params.retrieve(),
})
.collect();

Expand Down
10 changes: 0 additions & 10 deletions synedrion/src/cggmp21/protocols/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ pub(crate) struct PublicAuxInfo<P: SchemeParams> {
pub(crate) el_gamal_pk: Point, // `Y_i`
/// The Paillier public key.
pub(crate) paillier_pk: PublicKeyPaillier<P::Paillier>,
/// Auxiliary public key and ring-Pedersen parameters (for ZK proofs).
pub(crate) aux_paillier_pk: PublicKeyPaillier<P::Paillier>,
pub(crate) aux_rp_params: RPParams<P::Paillier>,
/// The ring-Pedersen parameters.
pub(crate) rp_params: RPParams<P::Paillier>, // `s_i` and `t_i`
}
Expand All @@ -118,8 +115,6 @@ pub(crate) struct PublicAuxInfoPrecomputed<P: SchemeParams> {
#[allow(dead_code)]
pub(crate) el_gamal_pk: Point,
pub(crate) paillier_pk: PublicKeyPaillierPrecomputed<P::Paillier>,
pub(crate) aux_rp_params: RPParamsMod<P::Paillier>,
#[allow(dead_code)]
pub(crate) rp_params: RPParamsMod<P::Paillier>,
}

Expand Down Expand Up @@ -243,12 +238,10 @@ impl<P: SchemeParams> KeyShare<P> {
.iter()
.map(|public_aux| {
let paillier_pk = public_aux.paillier_pk.to_precomputed();
let aux_paillier_pk = public_aux.aux_paillier_pk.to_precomputed();
PublicAuxInfoPrecomputed {
el_gamal_pk: public_aux.el_gamal_pk,
paillier_pk: paillier_pk.clone(),
rp_params: public_aux.rp_params.to_mod(&paillier_pk),
aux_rp_params: public_aux.aux_rp_params.to_mod(&aux_paillier_pk),
}
})
.collect(),
Expand Down Expand Up @@ -454,11 +447,8 @@ pub(crate) fn make_aux_info<P: SchemeParams>(
.iter()
.map(|secret| {
let sk = secret.paillier_sk.to_precomputed();
let aux_sk = SecretKeyPaillier::<P::Paillier>::random(rng).to_precomputed();
PublicAuxInfo {
paillier_pk: sk.public_key().to_minimal(),
aux_paillier_pk: aux_sk.public_key().to_minimal(),
aux_rp_params: RPParamsMod::random(rng, &aux_sk).retrieve(),
el_gamal_pk: secret.el_gamal_sk.mul_by_generator(),
rp_params: RPParamsMod::random(rng, &sk).retrieve(),
}
Expand Down
32 changes: 16 additions & 16 deletions synedrion/src/cggmp21/protocols/presigning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl<P: SchemeParams> DirectRound for Round1<P> {
&Signed::from_scalar(&self.context.ephemeral_scalar_share),
&self.context.rho,
&self.context.key_share.secret_aux.paillier_sk,
&self.context.key_share.public_aux[destination.as_usize()].aux_rp_params,
&self.context.key_share.public_aux[destination.as_usize()].rp_params,
&aux,
);
Ok((Round1Direct(proof), ()))
Expand Down Expand Up @@ -218,7 +218,7 @@ impl<P: SchemeParams> FinalizableToNextRound for Round1<P> {
if !proof.0.verify(
&self.context.key_share.public_aux[from].paillier_pk,
&ciphertexts.k_ciphertext,
&public_aux.aux_rp_params,
&public_aux.rp_params,
&aux,
) {
return Err(FinalizeError::Provable {
Expand Down Expand Up @@ -353,7 +353,7 @@ impl<P: SchemeParams> DirectRound for Round2<P> {
let f_hat = Ciphertext::new_with_randomizer_signed(pk, &beta_hat, &r_hat.retrieve());

let public_aux = &self.context.key_share.public_aux[idx];
let aux_rp = &public_aux.aux_rp_params;
let rp = &public_aux.rp_params;

let psi = AffGProof::random(
rng,
Expand All @@ -364,7 +364,7 @@ impl<P: SchemeParams> DirectRound for Round2<P> {
target_pk,
pk,
&self.k_ciphertexts[idx],
aux_rp,
rp,
&aux,
);

Expand All @@ -377,7 +377,7 @@ impl<P: SchemeParams> DirectRound for Round2<P> {
target_pk,
pk,
&self.k_ciphertexts[idx],
aux_rp,
rp,
&aux,
);

Expand All @@ -387,7 +387,7 @@ impl<P: SchemeParams> DirectRound for Round2<P> {
&self.context.nu,
pk,
&Point::GENERATOR,
aux_rp,
rp,
&aux,
);

Expand Down Expand Up @@ -429,7 +429,7 @@ impl<P: SchemeParams> DirectRound for Round2<P> {

let public_aux =
&self.context.key_share.public_aux[self.context.key_share.party_index().as_usize()];
let aux_rp = &public_aux.aux_rp_params;
let rp = &public_aux.rp_params;

if !msg.psi.verify(
pk,
Expand All @@ -438,7 +438,7 @@ impl<P: SchemeParams> DirectRound for Round2<P> {
&msg.d,
&msg.f,
&msg.gamma,
aux_rp,
rp,
&aux,
) {
return Err(ReceiveError::Provable(PresigningError::Round2(
Expand All @@ -453,7 +453,7 @@ impl<P: SchemeParams> DirectRound for Round2<P> {
&msg.d_hat,
&msg.f_hat,
&big_x,
aux_rp,
rp,
&aux,
) {
return Err(ReceiveError::Provable(PresigningError::Round2(
Expand All @@ -466,7 +466,7 @@ impl<P: SchemeParams> DirectRound for Round2<P> {
&self.g_ciphertexts[from.as_usize()],
&Point::GENERATOR,
&msg.gamma,
aux_rp,
rp,
&aux,
) {
return Err(ReceiveError::Provable(PresigningError::Round2(
Expand Down Expand Up @@ -612,15 +612,15 @@ impl<P: SchemeParams> DirectRound for Round3<P> {
let idx = destination.as_usize();

let public_aux = &self.context.key_share.public_aux[idx];
let aux_rp = &public_aux.aux_rp_params;
let rp = &public_aux.rp_params;

let psi_hat_pprime = LogStarProof::random(
rng,
&Signed::from_scalar(&self.context.ephemeral_scalar_share),
&self.context.rho,
pk,
&self.big_gamma,
aux_rp,
rp,
&aux,
);
let message = Round3Direct {
Expand All @@ -642,14 +642,14 @@ impl<P: SchemeParams> DirectRound for Round3<P> {

let public_aux =
&self.context.key_share.public_aux[self.context.key_share.party_index().as_usize()];
let aux_rp = &public_aux.aux_rp_params;
let rp = &public_aux.rp_params;

if !msg.psi_hat_pprime.verify(
from_pk,
&self.k_ciphertexts[from.as_usize()],
&self.big_gamma,
&msg.big_delta,
aux_rp,
rp,
&aux,
) {
return Err(ReceiveError::Provable(PresigningError::Round3(
Expand Down Expand Up @@ -746,7 +746,7 @@ impl<P: SchemeParams> FinalizableToResult for Round3<P> {
// Should we have a "double hole vec" for that?
for l in HoleRange::new(num_parties, my_idx) {
let target_pk = &self.context.key_share.public_aux[j].paillier_pk;
let aux_rp = &self.context.key_share.public_aux[l].aux_rp_params;
let rp = &self.context.key_share.public_aux[l].rp_params;

let p_aff_g = AffGProof::<P>::random(
rng,
Expand All @@ -757,7 +757,7 @@ impl<P: SchemeParams> FinalizableToResult for Round3<P> {
target_pk,
pk,
&self.k_ciphertexts[j],
aux_rp,
rp,
&aux,
);

Expand Down
Loading