Skip to content

Commit

Permalink
refactor: define RingPedersenParams structure
Browse files Browse the repository at this point in the history
  • Loading branch information
ivokub committed Nov 6, 2023
1 parent 86ddbc5 commit 70309b2
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 201 deletions.
24 changes: 5 additions & 19 deletions fs-dkr/src/add_party_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,13 @@ pub struct JoinMessage<E: Curve, H: Digest + Clone, const M: usize> {
/// generated by [generate_h1_h2_n_tilde]
fn generate_dlog_statement_proofs(
) -> FsDkrResult<(PiPrmStatement, PiPrmProof, PiPrmProof)> {
let (n_tilde, h1, h2, xhi, xhi_inv, phi) = generate_safe_h1_h2_N_tilde();
let (rpparam, rpwitness) = generate_safe_h1_h2_N_tilde();

let dlog_statement_base_h1 = PiPrmStatement {
modulus: n_tilde.clone(),
base: h1.clone(),
value: h2.clone(),
};
let dlog_witness_base_h1 = PiPrmWitness {
exponent: xhi,
totient: phi.clone(),
};
let dlog_statement_base_h1 = PiPrmStatement::from(&rpparam);
let dlog_witness_base_h1 = PiPrmWitness::from(&rpwitness);

let dlog_statement_base_h2 = PiPrmStatement {
modulus: n_tilde,
base: h2,
value: h1,
};
let dlog_witness_base_h2 = PiPrmWitness {
exponent: xhi_inv,
totient: phi.clone(),
};
let dlog_statement_base_h2 = PiPrmStatement::inverse_from(&rpparam);
let dlog_witness_base_h2 = PiPrmWitness::inverse_from(&rpwitness);

let composite_dlog_proof_base_h1 =
PiPrmProof::prove(&dlog_statement_base_h1, &dlog_witness_base_h1)
Expand Down
81 changes: 38 additions & 43 deletions multi-party-ecdsa/src/gg_2020/party_i.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ use curv::cryptographic_primitives::proofs::sigma_valid_pedersen::PedersenProof;
use std::convert::TryInto;

use tss_core::{
utilities::generate_safe_h1_h2_N_tilde,
utilities::{generate_normal_h1_h2_N_tilde, generate_safe_h1_h2_N_tilde},
zkproof::prm::{PiPrmProof, PiPrmStatement, PiPrmWitness},
};

Expand Down Expand Up @@ -155,21 +155,20 @@ impl Keys {
let u = Scalar::<Secp256k1>::random();
let y = Point::generator() * &u;
let (ek, dk) = Paillier::keypair().keys();
let (N_tilde, h1, h2, xhi, xhi_inv, phi) =
generate_safe_h1_h2_N_tilde();
let (rpparam, rpwitness) = generate_safe_h1_h2_N_tilde();

Self {
u_i: u,
y_i: y,
dk,
ek,
dk: dk,
ek: ek,
party_index: index,
N_tilde,
h1,
h2,
xhi,
xhi_inv,
phi,
N_tilde: rpparam.N,
h1: rpparam.s,
h2: rpparam.t,
xhi: rpwitness.lambda,
xhi_inv: rpwitness.lambdaInv,
phi: rpwitness.phi,
}
}

Expand All @@ -179,41 +178,39 @@ impl Keys {
let y = Point::generator() * &u;

let (ek, dk) = Paillier::keypair_safe_primes().keys();
let (N_tilde, h1, h2, xhi, xhi_inv, phi) =
generate_safe_h1_h2_N_tilde();
let (rpparam, rpwitness) = generate_safe_h1_h2_N_tilde();

Self {
u_i: u,
y_i: y,
dk,
ek,
party_index: index,
N_tilde,
h1,
h2,
xhi,
xhi_inv,
phi,
N_tilde: rpparam.N,
h1: rpparam.s,
h2: rpparam.t,
xhi: rpwitness.lambda,
xhi_inv: rpwitness.lambdaInv,
phi: rpwitness.phi,
}
}
pub fn create_from(u: Scalar<Secp256k1>, index: usize) -> Self {
let y = Point::generator() * &u;
let (ek, dk) = Paillier::keypair().keys();
let (N_tilde, h1, h2, xhi, xhi_inv, phi) =
generate_safe_h1_h2_N_tilde();
let (rpparam, rpwitness) = generate_normal_h1_h2_N_tilde();

Self {
u_i: u,
y_i: y,
dk,
ek,
party_index: index,
N_tilde,
h1,
h2,
xhi,
xhi_inv,
phi,
N_tilde: rpparam.N,
h1: rpparam.s,
h2: rpparam.t,
xhi: rpwitness.lambda,
xhi_inv: rpwitness.lambdaInv,
phi: rpwitness.phi,
}
}

Expand Down Expand Up @@ -550,21 +547,20 @@ impl PartyPrivate {
let y = Point::generator() * &u;
let (ek, dk) = Paillier::keypair().keys();

let (N_tilde, h1, h2, xhi, xhi_inv, phi) =
generate_safe_h1_h2_N_tilde();
let (rpparam, rpwitness) = generate_normal_h1_h2_N_tilde();

Keys {
u_i: u,
y_i: y,
dk,
ek,
party_index: index,
N_tilde,
h1,
h2,
xhi,
xhi_inv,
phi,
N_tilde: rpparam.N,
h1: rpparam.s,
h2: rpparam.t,
xhi: rpwitness.lambda,
xhi_inv: rpwitness.lambdaInv,
phi: rpwitness.phi,
}
}

Expand All @@ -578,21 +574,20 @@ impl PartyPrivate {
let y = Point::generator() * &u;
let (ek, dk) = Paillier::keypair_safe_primes().keys();

let (N_tilde, h1, h2, xhi, xhi_inv, phi) =
generate_safe_h1_h2_N_tilde();
let (rpparam, rpwitness) = generate_safe_h1_h2_N_tilde();

Keys {
u_i: u,
y_i: y,
dk,
ek,
party_index: index,
N_tilde,
h1,
h2,
xhi,
xhi_inv,
phi,
N_tilde: rpparam.N,
h1: rpparam.s,
h2: rpparam.t,
xhi: rpwitness.lambda,
xhi_inv: rpwitness.lambdaInv,
phi: rpwitness.phi,
}
}

Expand Down
77 changes: 36 additions & 41 deletions src/party_i.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub use crate::mpc_ecdsa::{
},
};
use tss_core::{
utilities::generate_safe_h1_h2_N_tilde,
utilities::{generate_normal_h1_h2_N_tilde, generate_safe_h1_h2_N_tilde},
zkproof::prm::{PiPrmProof, PiPrmStatement, PiPrmWitness},
};

Expand Down Expand Up @@ -136,21 +136,20 @@ impl Keys {
let u = Scalar::<Secp256k1>::random();
let y = Point::generator() * &u;
let (ek, dk) = Paillier::keypair().keys();
let (N_tilde, h1, h2, xhi, xhi_inv, phi) =
generate_safe_h1_h2_N_tilde();
let (rpparam, rpwitness) = generate_safe_h1_h2_N_tilde();

Self {
u_i: u,
y_i: y,
dk,
ek,
party_index: index,
N_tilde,
h1,
h2,
xhi,
xhi_inv,
phi,
N_tilde: rpparam.N,
h1: rpparam.s,
h2: rpparam.t,
xhi: rpwitness.lambda,
xhi_inv: rpwitness.lambdaInv,
phi: rpwitness.phi,
}
}

Expand All @@ -160,41 +159,39 @@ impl Keys {
let y = Point::generator() * &u;

let (ek, dk) = Paillier::keypair_safe_primes().keys();
let (N_tilde, h1, h2, xhi, xhi_inv, phi) =
generate_safe_h1_h2_N_tilde();
let (rpparam, rpwitness) = generate_safe_h1_h2_N_tilde();

Self {
u_i: u,
y_i: y,
dk,
ek,
party_index: index,
N_tilde,
h1,
h2,
xhi,
xhi_inv,
phi,
N_tilde: rpparam.N,
h1: rpparam.s,
h2: rpparam.t,
xhi: rpwitness.lambda,
xhi_inv: rpwitness.lambdaInv,
phi: rpwitness.phi,
}
}
pub fn create_from(u: Scalar<Secp256k1>, index: usize) -> Self {
let y = Point::generator() * &u;
let (ek, dk) = Paillier::keypair().keys();
let (N_tilde, h1, h2, xhi, xhi_inv, phi) =
generate_safe_h1_h2_N_tilde();
let (rpparam, rpwitness) = generate_normal_h1_h2_N_tilde();

Self {
u_i: u,
y_i: y,
dk,
ek,
party_index: index,
N_tilde,
h1,
h2,
xhi,
xhi_inv,
phi,
N_tilde: rpparam.N,
h1: rpparam.s,
h2: rpparam.t,
xhi: rpwitness.lambda,
xhi_inv: rpwitness.lambdaInv,
phi: rpwitness.phi,
}
}

Expand Down Expand Up @@ -486,21 +483,20 @@ impl PartyPrivate {
let y = Point::generator() * &u;
let (ek, dk) = Paillier::keypair().keys();

let (N_tilde, h1, h2, xhi, xhi_inv, phi) =
generate_safe_h1_h2_N_tilde();
let (rpparam, rpwitness) = generate_normal_h1_h2_N_tilde();

Keys {
u_i: u,
y_i: y,
dk,
ek,
party_index: index,
N_tilde,
h1,
h2,
xhi,
xhi_inv,
phi,
N_tilde: rpparam.N,
h1: rpparam.s,
h2: rpparam.t,
xhi: rpwitness.lambda,
xhi_inv: rpwitness.lambdaInv,
phi: rpwitness.phi,
}
}

Expand All @@ -514,21 +510,20 @@ impl PartyPrivate {
let y = Point::generator() * &u;
let (ek, dk) = Paillier::keypair_safe_primes().keys();

let (N_tilde, h1, h2, xhi, xhi_inv, phi) =
generate_safe_h1_h2_N_tilde();
let (rpparam, rpwitness) = generate_safe_h1_h2_N_tilde();

Keys {
u_i: u,
y_i: y,
dk,
ek,
party_index: index,
N_tilde,
h1,
h2,
xhi,
xhi_inv,
phi,
N_tilde: rpparam.N,
h1: rpparam.s,
h2: rpparam.t,
xhi: rpwitness.lambda,
xhi_inv: rpwitness.lambdaInv,
phi: rpwitness.phi,
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/presign/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,10 +736,10 @@ pub mod test {
let mut aux_ring_pedersen_s_values = HashMap::with_capacity(keys.len());
let mut aux_ring_pedersen_t_values = HashMap::with_capacity(keys.len());
for idx in 1..=p {
let (N_hat, S, T, _, _, _) = generate_safe_h1_h2_N_tilde();
aux_ring_pedersen_n_hat_values.insert(idx, N_hat);
aux_ring_pedersen_s_values.insert(idx, S);
aux_ring_pedersen_t_values.insert(idx, T);
let (rpparam, _) = generate_safe_h1_h2_N_tilde();
aux_ring_pedersen_n_hat_values.insert(idx, rpparam.N);
aux_ring_pedersen_s_values.insert(idx, rpparam.s);
aux_ring_pedersen_t_values.insert(idx, rpparam.t);
}

// Creates pre-signing inputs and auxiliary parameters for ZK proofs.
Expand Down
Loading

0 comments on commit 70309b2

Please sign in to comment.