[zk-token-sdk] Restructure proof error types (#28407)

* add pubkey sigma proof

* cargo fmt

* add EncryptionError

* add encryption errors
This commit is contained in:
samkim-crypto 2022-10-16 07:06:57 +09:00 committed by GitHub
parent 39fa297bf6
commit 00b1d0930f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 20 deletions

View File

@ -17,7 +17,7 @@
#![cfg(not(target_os = "solana"))]
use {
crate::errors::ProofError,
crate::encryption::errors::EncryptionError,
curve25519_dalek::{
constants::RISTRETTO_BASEPOINT_POINT as G,
ristretto::RistrettoPoint,
@ -100,10 +100,10 @@ impl DiscreteLog {
}
/// 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
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;
@ -117,9 +117,9 @@ impl DiscreteLog {
pub fn set_compression_batch_size(
&mut self,
compression_batch_size: usize,
) -> Result<(), ProofError> {
) -> Result<(), EncryptionError> {
if compression_batch_size >= TWO16 as usize {
return Err(ProofError::DiscreteLogBatchSize);
return Err(EncryptionError::DiscreteLogBatchSize);
}
self.compression_batch_size = compression_batch_size;

View File

@ -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,
}

View File

@ -13,4 +13,5 @@
pub mod auth_encryption;
pub mod discrete_log;
pub mod elgamal;
pub mod errors;
pub mod pedersen;

View File

@ -22,18 +22,12 @@ pub enum ProofError {
ZeroBalanceProof,
#[error("validity proof failed to verify")]
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")]
PubkeySigmaProof,
#[error("failed to decrypt ciphertext")]
Decryption,
#[error("invalid ciphertext data")]
CiphertextDeserialization,
}
#[derive(Error, Clone, Debug, Eq, PartialEq)]

View File

@ -98,7 +98,7 @@ mod target_arch {
type Error = ProofError;
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;
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;
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;
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;
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)
}
}