Skip to content

Commit

Permalink
refactor: risc0 proving return early for error response
Browse files Browse the repository at this point in the history
  • Loading branch information
keroro520 committed Nov 25, 2024
1 parent 64fd81f commit a52cb27
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions provers/risc0/driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl Prover for Risc0Prover {
debug!("elf code length: {}", RISC0_GUEST_ELF.len());
let encoded_input = to_vec(&input).expect("Could not serialize proving input!");

let result = maybe_prove::<GuestInput, B256>(
let (uuid, receipt) = maybe_prove::<GuestInput, B256>(
&config,
encoded_input,
RISC0_GUEST_ELF,
Expand All @@ -92,26 +92,22 @@ impl Prover for Risc0Prover {
)
.await?;

let proof_gen_result = {
if config.snark && config.bonsai {
let (stark_uuid, stark_receipt) = result.clone();
bonsai::bonsai_stark_to_snark(stark_uuid, stark_receipt, output.hash)
.await
.map(|r0_response| r0_response.into())
.map_err(|e| ProverError::GuestError(e.to_string()))
} else {
if !config.snark {
warn!("proof is not in snark mode, please check.");
}
let (uuid, stark_receipt) = result.clone();
Ok(Risc0Response {
proof: stark_receipt.journal.encode_hex_with_prefix(),
receipt: serde_json::to_string(&stark_receipt).unwrap(),
uuid,
input: output.hash,
}
.into())
let proof_gen_result = if config.snark && config.bonsai {
bonsai::bonsai_stark_to_snark(uuid, receipt, output.hash)
.await
.map(|r0_response| r0_response.into())
.map_err(|e| ProverError::GuestError(e.to_string()))
} else {
if !config.snark {
warn!("proof is not in snark mode, please check.");
}
Ok(Risc0Response {
proof: receipt.journal.encode_hex_with_prefix(),
receipt: serde_json::to_string(&receipt).unwrap(),
uuid,
input: output.hash,
}
.into())
};

#[cfg(feature = "bonsai-auto-scaling")]
Expand Down

0 comments on commit a52cb27

Please sign in to comment.