Skip to content

Commit

Permalink
Add Docs for Risc0 adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
citizen-stig committed Aug 10, 2023
1 parent 22c7d94 commit 2b6fec1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions adapters/risc0/src/guest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use sov_rollup_interface::zk::{Zkvm, ZkvmGuest};

use crate::Risc0MethodId;

/// Control struct for Risc0 guest
pub struct Risc0Guest;

#[cfg(target_os = "zkvm")]
Expand Down
10 changes: 8 additions & 2 deletions adapters/risc0/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ use sov_rollup_interface::zk::{Zkvm, ZkvmHost};

use crate::Risc0MethodId;

/// Allows to run prover code and send data to ZkVM
pub struct Risc0Host<'a> {
env: RefCell<ExecutorEnvBuilder<'a>>,
elf: &'a [u8],
}

impl<'a> Risc0Host<'a> {
/// Create a new host fo a given reference to an ELF file
pub fn new(elf: &'a [u8]) -> Self {
Self {
env: RefCell::new(ExecutorEnvBuilder::default()),
Expand Down Expand Up @@ -57,6 +59,7 @@ impl<'prover> Zkvm for Risc0Host<'prover> {
}
}

/// Making verification of Risc0 proofs
pub struct Risc0Verifier;

impl Zkvm for Risc0Verifier {
Expand Down Expand Up @@ -90,10 +93,13 @@ fn verify_from_slice<'a>(
Ok(journal)
}

/// A convenience type which contains the same data a Risc0 [`SessionReceipt`] but borrows the journal
/// data. This allows to avoid one unnecessary copy during proof verification.
/// A convenience type which contains the same data a Risc0 [`SessionReceipt`]
/// but borrows the journal data.
/// This allows avoiding one unnecessary copy during proof verification.
#[derive(serde::Serialize, serde::Deserialize)]
pub struct Risc0Proof<'a> {
/// References to the segment receipts
pub segment_receipts: Vec<Box<SegmentReceipt>>,
/// Reference to the journal
pub journal: &'a [u8],
}
7 changes: 7 additions & 0 deletions adapters/risc0/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
#![deny(missing_docs)]
#![doc = include_str!("../README.md")]

use risc0_zkvm::sha::Digest;
use serde::{Deserialize, Serialize};
use sov_rollup_interface::zk::Matches;

/// Guest or code that runs inside ZkVM
pub mod guest;

#[cfg(feature = "native")]
/// Host or code that runs outside ZkVM and interacts with the guest
pub mod host;

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
/// Risc0 implementation of a commitment to the zkVM program which is being proven
pub struct Risc0MethodId([u32; 8]);

impl Matches<Self> for Risc0MethodId {
Expand Down

0 comments on commit 2b6fec1

Please sign in to comment.