snarkvm_r1cs/errors.rs
1// Copyright (C) 2019-2023 Aleo Systems Inc.
2// This file is part of the snarkVM library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7// http://www.apache.org/licenses/LICENSE-2.0
8
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15pub type SynthesisResult<T> = Result<T, SynthesisError>;
16
17/// This is an error that could occur during circuit synthesis contexts,
18/// such as CRS generation, proving or verification.
19#[derive(Debug, Error)]
20pub enum SynthesisError {
21 #[error("{}", _0)]
22 AnyhowError(#[from] anyhow::Error),
23 /// During synthesis, we lacked knowledge of a variable assignment.
24 #[error("An assignment for a variable could not be computed")]
25 AssignmentMissing,
26 /// Handles a failed conversion of objects into constraint field elements.
27 #[error("Failed to convert object into constraint field elements")]
28 ConstraintFieldError(#[from] snarkvm_fields::ConstraintFieldError),
29 /// During synthesis, we divided by zero.
30 #[error("Division by zero during synthesis")]
31 DivisionByZero,
32 /// During synthesis, we constructed an unsatisfiable constraint system.
33 #[error("Unsatisfiable constraint system")]
34 Unsatisfiable,
35 /// During synthesis, our polynomials ended up being too high of degree
36 #[error("Polynomial degree is too large")]
37 PolynomialDegreeTooLarge,
38 /// During proof generation, we encountered an identity in the CRS
39 #[error("Encountered an identity element in the CRS")]
40 UnexpectedIdentity,
41 /// During proof generation, we encountered an I/O error with the CRS
42 #[error("Encountered an I/O error")]
43 IoError(std::io::Error),
44 /// During verification, our verifying key was malformed.
45 #[error("Malformed verifying key, public input count was {} but expected {}", _0, _1)]
46 MalformedVerifyingKey(usize, usize),
47 /// During CRS generation, we observed an unconstrained auxiliary variable
48 #[error("Auxiliary variable was unconstrained")]
49 UnconstrainedVariable,
50}
51
52impl From<std::io::Error> for SynthesisError {
53 fn from(e: std::io::Error) -> SynthesisError {
54 SynthesisError::IoError(e)
55 }
56}