feat: add errors for range proof module
This commit is contained in:
parent
e1d3883893
commit
a211fe1cf4
|
@ -5,14 +5,6 @@ use thiserror::Error;
|
|||
pub enum ProofError {
|
||||
#[error("proof failed to verify")]
|
||||
VerificationError,
|
||||
#[error("malformed proof")]
|
||||
FormatError,
|
||||
#[error("number of blinding factors do not match the number of values")]
|
||||
WrongNumBlindingFactors,
|
||||
#[error("attempted to create a proof with bitsize other than \\(8\\), \\(16\\), \\(32\\), or \\(64\\)")]
|
||||
InvalidBitsize,
|
||||
#[error("insufficient generators for the proof")]
|
||||
InvalidGeneratorsLength,
|
||||
#[error(
|
||||
"`zk_token_elgamal::pod::ElGamalCiphertext` contains invalid ElGamalCiphertext ciphertext"
|
||||
)]
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
//! Errors related to proving and verifying proofs.
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Clone, Debug, Eq, PartialEq)]
|
||||
pub enum ProofError {
|
||||
#[error("the required algebraic relation does not hold")]
|
||||
AlgebraicRelationError,
|
||||
#[error("malformed proof")]
|
||||
FormatError,
|
||||
#[error("attempted to create a proof with a non-power-of-two bitsize")]
|
||||
InvalidBitsize,
|
||||
#[error("insufficient generators for the proof")]
|
||||
InvalidGeneratorsLength,
|
||||
#[error("number of blinding factors do not match the number of values")]
|
||||
WrongNumBlindingFactors,
|
||||
}
|
|
@ -24,6 +24,7 @@ use {
|
|||
pub mod generators;
|
||||
pub mod inner_product;
|
||||
pub mod util;
|
||||
pub mod errors;
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[derive(Clone)]
|
||||
|
@ -222,23 +223,6 @@ impl RangeProof {
|
|||
bit_lengths: Vec<usize>,
|
||||
transcript: &mut Transcript,
|
||||
) -> Result<(), ProofError> {
|
||||
if self
|
||||
.verify_challenges(comms, bit_lengths, transcript)
|
||||
.is_ok()
|
||||
{
|
||||
Ok(())
|
||||
} else {
|
||||
Err(ProofError::VerificationError)
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::many_single_char_names)]
|
||||
pub fn verify_challenges(
|
||||
&self,
|
||||
comms: Vec<&CompressedRistretto>,
|
||||
bit_lengths: Vec<usize>,
|
||||
transcript: &mut Transcript,
|
||||
) -> Result<(Scalar, Scalar), ProofError> {
|
||||
let G = PedersenBase::default().G;
|
||||
let H = PedersenBase::default().H;
|
||||
|
||||
|
@ -246,6 +230,10 @@ impl RangeProof {
|
|||
let nm: usize = bit_lengths.iter().sum();
|
||||
let bp_gens = BulletproofGens::new(nm);
|
||||
|
||||
if !nm.is_power_of_two() {
|
||||
return Err(ProofError::InvalidBitsize);
|
||||
}
|
||||
|
||||
if !(nm == 8 || nm == 16 || nm == 32 || nm == 64 || nm == 128) {
|
||||
return Err(ProofError::InvalidBitsize);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue