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