Skip to content

Commit

Permalink
chore: use two fast proofs and a compressed proof into example
Browse files Browse the repository at this point in the history
  • Loading branch information
cfcosta committed Aug 4, 2024
1 parent 6990507 commit fb23939
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
10 changes: 3 additions & 7 deletions core/programs/guest/src/bin/apply.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
use minicbor::Decoder;
use mugraph_core::types::Operation;
#![no_std]

use mugraph_core_programs_guest::verify;
use risc0_zkvm::guest::env;

fn main() {
let mut buf = [0u8; size_of::<Operation>()];
env::read_slice(&mut buf);
let mut decoder = Decoder::new(&buf);
let op = decoder.decode().unwrap();

let op = env::read();
verify(&op).unwrap();
}
34 changes: 16 additions & 18 deletions examples/src/bin/send-reaction.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
use minicbor::{Encode, Encoder};
use mugraph_core::{
error::{Error, Result},
types::*,
};
use mugraph_core_programs::__build::APPLY_ELF;
use risc0_zkvm::{default_prover, ExecutorEnv};
use risc0_zkvm::{default_prover, ExecutorEnv, ProverOpts};
use tracing::*;

macro_rules! timed {
($name:literal, $($arg:tt)*) => {{
let s = tracing::span!(Level::INFO, concat!("mugraph::task[", $name, "]"));
let _e = s.enter();

tracing::debug!("Starting task");
tracing::info!("Starting task");

let now = std::time::Instant::now();
let result = { $($arg)* };
Expand Down Expand Up @@ -40,13 +39,10 @@ fn main() -> Result<()> {
output: sealed_note.clone(),
};

let mut buf = Vec::new();
let mut enc = Encoder::new(&mut buf);
enc.encode(&mint)?;

let env = timed!("create executor", {
ExecutorEnv::builder()
.write_slice(&buf)
.write(&mint)
.map_err(|e| Error::ZKVM(e.to_string()))?
.build()
.map_err(|e| Error::ZKVM(e.to_string()))?
});
Expand All @@ -55,10 +51,10 @@ fn main() -> Result<()> {
let prover = timed!("create prover", default_prover());

// Produce a receipt by proving the specified ELF binary.
let receipt = timed!(
let mint_receipt = timed!(
"prove mint",
prover
.prove(env, APPLY_ELF)
.prove_with_opts(env, APPLY_ELF, &ProverOpts::fast())
.map_err(|e| Error::ZKVM(e.to_string()))?
.receipt
);
Expand All @@ -73,27 +69,29 @@ fn main() -> Result<()> {
},
};

let mut buf = Vec::new();
let mut enc = Encoder::new(&mut buf);
enc.encode(&consume)?;

let env = timed!("create executor", {
ExecutorEnv::builder()
.add_assumption(receipt)
.write_slice(&buf)
.add_assumption(mint_receipt)
.write(&consume)
.map_err(|e| Error::ZKVM(e.to_string()))?
.build()
.map_err(|e| Error::ZKVM(e.to_string()))?
});

// Produce a receipt by proving the specified ELF binary.
let receipt = timed!(
let consume_receipt = timed!(
"prove consume",
prover
.prove(env, APPLY_ELF)
.prove_with_opts(env, APPLY_ELF, &ProverOpts::fast())
.map_err(|e| Error::ZKVM(e.to_string()))?
.receipt
);

let _compressed = timed!(
"prove compress",
prover.compress(&ProverOpts::groth16(), &consume_receipt)
);

println!("Ok");

Ok(())
Expand Down

0 comments on commit fb23939

Please sign in to comment.