extern crate alloc;
use alloc::vec::Vec;
#[cfg(feature = "std")]
use thiserror::Error;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "std", derive(Error))]
pub enum ProofError {
#[cfg_attr(feature = "std", error("Proof verification failed."))]
VerificationError,
#[cfg_attr(feature = "std", error("Proof data could not be parsed."))]
FormatError,
#[cfg_attr(feature = "std", error("Wrong number of blinding factors supplied."))]
WrongNumBlindingFactors,
#[cfg_attr(feature = "std", error("Invalid bitsize, must have n = 8,16,32,64."))]
InvalidBitsize,
#[cfg_attr(
feature = "std",
error("Invalid aggregation size, m must be a power of 2.")
)]
InvalidAggregation,
#[cfg_attr(
feature = "std",
error("Invalid generators size, too few generators for proof")
)]
InvalidGeneratorsLength,
#[cfg_attr(feature = "std", error("Internal error during proof creation: {0}"))]
ProvingError(MPCError),
}
impl From<MPCError> for ProofError {
fn from(e: MPCError) -> ProofError {
match e {
MPCError::InvalidBitsize => ProofError::InvalidBitsize,
MPCError::InvalidAggregation => ProofError::InvalidAggregation,
MPCError::InvalidGeneratorsLength => ProofError::InvalidGeneratorsLength,
_ => ProofError::ProvingError(e),
}
}
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "std", derive(Error))]
pub enum MPCError {
#[cfg_attr(feature = "std", error("Dealer gave a malicious challenge value."))]
MaliciousDealer,
#[cfg_attr(feature = "std", error("Invalid bitsize, must have n = 8,16,32,64"))]
InvalidBitsize,
#[cfg_attr(
feature = "std",
error("Invalid aggregation size, m must be a power of 2")
)]
InvalidAggregation,
#[cfg_attr(
feature = "std",
error("Invalid generators size, too few generators for proof")
)]
InvalidGeneratorsLength,
#[cfg_attr(feature = "std", error("Wrong number of value commitments"))]
WrongNumBitCommitments,
#[cfg_attr(feature = "std", error("Wrong number of value commitments"))]
WrongNumPolyCommitments,
#[cfg_attr(feature = "std", error("Wrong number of proof shares"))]
WrongNumProofShares,
#[cfg_attr(
feature = "std",
error("Malformed proof shares from parties {bad_shares:?}")
)]
MalformedProofShares {
bad_shares: Vec<usize>,
},
}
#[cfg(feature = "yoloproofs")]
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "std", derive(Error))]
pub enum R1CSError {
#[cfg_attr(
feature = "std",
error("Invalid generators size, too few generators for proof")
)]
InvalidGeneratorsLength,
#[cfg_attr(feature = "std", error("Proof data could not be parsed."))]
FormatError,
#[cfg_attr(feature = "std", error("R1CSProof did not verify correctly."))]
VerificationError,
#[cfg_attr(feature = "std", error("Variable does not have a value assignment."))]
MissingAssignment,
#[cfg_attr(feature = "std", error("Gadget error: {description:?}"))]
GadgetError {
description: String,
},
}
#[cfg(feature = "yoloproofs")]
impl From<ProofError> for R1CSError {
fn from(e: ProofError) -> R1CSError {
match e {
ProofError::InvalidGeneratorsLength => R1CSError::InvalidGeneratorsLength,
ProofError::FormatError => R1CSError::FormatError,
ProofError::VerificationError => R1CSError::VerificationError,
_ => panic!("unexpected error type in conversion"),
}
}
}