mirror of
https://github.com/eth-act/ere.git
synced 2026-02-19 11:54:42 -05:00
move error into its own module
This commit is contained in:
@@ -1,53 +1,10 @@
|
||||
use std::{
|
||||
fs,
|
||||
path::{Path, PathBuf},
|
||||
process::{Command, ExitStatus},
|
||||
};
|
||||
use std::{fs, path::Path, process::Command};
|
||||
|
||||
use tempfile::TempDir;
|
||||
use thiserror::Error;
|
||||
use toml::Value as TomlValue;
|
||||
use tracing::info;
|
||||
|
||||
/// Errors that can be encountered while compiling a SP1 program
|
||||
#[derive(Debug, Error)]
|
||||
pub enum CompileError {
|
||||
#[error("Program path does not exist or is not a directory: {0}")]
|
||||
InvalidProgramPath(PathBuf),
|
||||
#[error(
|
||||
"Cargo.toml not found in program directory: {program_dir}. Expected at: {manifest_path}"
|
||||
)]
|
||||
CargoTomlMissing {
|
||||
program_dir: PathBuf,
|
||||
manifest_path: PathBuf,
|
||||
},
|
||||
#[error("Could not find `[package].name` in guest Cargo.toml at {path}")]
|
||||
MissingPackageName { path: PathBuf },
|
||||
#[error("Compiled ELF not found at expected path: {0}")]
|
||||
ElfNotFound(PathBuf),
|
||||
#[error("`cargo prove build` failed with status: {status} for program at {path}")]
|
||||
CargoBuildFailed { status: ExitStatus, path: PathBuf },
|
||||
#[error("Failed to read file at {path}: {source}")]
|
||||
ReadFile {
|
||||
path: PathBuf,
|
||||
#[source]
|
||||
source: std::io::Error,
|
||||
},
|
||||
#[error("Failed to parse guest Cargo.toml at {path}: {source}")]
|
||||
ParseCargoToml {
|
||||
path: PathBuf,
|
||||
#[source]
|
||||
source: toml::de::Error,
|
||||
},
|
||||
#[error("Failed to execute `cargo prove build` in {cwd}: {source}")]
|
||||
CargoProveBuild {
|
||||
cwd: PathBuf,
|
||||
#[source]
|
||||
source: std::io::Error,
|
||||
},
|
||||
#[error("Failed to create temporary output directory: {0}")]
|
||||
TempDir(#[from] std::io::Error),
|
||||
}
|
||||
use crate::error::CompileError;
|
||||
|
||||
/// Compile the guest crate and return raw ELF bytes.
|
||||
pub fn compile_sp1_program(program_crate_path: &Path) -> Result<Vec<u8>, CompileError> {
|
||||
|
||||
82
crates/ere-sp1/src/error.rs
Normal file
82
crates/ere-sp1/src/error.rs
Normal file
@@ -0,0 +1,82 @@
|
||||
use std::{path::PathBuf, process::ExitStatus};
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum SP1Error {
|
||||
#[error(transparent)]
|
||||
CompileError(#[from] CompileError),
|
||||
|
||||
#[error(transparent)]
|
||||
Execute(#[from] ExecuteError),
|
||||
|
||||
#[error(transparent)]
|
||||
Prove(#[from] ProveError),
|
||||
|
||||
#[error(transparent)]
|
||||
Verify(#[from] VerifyError),
|
||||
}
|
||||
|
||||
/// Errors that can be encountered while compiling a SP1 program
|
||||
#[derive(Debug, Error)]
|
||||
pub enum CompileError {
|
||||
#[error("Program path does not exist or is not a directory: {0}")]
|
||||
InvalidProgramPath(PathBuf),
|
||||
#[error(
|
||||
"Cargo.toml not found in program directory: {program_dir}. Expected at: {manifest_path}"
|
||||
)]
|
||||
CargoTomlMissing {
|
||||
program_dir: PathBuf,
|
||||
manifest_path: PathBuf,
|
||||
},
|
||||
#[error("Could not find `[package].name` in guest Cargo.toml at {path}")]
|
||||
MissingPackageName { path: PathBuf },
|
||||
#[error("Compiled ELF not found at expected path: {0}")]
|
||||
ElfNotFound(PathBuf),
|
||||
#[error("`cargo prove build` failed with status: {status} for program at {path}")]
|
||||
CargoBuildFailed { status: ExitStatus, path: PathBuf },
|
||||
#[error("Failed to read file at {path}: {source}")]
|
||||
ReadFile {
|
||||
path: PathBuf,
|
||||
#[source]
|
||||
source: std::io::Error,
|
||||
},
|
||||
#[error("Failed to parse guest Cargo.toml at {path}: {source}")]
|
||||
ParseCargoToml {
|
||||
path: PathBuf,
|
||||
#[source]
|
||||
source: toml::de::Error,
|
||||
},
|
||||
#[error("Failed to execute `cargo prove build` in {cwd}: {source}")]
|
||||
CargoProveBuild {
|
||||
cwd: PathBuf,
|
||||
#[source]
|
||||
source: std::io::Error,
|
||||
},
|
||||
#[error("Failed to create temporary output directory: {0}")]
|
||||
TempDir(#[from] std::io::Error),
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ExecuteError {
|
||||
#[error("SP1 execution failed: {0}")]
|
||||
Client(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ProveError {
|
||||
#[error("SP1 SDK proving failed: {0}")]
|
||||
Client(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),
|
||||
|
||||
#[error("Serialising proof with `bincode` failed: {0}")]
|
||||
Bincode(#[from] bincode::Error),
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum VerifyError {
|
||||
#[error("Deserialising proof failed: {0}")]
|
||||
Bincode(#[from] bincode::Error),
|
||||
|
||||
#[error("SP1 SDK verification failed: {0}")]
|
||||
Client(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),
|
||||
}
|
||||
@@ -2,56 +2,19 @@
|
||||
|
||||
use compile::compile_sp1_program;
|
||||
use sp1_sdk::{Prover, ProverClient, SP1ProofWithPublicValues, SP1Stdin};
|
||||
use thiserror::Error;
|
||||
use tracing::info;
|
||||
use zkvm_interface::{Compiler, ProgramExecutionReport, ProgramProvingReport, zkVM};
|
||||
|
||||
mod compile;
|
||||
|
||||
mod error;
|
||||
use error::{ExecuteError, ProveError, SP1Error, VerifyError};
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct RV32_IM_SUCCINCT_ZKVM_ELF;
|
||||
|
||||
pub struct EreSP1;
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum SP1Error {
|
||||
#[error(transparent)]
|
||||
CompileError(#[from] compile::CompileError),
|
||||
|
||||
#[error(transparent)]
|
||||
Execute(#[from] ExecuteError),
|
||||
|
||||
#[error(transparent)]
|
||||
Prove(#[from] ProveError),
|
||||
|
||||
#[error(transparent)]
|
||||
Verify(#[from] VerifyError),
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ExecuteError {
|
||||
#[error("SP1 execution failed: {0}")]
|
||||
Client(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ProveError {
|
||||
#[error("SP1 SDK proving failed: {0}")]
|
||||
Client(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),
|
||||
|
||||
#[error("Serialising proof with `bincode` failed: {0}")]
|
||||
Bincode(#[from] bincode::Error),
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum VerifyError {
|
||||
#[error("Deserialising proof failed: {0}")]
|
||||
Bincode(#[from] bincode::Error),
|
||||
|
||||
#[error("SP1 SDK verification failed: {0}")]
|
||||
Client(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),
|
||||
}
|
||||
|
||||
impl Compiler for RV32_IM_SUCCINCT_ZKVM_ELF {
|
||||
type Error = SP1Error;
|
||||
|
||||
@@ -112,7 +75,7 @@ impl zkVM<RV32_IM_SUCCINCT_ZKVM_ELF> for EreSP1 {
|
||||
let proving_time = start.elapsed();
|
||||
|
||||
let bytes = bincode::serialize(&proof_with_inputs)
|
||||
.map_err(|err| SP1Error::Verify(VerifyError::Bincode(err)))?;
|
||||
.map_err(|err| SP1Error::Prove(ProveError::Bincode(err)))?;
|
||||
|
||||
Ok((bytes, ProgramProvingReport::new(proving_time)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user