Skip to content

Commit

Permalink
refactor(risc0,sp1): rename arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
petarvujovic98 committed Jul 18, 2024
1 parent c767327 commit a43bfbd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
10 changes: 5 additions & 5 deletions provers/risc0/driver/src/bonsai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub async fn maybe_prove<I: Serialize, O: Eq + Debug + Serialize + DeserializeOw
expected_output: &O,
assumptions: (Vec<Assumption>, Vec<String>),
proof_key: ProofKey,
write: &mut Option<&mut dyn IdWrite>,
id_store: &mut Option<&mut dyn IdWrite>,
) -> Option<(String, Receipt)> {
let (assumption_instances, assumption_uuids) = assumptions;

Expand Down Expand Up @@ -121,7 +121,7 @@ pub async fn maybe_prove<I: Serialize, O: Eq + Debug + Serialize + DeserializeOw
expected_output,
assumption_uuids.clone(),
proof_key,
write,
id_store,
)
.await
{
Expand Down Expand Up @@ -198,7 +198,7 @@ pub async fn prove_bonsai<O: Eq + Debug + DeserializeOwned>(
expected_output: &O,
assumption_uuids: Vec<String>,
proof_key: ProofKey,
write: &mut Option<&mut dyn IdWrite>,
id_store: &mut Option<&mut dyn IdWrite>,
) -> anyhow::Result<(String, Receipt)> {
info!("Proving on Bonsai");
// Compute the image_id, then upload the ELF with the image_id as its key.
Expand All @@ -218,8 +218,8 @@ pub async fn prove_bonsai<O: Eq + Debug + DeserializeOwned>(
assumption_uuids.clone(),
)?;

if let Some(write) = write {
write.store_id(proof_key, session.uuid.clone())?;
if let Some(id_store) = id_store {
id_store.store_id(proof_key, session.uuid.clone())?;
}

verify_bonsai_receipt(image_id, expected_output, session.uuid.clone(), 8).await
Expand Down
12 changes: 6 additions & 6 deletions provers/risc0/driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ impl Prover for Risc0Prover {
input: GuestInput,
output: &GuestOutput,
config: &ProverConfig,
write: Option<&mut dyn IdWrite>,
id_store: Option<&mut dyn IdWrite>,
) -> ProverResult<Proof> {
let mut write = write;
let mut id_store = id_store;
let config = Risc0Param::deserialize(config.get("risc0").unwrap()).unwrap();
let proof_key = (
input.chain_spec.chain_id,
Expand All @@ -76,7 +76,7 @@ impl Prover for Risc0Prover {
&output.hash,
Default::default(),
proof_key,
&mut write,
&mut id_store,
)
.await;

Expand Down Expand Up @@ -105,12 +105,12 @@ impl Prover for Risc0Prover {
Ok(Risc0Response { proof: journal }.into())
}

async fn cancel(key: ProofKey, store: Box<&mut dyn IdStore>) -> ProverResult<()> {
let uuid = store.read_id(key)?;
async fn cancel(key: ProofKey, id_store: Box<&mut dyn IdStore>) -> ProverResult<()> {
let uuid = id_store.read_id(key)?;
cancel_proof(uuid)
.await
.map_err(|e| ProverError::GuestError(e.to_string()))?;
store.remove_id(key)?;
id_store.remove_id(key)?;
Ok(())
}
}
Expand Down
12 changes: 6 additions & 6 deletions provers/sp1/driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Prover for Sp1Prover {
input: GuestInput,
output: &GuestOutput,
_config: &ProverConfig,
writer: Option<&mut dyn IdWrite>,
id_store: Option<&mut dyn IdWrite>,
) -> ProverResult<Proof> {
// Write the input.
let mut stdin = SP1Stdin::new();
Expand Down Expand Up @@ -68,8 +68,8 @@ impl Prover for Sp1Prover {
.map_err(|_| {
ProverError::GuestError("Sp1: creating proof failed".to_owned())
})?;
if let Some(writer) = writer {
writer.store_id(
if let Some(id_store) = id_store {
id_store.store_id(
(input.chain_spec.chain_id, output.hash, SP1_PROVER_CODE),
proof_id.clone(),
)?;
Expand Down Expand Up @@ -135,8 +135,8 @@ impl Prover for Sp1Prover {
.into())
}

async fn cancel(key: ProofKey, store: Box<&mut dyn IdStore>) -> ProverResult<()> {
let proof_id = store.read_id(key)?;
async fn cancel(key: ProofKey, id_store: Box<&mut dyn IdStore>) -> ProverResult<()> {
let proof_id = id_store.read_id(key)?;
let private_key = env::var("SP1_PRIVATE_KEY").map_err(|_| {
ProverError::GuestError("SP1_PRIVATE_KEY must be set for remote proving".to_owned())
})?;
Expand All @@ -145,7 +145,7 @@ impl Prover for Sp1Prover {
.unclaim_proof(proof_id, UnclaimReason::Abandoned, "".to_owned())
.await
.map_err(|_| ProverError::GuestError("Sp1: couldn't unclaim proof".to_owned()))?;
store.remove_id(key)?;
id_store.remove_id(key)?;
Ok(())
}
}
Expand Down

0 comments on commit a43bfbd

Please sign in to comment.