-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use r0vm to run risc0 programs
- Loading branch information
Showing
6 changed files
with
50 additions
and
24 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,39 @@ | ||
use mugraph_core::{Error, Result}; | ||
use risc0_zkvm::{default_prover, ExecutorEnv, ProverOpts, Receipt}; | ||
use serde::{de::DeserializeOwned, Serialize}; | ||
|
||
include!(concat!(env!("OUT_DIR"), "/methods.rs")); | ||
|
||
pub struct Prover { | ||
stdout: Vec<u8>, | ||
opts: ProverOpts, | ||
} | ||
|
||
impl Prover { | ||
pub fn new() -> Self { | ||
Self { | ||
opts: ProverOpts::fast(), | ||
stdout: Vec::new(), | ||
} | ||
} | ||
|
||
pub fn prove<T: Serialize>(&mut self, input: T) -> Result<Receipt> { | ||
let env = ExecutorEnv::builder() | ||
.write(&input) | ||
.map_err(|_| Error::ExecutorWriteValue)? | ||
.stdout(&mut self.stdout) | ||
.build() | ||
.map_err(|_| Error::ExecutorInitialize)?; | ||
|
||
let prover = default_prover(); | ||
|
||
Ok(prover | ||
.prove_with_opts(env, FISSION_ELF, &self.opts) | ||
.map_err(|_| Error::ProofGenerate)? | ||
.receipt) | ||
} | ||
|
||
pub fn read<T: DeserializeOwned>(&self) -> Result<T> { | ||
risc0_zkvm::serde::from_slice(&self.stdout).map_err(|_| Error::StdoutDecode) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters