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

v1.16: [zk-token-sdk] Make inner scalar and ristretto point of PedersenOpening and PedersenCommitment private (backport of #32187) #32212

Merged
merged 1 commit into from
Jun 21, 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
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