Skip to content

Commit

Permalink
add sanity check for local assumptions uploaded to Bonsai (risc0#2258)
Browse files Browse the repository at this point in the history
Tested against this repro
https://github.com/austinabell/bs-repro/blob/main/host/src/main.rs

The pattern that is an issue is generating local receipts (which default
to composite) and uploading those to Bonsai.

Co-authored-by: Frank Laub <[email protected]>
  • Loading branch information
austinabell and flaub authored Aug 31, 2024
1 parent 7c9d82d commit 220c212
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions risc0/zkvm/src/host/client/prove/bonsai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ use bonsai_sdk::blocking::Client;

use super::Prover;
use crate::{
compute_image_id, is_dev_mode, sha::Digestible, ExecutorEnv, Groth16Receipt, InnerReceipt,
ProveInfo, ProverOpts, Receipt, ReceiptKind, VerifierContext,
compute_image_id, is_dev_mode, sha::Digestible, AssumptionReceipt, ExecutorEnv, Groth16Receipt,
InnerAssumptionReceipt, InnerReceipt, ProveInfo, ProverOpts, Receipt, ReceiptKind,
VerifierContext,
};

/// An implementation of a [Prover] that runs proof workloads via Bonsai.
Expand All @@ -40,6 +41,25 @@ impl BonsaiProver {
}
}

/// Serializes the assumption receipt to upload to Bonsai. Will error if an unsupported receipt type
/// is provided.
fn serialize_succinct_assumption_receipt(assumption: &AssumptionReceipt) -> Result<Vec<u8>> {
match assumption {
AssumptionReceipt::Proven(receipt) => {
if !matches!(receipt, InnerAssumptionReceipt::Succinct(_)) {
bail!(
"only succinct starks can be provided as assumptions for Bonsai. \
Use `ProverOpts::succinct()` when generating any assumptions locally."
);
};
Ok(bincode::serialize(receipt)?)
}
crate::AssumptionReceipt::Unresolved(_) => {
bail!("only proven assumptions can be uploaded to Bonsai.")
}
}
}

impl Prover for BonsaiProver {
fn get_name(&self) -> String {
self.name.clone()
Expand All @@ -65,12 +85,7 @@ impl Prover for BonsaiProver {
// upload receipts
let mut receipts_ids: Vec<String> = vec![];
for assumption in &env.assumptions.borrow().cached {
let serialized_receipt = match assumption {
crate::AssumptionReceipt::Proven(receipt) => bincode::serialize(receipt)?,
crate::AssumptionReceipt::Unresolved(_) => {
bail!("only proven assumptions can be uploaded to Bonsai.")
}
};
let serialized_receipt = serialize_succinct_assumption_receipt(assumption)?;
let receipt_id = client.upload_receipt(serialized_receipt)?;
receipts_ids.push(receipt_id);
}
Expand Down

0 comments on commit 220c212

Please sign in to comment.