From 2b6fec1dac7a7a5229ab0f19e5d9901c311d012e Mon Sep 17 00:00:00 2001 From: Nikolai Golub Date: Thu, 10 Aug 2023 15:39:31 +0200 Subject: [PATCH] Add Docs for Risc0 adapter --- adapters/risc0/src/guest.rs | 1 + adapters/risc0/src/host.rs | 10 ++++++++-- adapters/risc0/src/lib.rs | 7 +++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/adapters/risc0/src/guest.rs b/adapters/risc0/src/guest.rs index f664e0ff2..3b4911a74 100644 --- a/adapters/risc0/src/guest.rs +++ b/adapters/risc0/src/guest.rs @@ -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")] diff --git a/adapters/risc0/src/host.rs b/adapters/risc0/src/host.rs index e7ca82a93..510939e74 100644 --- a/adapters/risc0/src/host.rs +++ b/adapters/risc0/src/host.rs @@ -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>, 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()), @@ -57,6 +59,7 @@ impl<'prover> Zkvm for Risc0Host<'prover> { } } +/// Making verification of Risc0 proofs pub struct Risc0Verifier; impl Zkvm for Risc0Verifier { @@ -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>, + /// Reference to the journal pub journal: &'a [u8], } diff --git a/adapters/risc0/src/lib.rs b/adapters/risc0/src/lib.rs index ee3d48bdc..8271304bd 100644 --- a/adapters/risc0/src/lib.rs +++ b/adapters/risc0/src/lib.rs @@ -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 for Risc0MethodId {