Skip to content

Commit

Permalink
refactor: rename to PiEnc to correspond with paper
Browse files Browse the repository at this point in the history
  • Loading branch information
ivokub committed Nov 30, 2023
1 parent dfe9d9f commit c9e1e64
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 44 deletions.
8 changes: 3 additions & 5 deletions src/presign/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ use crate::utilities::{
},
mul::{PaillierMulProof, PaillierMulStatement},
};
use tss_core::zkproof::enc::{
PaillierEncryptionInRangeProof, PaillierEncryptionInRangeStatement,
};
use tss_core::zkproof::enc::{PiEncProof, PiEncStatement};

use serde::{Deserialize, Serialize};
use zeroize::Zeroize;
Expand Down Expand Up @@ -125,8 +123,8 @@ pub struct PreSigningP2PMessage1<E: Curve> {
pub K_i: BigInt,
pub G_i: BigInt,
pub ek: EncryptionKey,
pub psi_0_j_i: PaillierEncryptionInRangeProof<E, Sha256>,
pub enc_j_statement: PaillierEncryptionInRangeStatement<E, Sha256>,
pub psi_0_j_i: PiEncProof<E, Sha256>,
pub enc_j_statement: PiEncStatement<E, Sha256>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
21 changes: 8 additions & 13 deletions src/presign/rounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ use curv::{
};
use tss_core::security_level::L_PRIME;
use tss_core::utilities::sample_relatively_prime_integer;
use tss_core::zkproof::enc::{
PaillierEncryptionInRangeProof, PaillierEncryptionInRangeStatement,
PaillierEncryptionInRangeWitness,
};
use tss_core::zkproof::enc::{PiEncProof, PiEncStatement, PiEncWitness};

use paillier::{
Add, Decrypt, EncryptWithChosenRandomness, EncryptionKey, Mul, Paillier,
Expand Down Expand Up @@ -108,12 +105,11 @@ impl Round0 {
&Randomness(rho_i.clone()),
)
.into();
let witness_psi_0_j_i =
PaillierEncryptionInRangeWitness::new(k_i.clone(), rho_i.clone());
let witness_psi_0_j_i = PiEncWitness::new(k_i.clone(), rho_i.clone());

for j in self.ssid.P.iter() {
if *j != self.ssid.X.i {
let statement_psi_0_j_i = PaillierEncryptionInRangeStatement {
let statement_psi_0_j_i = PiEncStatement {
N0: self.secrets.ek.n.clone(),
NN0: self.secrets.ek.nn.clone(),
K: K_i.clone(),
Expand All @@ -128,11 +124,10 @@ impl Round0 {
},
phantom: PhantomData,
};
let psi_0_j_i =
PaillierEncryptionInRangeProof::<Secp256k1, Sha256>::prove(
&witness_psi_0_j_i,
&statement_psi_0_j_i,
);
let psi_0_j_i = PiEncProof::<Secp256k1, Sha256>::prove(
&witness_psi_0_j_i,
&statement_psi_0_j_i,
);

let body = PreSigningP2PMessage1 {
ssid: self.ssid.clone(),
Expand Down Expand Up @@ -226,7 +221,7 @@ impl Round1 {
let psi_0_i_j = msg.psi_0_j_i;
let enc_i_statement = msg.enc_j_statement;
// Verify psi_0_i_j proof
if PaillierEncryptionInRangeProof::<Secp256k1, Sha256>::verify(
if PiEncProof::<Secp256k1, Sha256>::verify(
&psi_0_i_j,
&enc_i_statement,
)
Expand Down
48 changes: 22 additions & 26 deletions tss-core/src/zkproof/enc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use serde::{Deserialize, Serialize};
use std::marker::PhantomData;

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct PaillierEncryptionInRangeStatement<E: Curve, H: Digest + Clone> {
pub struct PiEncStatement<E: Curve, H: Digest + Clone> {
pub N0: BigInt,
pub NN0: BigInt,
pub K: BigInt,
Expand All @@ -47,7 +47,7 @@ pub struct PaillierEncryptionInRangeStatement<E: Curve, H: Digest + Clone> {
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct PaillierEncryptionInRangeWitness<E: Curve, H: Digest + Clone> {
pub struct PiEncWitness<E: Curve, H: Digest + Clone> {
k: BigInt,
rho: BigInt,
phantom: PhantomData<(E, H)>,
Expand All @@ -61,22 +61,22 @@ pub enum PiEncError {
Proof,
}

impl<E: Curve, H: Digest + Clone> PaillierEncryptionInRangeWitness<E, H> {
impl<E: Curve, H: Digest + Clone> PiEncWitness<E, H> {
pub fn new(k: BigInt, rho: BigInt) -> Self {
PaillierEncryptionInRangeWitness {
PiEncWitness {
k,
rho,
phantom: PhantomData,
}
}
}

impl<E: Curve, H: Digest + Clone> PaillierEncryptionInRangeStatement<E, H> {
impl<E: Curve, H: Digest + Clone> PiEncStatement<E, H> {
#[allow(clippy::too_many_arguments)]
pub fn generate(
rpparam: RingPedersenParams,
paillier_key: EncryptionKey,
) -> (Self, PaillierEncryptionInRangeWitness<E, H>) {
) -> (Self, PiEncWitness<E, H>) {
// sample the prover secret inputs
let rho: BigInt = sample_relatively_prime_integer(&paillier_key.n);
let k = BigInt::sample_below(Scalar::<E>::group_order());
Expand All @@ -100,7 +100,7 @@ impl<E: Curve, H: Digest + Clone> PaillierEncryptionInRangeStatement<E, H> {
RPParam: rpparam,
phantom: PhantomData,
},
PaillierEncryptionInRangeWitness {
PiEncWitness {
k,
rho,
phantom: PhantomData,
Expand All @@ -117,19 +117,18 @@ pub struct PaillierEncryptionInRangeCommitment {
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct PaillierEncryptionInRangeProof<E: Curve, H: Digest + Clone> {
pub struct PiEncProof<E: Curve, H: Digest + Clone> {
z_1: BigInt,
z_2: BigInt,
z_3: BigInt,
commitment: PaillierEncryptionInRangeCommitment,
phantom: PhantomData<(E, H)>,
}

impl<E: Curve, H: Digest + Clone> PaillierEncryptionInRangeProof<E, H> {
#[allow(dead_code)]
impl<E: Curve, H: Digest + Clone> PiEncProof<E, H> {
pub fn prove(
witness: &PaillierEncryptionInRangeWitness<E, H>,
statement: &PaillierEncryptionInRangeStatement<E, H>,
witness: &PiEncWitness<E, H>,
statement: &PiEncStatement<E, H>,
) -> Self {
// Step 1: Sample alpha between -2^{L+eps} and 2^{L+eps}
let alpha_upper = BigInt::pow(&BigInt::from(2), L_PLUS_EPSILON as u32);
Expand Down Expand Up @@ -231,10 +230,9 @@ impl<E: Curve, H: Digest + Clone> PaillierEncryptionInRangeProof<E, H> {
}
}

#[allow(dead_code)]
pub fn verify(
proof: &PaillierEncryptionInRangeProof<E, H>,
statement: &PaillierEncryptionInRangeStatement<E, H>,
proof: &PiEncProof<E, H>,
statement: &PiEncStatement<E, H>,
) -> Result<(), PiEncError> {
let e = H::new()
.chain_bigint(&proof.commitment.S)
Expand Down Expand Up @@ -322,16 +320,14 @@ mod tests {
)
.keys();

let (statement, witness) = PaillierEncryptionInRangeStatement::<
Secp256k1,
Sha256,
>::generate(auxRPParam, paillier_key);
let proof = PaillierEncryptionInRangeProof::<Secp256k1, Sha256>::prove(
&witness, &statement,
);
assert!(PaillierEncryptionInRangeProof::<Secp256k1, Sha256>::verify(
&proof, &statement,
)
.is_ok());
let (statement, witness) =
PiEncStatement::<Secp256k1, Sha256>::generate(
auxRPParam,
paillier_key,
);
let proof =
PiEncProof::<Secp256k1, Sha256>::prove(&witness, &statement);
assert!(PiEncProof::<Secp256k1, Sha256>::verify(&proof, &statement,)
.is_ok());
}
}

0 comments on commit c9e1e64

Please sign in to comment.