snarkvm_errors/gadgets/synthesis.rs
1// Copyright (C) 2019-2021 Aleo Systems Inc.
2// This file is part of the snarkVM library.
3
4// The snarkVM library is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// The snarkVM library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with the snarkVM library. If not, see <https://www.gnu.org/licenses/>.
16
17use std::{error::Error, fmt, io};
18
19pub type SynthesisResult<T> = Result<T, SynthesisError>;
20
21/// This is an error that could occur during circuit synthesis contexts,
22/// such as CRS generation, proving or verification.
23#[derive(Debug)]
24pub enum SynthesisError {
25 /// During synthesis, we lacked knowledge of a variable assignment.
26 AssignmentMissing,
27 /// During synthesis, we divided by zero.
28 DivisionByZero,
29 /// During synthesis, we constructed an unsatisfiable constraint system.
30 Unsatisfiable,
31 /// During synthesis, our polynomials ended up being too high of degree
32 PolynomialDegreeTooLarge,
33 /// During proof generation, we encountered an identity in the CRS
34 UnexpectedIdentity,
35 /// During proof generation, we encountered an I/O error with the CRS
36 IoError(io::Error),
37 /// During verification, our verifying key was malformed.
38 MalformedVerifyingKey,
39 /// During CRS generation, we observed an unconstrained auxiliary variable
40 UnconstrainedVariable,
41}
42
43impl From<io::Error> for SynthesisError {
44 fn from(e: io::Error) -> SynthesisError {
45 SynthesisError::IoError(e)
46 }
47}
48
49impl Error for SynthesisError {
50 fn description(&self) -> &str {
51 match *self {
52 SynthesisError::AssignmentMissing => "an assignment for a variable could not be computed",
53 SynthesisError::DivisionByZero => "division by zero",
54 SynthesisError::Unsatisfiable => "unsatisfiable constraint system",
55 SynthesisError::PolynomialDegreeTooLarge => "polynomial degree is too large",
56 SynthesisError::UnexpectedIdentity => "encountered an identity element in the CRS",
57 SynthesisError::IoError(_) => "encountered an I/O error",
58 SynthesisError::MalformedVerifyingKey => "malformed verifying key",
59 SynthesisError::UnconstrainedVariable => "auxiliary variable was unconstrained",
60 }
61 }
62}
63
64impl fmt::Display for SynthesisError {
65 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
66 if let SynthesisError::IoError(ref e) = *self {
67 write!(f, "I/O error: ")?;
68 e.fmt(f)
69 } else {
70 write!(f, "{}", self)
71 }
72 }
73}