nexus_sdk/legacy/jolt/
mod.rsuse crate::legacy::compile;
use crate::traits::*;
use std::fs;
use thiserror::Error;
use nexus_core_legacy::nvm::memory::MerkleTrie;
use nexus_core_legacy::prover::jolt::types::{JoltCommitments, JoltPreprocessing, JoltProof};
use nexus_core_legacy::prover::jolt::{
parse_elf, preprocess, prove, trace, verify, Error as ProofError, VM as JoltVM,
};
use crate::error::{BuildError, ConfigurationError, IOError};
use std::marker::PhantomData;
#[derive(Debug, Error)]
pub enum Error {
#[error(transparent)]
ProofError(#[from] ProofError),
#[error(transparent)]
BuildError(#[from] BuildError),
#[error(transparent)]
HostIOError(#[from] std::io::Error),
#[error(transparent)]
GuestIOError(#[from] IOError),
#[error(transparent)]
ConfigurationError(#[from] ConfigurationError),
}
pub struct Jolt<C: Compute = Local> {
vm: JoltVM<MerkleTrie>,
pre: Option<JoltPreprocessing>,
_compute: PhantomData<C>,
}
pub struct Proof {
proof: (JoltProof, JoltCommitments),
pre: JoltPreprocessing,
}
impl Jolt<Local> {
pub fn compile(opts: &compile::CompileOpts) -> Result<Self, Error> {
let mut iopts = opts.to_owned();
let elf_path = iopts.build(&compile::ForProver::Jolt)?;
Ok(Jolt::<Local> {
vm: parse_elf::<MerkleTrie>(fs::read(elf_path)?.as_slice())?,
pre: None,
_compute: PhantomData,
})
}
pub fn prove(mut self) -> Result<Proof, Error> {
let pre = preprocess(&self.vm);
self.pre = Some(pre.clone()); let tr = trace(self.vm)?;
let proof = prove(tr, &pre)?;
Ok(Proof { proof, pre })
}
}
impl<'a> Setup<'a> for Proof {
type Reference = ();
type Parameters = ();
type Preprocessing = JoltPreprocessing;
type Error = Error;
fn setup_reference<'b: 'a>(
&mut self,
_reference: &'b Self::Reference,
) -> Result<(), Self::Error> {
Err(Error::from(ConfigurationError::NotApplicableOperation))
}
fn setup_parameters<'b: 'a>(
&mut self,
_parameters: &'b Self::Parameters,
) -> Result<(), Self::Error> {
Err(Error::from(ConfigurationError::NotApplicableOperation))
}
fn detach(&mut self) {}
fn reference(&self) -> Result<&'a Self::Reference, Self::Error> {
Ok(&())
}
fn parameters(&self) -> Result<&'a Self::Parameters, Self::Error> {
Ok(&())
}
fn preprocessing(&self) -> Result<Self::Preprocessing, Self::Error> {
Ok(self.pre.clone())
}
}
impl Proof {
pub fn verify(self) -> Result<(), Error> {
Ok(verify(self.pre, self.proof.0, self.proof.1)?)
}
}