feat: add a separate TranscriptError

This commit is contained in:
Sam Kim 2022-01-04 07:31:24 -05:00 committed by Michael Vines
parent a211fe1cf4
commit 7439d2424b
4 changed files with 23 additions and 13 deletions

View File

@ -10,3 +10,9 @@ pub enum ProofError {
)]
InconsistentCTData,
}
#[derive(Error, Clone, Debug, Eq, PartialEq)]
pub enum TranscriptError {
#[error("point is the identity")]
ValidationError,
}

View File

@ -1,8 +1,9 @@
//! Errors related to proving and verifying proofs.
use thiserror::Error;
use crate::errors::TranscriptError;
#[derive(Error, Clone, Debug, Eq, PartialEq)]
pub enum ProofError {
pub enum RangeProofError {
#[error("the required algebraic relation does not hold")]
AlgebraicRelationError,
#[error("malformed proof")]
@ -11,6 +12,14 @@ pub enum ProofError {
InvalidBitsize,
#[error("insufficient generators for the proof")]
InvalidGeneratorsLength,
#[error("transcript failed to produce a challenge")]
TranscriptError,
#[error("number of blinding factors do not match the number of values")]
WrongNumBlindingFactors,
}
impl From<TranscriptError> for RangeProofError {
fn from(err: TranscriptError) -> Self {
Self::TranscriptError
}
}

View File

@ -8,8 +8,7 @@ use {
use {
crate::{
encryption::pedersen::PedersenBase,
errors::ProofError,
range_proof::{generators::BulletproofGens, inner_product::InnerProductProof},
range_proof::{errors::RangeProofError, generators::BulletproofGens, inner_product::InnerProductProof},
transcript::TranscriptProtocol,
},
core::iter,
@ -222,7 +221,7 @@ impl RangeProof {
comms: Vec<&CompressedRistretto>,
bit_lengths: Vec<usize>,
transcript: &mut Transcript,
) -> Result<(), ProofError> {
) -> Result<(), RangeProofError> {
let G = PedersenBase::default().G;
let H = PedersenBase::default().H;
@ -231,11 +230,7 @@ impl RangeProof {
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);
return Err(RangeProofError::InvalidBitsize);
}
transcript.validate_and_append_point(b"A", &self.A)?;

View File

@ -1,5 +1,5 @@
use {
crate::errors::ProofError,
crate::errors::TranscriptError,
curve25519_dalek::{ristretto::CompressedRistretto, scalar::Scalar, traits::IsIdentity},
merlin::Transcript,
};
@ -40,7 +40,7 @@ pub trait TranscriptProtocol {
&mut self,
label: &'static [u8],
point: &CompressedRistretto,
) -> Result<(), ProofError>;
) -> Result<(), TranscriptError>;
/// Compute a `label`ed challenge variable.
fn challenge_scalar(&mut self, label: &'static [u8]) -> Scalar;
@ -90,9 +90,9 @@ impl TranscriptProtocol for Transcript {
&mut self,
label: &'static [u8],
point: &CompressedRistretto,
) -> Result<(), ProofError> {
) -> Result<(), TranscriptError> {
if point.is_identity() {
Err(ProofError::VerificationError)
Err(TranscriptError::ValidationError)
} else {
self.append_message(label, point.as_bytes());
Ok(())