Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
[zk-token-sdk] Make inner scalar and ristretto point of `PedersenOpen…
Browse files Browse the repository at this point in the history
…ing` and `PedersenCommitment` private (#32187)

* make `PedersenOpening` inner scalar private

* make `PedersenCommitment` inner point private
  • Loading branch information
samkim-crypto authored Jun 20, 2023
1 parent 469661d commit 1616123
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
10 changes: 6 additions & 4 deletions zk-token-sdk/src/encryption/elgamal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl ElGamal {
fn decrypt(secret: &ElGamalSecretKey, ciphertext: &ElGamalCiphertext) -> DiscreteLog {
DiscreteLog::new(
*G,
&ciphertext.commitment.0 - &(&secret.0 * &ciphertext.handle.0),
ciphertext.commitment.get_point() - &(&secret.0 * &ciphertext.handle.0),
)
}

Expand Down Expand Up @@ -520,15 +520,17 @@ pub struct ElGamalCiphertext {
}
impl ElGamalCiphertext {
pub fn add_amount<T: Into<Scalar>>(&self, amount: T) -> Self {
let commitment_to_add = PedersenCommitment(amount.into() * &(*G));
let point = amount.into() * &(*G);
let commitment_to_add = PedersenCommitment::new(point);
ElGamalCiphertext {
commitment: &self.commitment + &commitment_to_add,
handle: self.handle,
}
}

pub fn subtract_amount<T: Into<Scalar>>(&self, amount: T) -> Self {
let commitment_to_subtract = PedersenCommitment(amount.into() * &(*G));
let point = amount.into() * &(*G);
let commitment_to_subtract = PedersenCommitment::new(point);
ElGamalCiphertext {
commitment: &self.commitment - &commitment_to_subtract,
handle: self.handle,
Expand Down Expand Up @@ -650,7 +652,7 @@ define_mul_variants!(
pub struct DecryptHandle(RistrettoPoint);
impl DecryptHandle {
pub fn new(public: &ElGamalPubkey, opening: &PedersenOpening) -> Self {
Self(&public.0 * &opening.0)
Self(&public.0 * opening.get_scalar())
}

pub fn get_point(&self) -> &RistrettoPoint {
Expand Down
12 changes: 10 additions & 2 deletions zk-token-sdk/src/encryption/pedersen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ impl Pedersen {
/// Instances of Pedersen openings are zeroized on drop.
#[derive(Clone, Debug, Default, Serialize, Deserialize, Zeroize)]
#[zeroize(drop)]
pub struct PedersenOpening(pub(crate) Scalar);
pub struct PedersenOpening(Scalar);
impl PedersenOpening {
pub fn new(scalar: Scalar) -> Self {
Self(scalar)
}

pub fn get_scalar(&self) -> &Scalar {
&self.0
}
Expand Down Expand Up @@ -163,8 +167,12 @@ define_mul_variants!(

/// Pedersen commitment type.
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct PedersenCommitment(pub(crate) RistrettoPoint);
pub struct PedersenCommitment(RistrettoPoint);
impl PedersenCommitment {
pub fn new(point: RistrettoPoint) -> Self {
Self(point)
}

pub fn get_point(&self) -> &RistrettoPoint {
&self.0
}
Expand Down

0 comments on commit 1616123

Please sign in to comment.