Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[curve25519] Remove ElGamalError from curve25519 crate #1777

Merged
merged 2 commits into from
Jun 18, 2024
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
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,
}
10 changes: 3 additions & 7 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 @@ -33,10 +29,10 @@ 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).ok_or(ElGamalError::CiphertextDeserialization)
Scalar::from_canonical_bytes(pod.0).ok_or(Curve25519Error::PodConversion)
}
}
}
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