feat: add a separate TranscriptError
This commit is contained in:
parent
a211fe1cf4
commit
7439d2424b
|
@ -10,3 +10,9 @@ pub enum ProofError {
|
||||||
)]
|
)]
|
||||||
InconsistentCTData,
|
InconsistentCTData,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Error, Clone, Debug, Eq, PartialEq)]
|
||||||
|
pub enum TranscriptError {
|
||||||
|
#[error("point is the identity")]
|
||||||
|
ValidationError,
|
||||||
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
//! Errors related to proving and verifying proofs.
|
//! Errors related to proving and verifying proofs.
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
use crate::errors::TranscriptError;
|
||||||
|
|
||||||
#[derive(Error, Clone, Debug, Eq, PartialEq)]
|
#[derive(Error, Clone, Debug, Eq, PartialEq)]
|
||||||
pub enum ProofError {
|
pub enum RangeProofError {
|
||||||
#[error("the required algebraic relation does not hold")]
|
#[error("the required algebraic relation does not hold")]
|
||||||
AlgebraicRelationError,
|
AlgebraicRelationError,
|
||||||
#[error("malformed proof")]
|
#[error("malformed proof")]
|
||||||
|
@ -11,6 +12,14 @@ pub enum ProofError {
|
||||||
InvalidBitsize,
|
InvalidBitsize,
|
||||||
#[error("insufficient generators for the proof")]
|
#[error("insufficient generators for the proof")]
|
||||||
InvalidGeneratorsLength,
|
InvalidGeneratorsLength,
|
||||||
|
#[error("transcript failed to produce a challenge")]
|
||||||
|
TranscriptError,
|
||||||
#[error("number of blinding factors do not match the number of values")]
|
#[error("number of blinding factors do not match the number of values")]
|
||||||
WrongNumBlindingFactors,
|
WrongNumBlindingFactors,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<TranscriptError> for RangeProofError {
|
||||||
|
fn from(err: TranscriptError) -> Self {
|
||||||
|
Self::TranscriptError
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -8,8 +8,7 @@ use {
|
||||||
use {
|
use {
|
||||||
crate::{
|
crate::{
|
||||||
encryption::pedersen::PedersenBase,
|
encryption::pedersen::PedersenBase,
|
||||||
errors::ProofError,
|
range_proof::{errors::RangeProofError, generators::BulletproofGens, inner_product::InnerProductProof},
|
||||||
range_proof::{generators::BulletproofGens, inner_product::InnerProductProof},
|
|
||||||
transcript::TranscriptProtocol,
|
transcript::TranscriptProtocol,
|
||||||
},
|
},
|
||||||
core::iter,
|
core::iter,
|
||||||
|
@ -222,7 +221,7 @@ impl RangeProof {
|
||||||
comms: Vec<&CompressedRistretto>,
|
comms: Vec<&CompressedRistretto>,
|
||||||
bit_lengths: Vec<usize>,
|
bit_lengths: Vec<usize>,
|
||||||
transcript: &mut Transcript,
|
transcript: &mut Transcript,
|
||||||
) -> Result<(), ProofError> {
|
) -> Result<(), RangeProofError> {
|
||||||
let G = PedersenBase::default().G;
|
let G = PedersenBase::default().G;
|
||||||
let H = PedersenBase::default().H;
|
let H = PedersenBase::default().H;
|
||||||
|
|
||||||
|
@ -231,11 +230,7 @@ impl RangeProof {
|
||||||
let bp_gens = BulletproofGens::new(nm);
|
let bp_gens = BulletproofGens::new(nm);
|
||||||
|
|
||||||
if !nm.is_power_of_two() {
|
if !nm.is_power_of_two() {
|
||||||
return Err(ProofError::InvalidBitsize);
|
return Err(RangeProofError::InvalidBitsize);
|
||||||
}
|
|
||||||
|
|
||||||
if !(nm == 8 || nm == 16 || nm == 32 || nm == 64 || nm == 128) {
|
|
||||||
return Err(ProofError::InvalidBitsize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
transcript.validate_and_append_point(b"A", &self.A)?;
|
transcript.validate_and_append_point(b"A", &self.A)?;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use {
|
use {
|
||||||
crate::errors::ProofError,
|
crate::errors::TranscriptError,
|
||||||
curve25519_dalek::{ristretto::CompressedRistretto, scalar::Scalar, traits::IsIdentity},
|
curve25519_dalek::{ristretto::CompressedRistretto, scalar::Scalar, traits::IsIdentity},
|
||||||
merlin::Transcript,
|
merlin::Transcript,
|
||||||
};
|
};
|
||||||
|
@ -40,7 +40,7 @@ pub trait TranscriptProtocol {
|
||||||
&mut self,
|
&mut self,
|
||||||
label: &'static [u8],
|
label: &'static [u8],
|
||||||
point: &CompressedRistretto,
|
point: &CompressedRistretto,
|
||||||
) -> Result<(), ProofError>;
|
) -> Result<(), TranscriptError>;
|
||||||
|
|
||||||
/// Compute a `label`ed challenge variable.
|
/// Compute a `label`ed challenge variable.
|
||||||
fn challenge_scalar(&mut self, label: &'static [u8]) -> Scalar;
|
fn challenge_scalar(&mut self, label: &'static [u8]) -> Scalar;
|
||||||
|
@ -90,9 +90,9 @@ impl TranscriptProtocol for Transcript {
|
||||||
&mut self,
|
&mut self,
|
||||||
label: &'static [u8],
|
label: &'static [u8],
|
||||||
point: &CompressedRistretto,
|
point: &CompressedRistretto,
|
||||||
) -> Result<(), ProofError> {
|
) -> Result<(), TranscriptError> {
|
||||||
if point.is_identity() {
|
if point.is_identity() {
|
||||||
Err(ProofError::VerificationError)
|
Err(TranscriptError::ValidationError)
|
||||||
} else {
|
} else {
|
||||||
self.append_message(label, point.as_bytes());
|
self.append_message(label, point.as_bytes());
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in New Issue