Skip to main content

rings_snark/
error.rs

1//! Error module of snark crate
2
3/// A wrap `Result` contains custom errors.
4pub type Result<T> = std::result::Result<T, Error>;
5
6/// Errors collections in rings-snark
7#[derive(thiserror::Error, Debug)]
8pub enum Error {
9    /// Request error from reqwest
10    #[error("Invalid http request: {0}")]
11    HttpRequestError(#[from] reqwest::Error),
12    /// Error on load witness at path
13    #[error("Error on load witness calculator at path {0}")]
14    WASMFailedToLoad(String),
15    /// Error on loading witness from binary
16    #[error("Failed to load witnesses: {0}")]
17    WitnessFailedOnLoad(String),
18    /// Error on compiling witness
19    #[error("Error on witness compiling: {0}")]
20    WitnessWasmRuntimeError(Box<wasmer::RuntimeError>),
21    /// Error on create wasm instance
22    #[error("Error on create wasm instance: {0}")]
23    WitnessWasmInstanceError(Box<wasmer::InstantiationError>),
24    /// Error on create wasm memory
25    #[error("Error on create wasm memory: {0}")]
26    WitnessWasmMemoryError(String),
27    /// Wasm runtime error
28    #[error("Error on wasm runtime: {0}")]
29    WitnessCompileError(Box<wasmer::CompileError>),
30    /// Required Wasm export is not available
31    #[error("Wasm export not found: {0}")]
32    WitnessMissingExport(String),
33    /// Wasm export returned a value that does not match the Circom ABI
34    #[error("Invalid wasm return from {function}: expected {expected}, got {actual}")]
35    WitnessInvalidReturn {
36        /// Wasm function name.
37        function: String,
38        /// Expected return shape.
39        expected: &'static str,
40        /// Actual return shape.
41        actual: String,
42    },
43    /// Unsupported Circom compiler ABI version
44    #[error("Unsupported Circom version: {0}")]
45    WitnessUnsupportedCircomVersion(u32),
46    /// Invalid number of 32-bit words for a 256-bit integer
47    #[error("Invalid U256 word length: expected {expected}, got {actual}")]
48    WitnessInvalidU256WordLength {
49        /// Expected number of 32-bit words.
50        expected: usize,
51        /// Actual number of 32-bit words.
52        actual: usize,
53    },
54    /// Failed on load wasm module
55    #[error("Error on load wasm module: {0}")]
56    WitnessIoCompileError(Box<wasmer::IoCompileError>),
57    /// Error on load r1cs
58    #[error("Error on load r1cs: {0}")]
59    LoadR1CS(String),
60    /// Invalid data when reading header
61    #[error("Invalid data: {0}")]
62    InvalidDataWhenReadingR1CS(String),
63    /// Io Error
64    #[error("IO error: {0}")]
65    IOError(#[from] std::io::Error),
66    /// Error on call nova snark
67    #[error("Error on nova snark: {0}")]
68    NovaError(#[from] nova_snark::errors::NovaError),
69}
70
71impl From<wasmer::RuntimeError> for Error {
72    fn from(e: wasmer::RuntimeError) -> Self {
73        Self::WitnessWasmRuntimeError(Box::new(e))
74    }
75}
76
77impl From<wasmer::InstantiationError> for Error {
78    fn from(e: wasmer::InstantiationError) -> Self {
79        Self::WitnessWasmInstanceError(Box::new(e))
80    }
81}
82
83impl From<wasmer::CompileError> for Error {
84    fn from(e: wasmer::CompileError) -> Self {
85        Self::WitnessCompileError(Box::new(e))
86    }
87}
88
89impl From<wasmer::IoCompileError> for Error {
90    fn from(e: wasmer::IoCompileError) -> Self {
91        Self::WitnessIoCompileError(Box::new(e))
92    }
93}