Skip to content

Commit

Permalink
[curve25519] Remove ElGamalError from curve25519 crate (anza-xyz#1777)
Browse files Browse the repository at this point in the history
* remove `ElGamalError` from curve25519 crate

* add `ElGamalError` to zk-token-sdk
  • Loading branch information
samkim-crypto committed Jul 31, 2024
1 parent 61abf78 commit 556ab6a
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 36 deletions.
18 changes: 0 additions & 18 deletions curves/curve25519/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,3 @@ pub enum Curve25519Error {
#[error("pod conversion failed")]
PodConversion,
}

#[derive(Error, Clone, Debug, Eq, PartialEq)]
pub enum ElGamalError {
#[error("key derivation method not supported")]
DerivationMethodNotSupported,
#[error("seed length too short for derivation")]
SeedLengthTooShort,
#[error("seed length too long for derivation")]
SeedLengthTooLong,
#[error("failed to deserialize ciphertext")]
CiphertextDeserialization,
#[error("failed to deserialize public key")]
PubkeyDeserialization,
#[error("failed to deserialize keypair")]
KeypairDeserialization,
#[error("failed to deserialize secret key")]
SecretKeyDeserialization,
}
8 changes: 2 additions & 6 deletions curves/curve25519/src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ pub struct PodScalar(pub [u8; 32]);

#[cfg(not(target_os = "solana"))]
mod target_arch {
use {
super::*,
crate::errors::{Curve25519Error, ElGamalError},
curve25519_dalek::scalar::Scalar,
};
use {super::*, crate::errors::Curve25519Error, curve25519_dalek::scalar::Scalar};

impl From<&Scalar> for PodScalar {
fn from(scalar: &Scalar) -> Self {
Expand All @@ -35,7 +31,7 @@ mod target_arch {
}

impl TryFrom<PodScalar> for Scalar {
type Error = ElGamalError;
type Error = Curve25519Error;

fn try_from(pod: PodScalar) -> Result<Self, Self::Error> {
Scalar::from_canonical_bytes(pod.0)
Expand Down
2 changes: 1 addition & 1 deletion zk-token-sdk/src/encryption/elgamal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use {
Pedersen, PedersenCommitment, PedersenOpening, G, H, PEDERSEN_COMMITMENT_LEN,
},
},
errors::ElGamalError,
RISTRETTO_POINT_LEN, SCALAR_LEN,
},
base64::{prelude::BASE64_STANDARD, Engine},
Expand All @@ -31,7 +32,6 @@ use {
traits::Identity,
},
serde::{Deserialize, Serialize},
solana_curve25519::errors::ElGamalError,
solana_sdk::{
derivation_path::DerivationPath,
signature::Signature,
Expand Down
19 changes: 18 additions & 1 deletion zk-token-sdk/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,27 @@
use crate::range_proof::errors::RangeProofGenerationError;
use {
crate::{range_proof::errors::RangeProofVerificationError, sigma_proofs::errors::*},
solana_curve25519::errors::ElGamalError,
thiserror::Error,
};

#[derive(Error, Clone, Debug, Eq, PartialEq)]
pub enum ElGamalError {
#[error("key derivation method not supported")]
DerivationMethodNotSupported,
#[error("seed length too short for derivation")]
SeedLengthTooShort,
#[error("seed length too long for derivation")]
SeedLengthTooLong,
#[error("failed to deserialize ciphertext")]
CiphertextDeserialization,
#[error("failed to deserialize public key")]
PubkeyDeserialization,
#[error("failed to deserialize keypair")]
KeypairDeserialization,
#[error("failed to deserialize secret key")]
SecretKeyDeserialization,
}

#[derive(Error, Clone, Debug, Eq, PartialEq)]
pub enum AuthenticatedEncryptionError {
#[error("key derivation method not supported")]
Expand Down
6 changes: 4 additions & 2 deletions zk-token-sdk/src/zk_token_elgamal/pod/elgamal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
#[cfg(not(target_os = "solana"))]
use {
crate::encryption::elgamal::{self as decoded},
crate::{
encryption::elgamal::{self as decoded},
errors::ElGamalError,
},
curve25519_dalek::ristretto::CompressedRistretto,
solana_curve25519::errors::ElGamalError,
};
use {
crate::{
Expand Down
12 changes: 7 additions & 5 deletions zk-token-sdk/src/zk_token_elgamal/pod/grouped_elgamal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
#[cfg(not(target_os = "solana"))]
use crate::encryption::grouped_elgamal::GroupedElGamalCiphertext;
use {
crate::zk_token_elgamal::pod::{
elgamal::{ElGamalCiphertext, DECRYPT_HANDLE_LEN, ELGAMAL_CIPHERTEXT_LEN},
pedersen::{PedersenCommitment, PEDERSEN_COMMITMENT_LEN},
Pod, Zeroable,
crate::{
errors::ElGamalError,
zk_token_elgamal::pod::{
elgamal::{ElGamalCiphertext, DECRYPT_HANDLE_LEN, ELGAMAL_CIPHERTEXT_LEN},
pedersen::{PedersenCommitment, PEDERSEN_COMMITMENT_LEN},
Pod, Zeroable,
},
},
solana_curve25519::errors::ElGamalError,
std::fmt,
};

Expand Down
2 changes: 1 addition & 1 deletion zk-token-sdk/src/zk_token_elgamal/pod/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::zk_token_elgamal::pod::{
Zeroable,
};
#[cfg(not(target_os = "solana"))]
use {crate::instruction::transfer as decoded, solana_curve25519::errors::ElGamalError};
use crate::{errors::ElGamalError, instruction::transfer as decoded};

#[derive(Clone, Copy, Pod, Zeroable)]
#[repr(C)]
Expand Down
4 changes: 2 additions & 2 deletions zk-token-sdk/src/zk_token_elgamal/pod/pedersen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#[cfg(not(target_os = "solana"))]
use {
crate::encryption::pedersen as decoded, curve25519_dalek::ristretto::CompressedRistretto,
solana_curve25519::errors::ElGamalError,
crate::{encryption::pedersen as decoded, errors::ElGamalError},
curve25519_dalek::ristretto::CompressedRistretto,
};
use {
crate::{
Expand Down

0 comments on commit 556ab6a

Please sign in to comment.