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 compilling: {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    /// Wasm runtime error
25    #[error("Error on wasm runtime: {0}")]
26    WitnessCompileError(Box<wasmer::CompileError>),
27    /// Failed on load wasm module
28    #[error("Error on load wasm module: {0}")]
29    WitnessIoCompileError(Box<wasmer::IoCompileError>),
30    /// Error on load r1cs
31    #[error("Error on load r1cs: {0}")]
32    LoadR1CS(String),
33    /// Invalid data when reading header
34    #[error("Invalid data: {0}")]
35    InvalidDataWhenReadingR1CS(String),
36    /// Io Error
37    #[error("IO error: {0}")]
38    IOError(#[from] std::io::Error),
39    /// Error on call nova snark
40    #[error("Error on nova snark: {0}")]
41    NovaError(#[from] nova_snark::errors::NovaError),
42}
43
44impl From<wasmer::RuntimeError> for Error {
45    fn from(e: wasmer::RuntimeError) -> Self {
46        Self::WitnessWasmRuntimeError(Box::new(e))
47    }
48}
49
50impl From<wasmer::InstantiationError> for Error {
51    fn from(e: wasmer::InstantiationError) -> Self {
52        Self::WitnessWasmInstanceError(Box::new(e))
53    }
54}
55
56impl From<wasmer::CompileError> for Error {
57    fn from(e: wasmer::CompileError) -> Self {
58        Self::WitnessCompileError(Box::new(e))
59    }
60}
61
62impl From<wasmer::IoCompileError> for Error {
63    fn from(e: wasmer::IoCompileError) -> Self {
64        Self::WitnessIoCompileError(Box::new(e))
65    }
66}