core_utils/circuit/latest/
errors.rs1use crate::{
2 circuit::{AlgebraicType, Gate, GateIndex},
3 config::MpcConfig,
4};
5
6#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
7pub enum ConversionError {
8 #[error("Cannot transform AlgebraicType {0:?} into FieldType")]
9 IntoFieldTypeError(AlgebraicType),
10}
11
12#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
13pub enum SliceError {
14 #[error("Expected non-negative index, found {0}")]
15 NegativeIndex(i128),
16 #[error("Expected index in [0, {max}], found {found}")]
17 IndexOutOfBounds { found: i128, max: u32 },
18}
19
20#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
21#[error("Batch size must be a strictly positive integer, found {0}")]
22pub struct BatchSizeError(pub usize);
23
24#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
25#[error("Internal error: {0}")]
26pub struct InternalError(pub String);
27
28#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
29pub enum CircuitError<C: MpcConfig> {
30 #[error("Invalid gate {0:?}: {1}")]
31 InvalidGate(Gate<C>, String),
32 #[error("Gate index {0} out-of-bounds [0,{1})")]
33 GateIndexOutOfBounds(GateIndex, GateIndex),
34 #[error("Conversion error: {0}")]
35 ConversionError(#[from] ConversionError),
36 #[error("Invalid gate input count, expected {expected} inputs found {found}")]
37 InvalidGateInputCount { expected: usize, found: usize },
38 #[error("Invalid gate algebraic type, expected {expected:?} found {found:?}")]
39 InvalidGateAlgebraicType {
40 expected: AlgebraicType,
41 found: AlgebraicType,
42 },
43 #[error("Circuit is limited to a maximum of 2^32 gates")]
44 CircuitTooBig,
45 #[error("Slice error: {0}")]
46 SliceError(#[from] SliceError),
47 #[error("{0}")]
48 InternalError(#[from] InternalError),
49 #[error("{0}")]
50 BatchSizeError(#[from] BatchSizeError),
51 #[error("Circuit uses serialization format version {found} but this runtime reads {expected}")]
52 UnsupportedFormatVersion { expected: u8, found: u8 },
53 #[error("Circuit was built for curve {found:?} but this runtime uses {expected:?}")]
54 CurveMismatch { expected: String, found: String },
55 #[error("Circuit was built for MPC field {found:?} but this runtime uses {expected:?}")]
56 MpcFieldMismatch { expected: String, found: String },
57}