use crate::{
circuit::{AlgebraicType, Gate, GateIndex},
config::MpcConfig,
};
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum ConversionError {
#[error("Cannot transform AlgebraicType {0:?} into FieldType")]
IntoFieldTypeError(AlgebraicType),
}
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum SliceError {
#[error("Expected non-negative index, found {0}")]
NegativeIndex(i128),
#[error("Expected index in [0, {max}], found {found}")]
IndexOutOfBounds { found: i128, max: u32 },
}
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[error("Batch size must be a strictly positive integer, found {0}")]
pub struct BatchSizeError(pub usize);
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[error("Internal error: {0}")]
pub struct InternalError(pub String);
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum CircuitError<C: MpcConfig> {
#[error("Invalid gate {0:?}: {1}")]
InvalidGate(Gate<C>, String),
#[error("Gate index {0} out-of-bounds [0,{1})")]
GateIndexOutOfBounds(GateIndex, GateIndex),
#[error("Conversion error: {0}")]
ConversionError(#[from] ConversionError),
#[error("Invalid gate input count, expected {expected} inputs found {found}")]
InvalidGateInputCount { expected: usize, found: usize },
#[error("Invalid gate algebraic type, expected {expected:?} found {found:?}")]
InvalidGateAlgebraicType {
expected: AlgebraicType,
found: AlgebraicType,
},
#[error("Circuit is limited to a maximum of 2^32 gates")]
CircuitTooBig,
#[error("Slice error: {0}")]
SliceError(#[from] SliceError),
#[error("{0}")]
InternalError(#[from] InternalError),
#[error("{0}")]
BatchSizeError(#[from] BatchSizeError),
#[error("Circuit uses serialization format version {found} but this runtime reads {expected}")]
UnsupportedFormatVersion { expected: u8, found: u8 },
#[error("Circuit was built for curve {found:?} but this runtime uses {expected:?}")]
CurveMismatch { expected: String, found: String },
#[error("Circuit was built for MPC field {found:?} but this runtime uses {expected:?}")]
MpcFieldMismatch { expected: String, found: String },
}