[zk-token-sdk] Restructure proof error types (#28407)
* add pubkey sigma proof * cargo fmt * add EncryptionError * add encryption errors
This commit is contained in:
parent
39fa297bf6
commit
00b1d0930f
|
@ -17,7 +17,7 @@
|
||||||
#![cfg(not(target_os = "solana"))]
|
#![cfg(not(target_os = "solana"))]
|
||||||
|
|
||||||
use {
|
use {
|
||||||
crate::errors::ProofError,
|
crate::encryption::errors::EncryptionError,
|
||||||
curve25519_dalek::{
|
curve25519_dalek::{
|
||||||
constants::RISTRETTO_BASEPOINT_POINT as G,
|
constants::RISTRETTO_BASEPOINT_POINT as G,
|
||||||
ristretto::RistrettoPoint,
|
ristretto::RistrettoPoint,
|
||||||
|
@ -100,10 +100,10 @@ impl DiscreteLog {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adjusts number of threads in a discrete log instance.
|
/// Adjusts number of threads in a discrete log instance.
|
||||||
pub fn num_threads(&mut self, num_threads: usize) -> Result<(), ProofError> {
|
pub fn num_threads(&mut self, num_threads: usize) -> Result<(), EncryptionError> {
|
||||||
// number of threads must be a positive power-of-two integer
|
// number of threads must be a positive power-of-two integer
|
||||||
if num_threads == 0 || (num_threads & (num_threads - 1)) != 0 || num_threads > 65536 {
|
if num_threads == 0 || (num_threads & (num_threads - 1)) != 0 || num_threads > 65536 {
|
||||||
return Err(ProofError::DiscreteLogThreads);
|
return Err(EncryptionError::DiscreteLogThreads);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.num_threads = num_threads;
|
self.num_threads = num_threads;
|
||||||
|
@ -117,9 +117,9 @@ impl DiscreteLog {
|
||||||
pub fn set_compression_batch_size(
|
pub fn set_compression_batch_size(
|
||||||
&mut self,
|
&mut self,
|
||||||
compression_batch_size: usize,
|
compression_batch_size: usize,
|
||||||
) -> Result<(), ProofError> {
|
) -> Result<(), EncryptionError> {
|
||||||
if compression_batch_size >= TWO16 as usize {
|
if compression_batch_size >= TWO16 as usize {
|
||||||
return Err(ProofError::DiscreteLogBatchSize);
|
return Err(EncryptionError::DiscreteLogBatchSize);
|
||||||
}
|
}
|
||||||
self.compression_batch_size = compression_batch_size;
|
self.compression_batch_size = compression_batch_size;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
//! Errors related to the twisted ElGamal encryption scheme.
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
|
#[derive(Error, Clone, Debug, Eq, PartialEq)]
|
||||||
|
pub enum EncryptionError {
|
||||||
|
#[error("discrete log number of threads not power-of-two")]
|
||||||
|
DiscreteLogThreads,
|
||||||
|
#[error("discrete log batch size too large")]
|
||||||
|
DiscreteLogBatchSize,
|
||||||
|
}
|
|
@ -13,4 +13,5 @@
|
||||||
pub mod auth_encryption;
|
pub mod auth_encryption;
|
||||||
pub mod discrete_log;
|
pub mod discrete_log;
|
||||||
pub mod elgamal;
|
pub mod elgamal;
|
||||||
|
pub mod errors;
|
||||||
pub mod pedersen;
|
pub mod pedersen;
|
||||||
|
|
|
@ -22,18 +22,12 @@ pub enum ProofError {
|
||||||
ZeroBalanceProof,
|
ZeroBalanceProof,
|
||||||
#[error("validity proof failed to verify")]
|
#[error("validity proof failed to verify")]
|
||||||
ValidityProof,
|
ValidityProof,
|
||||||
#[error(
|
|
||||||
"`zk_token_elgamal::pod::ElGamalCiphertext` contains invalid ElGamalCiphertext ciphertext"
|
|
||||||
)]
|
|
||||||
InconsistentCTData,
|
|
||||||
#[error("failed to decrypt ciphertext from transfer data")]
|
|
||||||
Decryption,
|
|
||||||
#[error("discrete log number of threads not power-of-two")]
|
|
||||||
DiscreteLogThreads,
|
|
||||||
#[error("discrete log batch size too large")]
|
|
||||||
DiscreteLogBatchSize,
|
|
||||||
#[error("public-key sigma proof failed to verify")]
|
#[error("public-key sigma proof failed to verify")]
|
||||||
PubkeySigmaProof,
|
PubkeySigmaProof,
|
||||||
|
#[error("failed to decrypt ciphertext")]
|
||||||
|
Decryption,
|
||||||
|
#[error("invalid ciphertext data")]
|
||||||
|
CiphertextDeserialization,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Error, Clone, Debug, Eq, PartialEq)]
|
#[derive(Error, Clone, Debug, Eq, PartialEq)]
|
||||||
|
|
|
@ -98,7 +98,7 @@ mod target_arch {
|
||||||
type Error = ProofError;
|
type Error = ProofError;
|
||||||
|
|
||||||
fn try_from(ct: pod::ElGamalCiphertext) -> Result<Self, Self::Error> {
|
fn try_from(ct: pod::ElGamalCiphertext) -> Result<Self, Self::Error> {
|
||||||
Self::from_bytes(&ct.0).ok_or(ProofError::InconsistentCTData)
|
Self::from_bytes(&ct.0).ok_or(ProofError::CiphertextDeserialization)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ mod target_arch {
|
||||||
type Error = ProofError;
|
type Error = ProofError;
|
||||||
|
|
||||||
fn try_from(pk: pod::ElGamalPubkey) -> Result<Self, Self::Error> {
|
fn try_from(pk: pod::ElGamalPubkey) -> Result<Self, Self::Error> {
|
||||||
Self::from_bytes(&pk.0).ok_or(ProofError::InconsistentCTData)
|
Self::from_bytes(&pk.0).ok_or(ProofError::CiphertextDeserialization)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ mod target_arch {
|
||||||
type Error = ProofError;
|
type Error = ProofError;
|
||||||
|
|
||||||
fn try_from(pod: pod::PedersenCommitment) -> Result<Self, Self::Error> {
|
fn try_from(pod: pod::PedersenCommitment) -> Result<Self, Self::Error> {
|
||||||
Self::from_bytes(&pod.0).ok_or(ProofError::InconsistentCTData)
|
Self::from_bytes(&pod.0).ok_or(ProofError::CiphertextDeserialization)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ mod target_arch {
|
||||||
type Error = ProofError;
|
type Error = ProofError;
|
||||||
|
|
||||||
fn try_from(pod: pod::DecryptHandle) -> Result<Self, Self::Error> {
|
fn try_from(pod: pod::DecryptHandle) -> Result<Self, Self::Error> {
|
||||||
Self::from_bytes(&pod.0).ok_or(ProofError::InconsistentCTData)
|
Self::from_bytes(&pod.0).ok_or(ProofError::CiphertextDeserialization)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ mod target_arch {
|
||||||
type Error = ProofError;
|
type Error = ProofError;
|
||||||
|
|
||||||
fn try_from(ct: pod::AeCiphertext) -> Result<Self, Self::Error> {
|
fn try_from(ct: pod::AeCiphertext) -> Result<Self, Self::Error> {
|
||||||
Self::from_bytes(&ct.0).ok_or(ProofError::InconsistentCTData)
|
Self::from_bytes(&ct.0).ok_or(ProofError::CiphertextDeserialization)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue