1use serde::{Deserialize, Serialize};
2use sp1_prover::{worker::ProofFromNetwork, SP1VerifyingKey};
3use sp1_prover_types::{network_base_types::ProofMode, SerializableRiscvMachine};
4
5use crate::CudaClientError;
6use sp1_core_machine::io::SP1Stdin;
7
8#[derive(Serialize, Deserialize)]
9pub enum Request {
10 Setup { elf: Vec<u8>, machine: SerializableRiscvMachine },
12
13 ProveWithMode { mode: ProofMode, key: [u8; 32], stdin: SP1Stdin, proof_nonce: [u32; 4] },
15
16 Destroy { key: [u8; 32] },
18}
19
20#[derive(Serialize, Deserialize)]
21pub enum Response {
22 Ok,
24 Setup { id: [u8; 32], vk: SP1VerifyingKey },
26 Proof { proof: ProofFromNetwork },
28 ProverError(String),
30 InternalError(String),
32 ConnectionClosed,
37}
38
39impl Response {
40 pub(crate) const fn type_of(&self) -> &'static str {
42 match self {
43 Response::Ok => "Ok",
44 Response::Setup { .. } => "Setup",
45 Response::Proof { .. } => "Proof",
46 Response::InternalError(_) => "InternalError",
47 Response::ProverError(_) => "ProverError",
48 Response::ConnectionClosed => "ConnectionClosed",
49 }
50 }
51
52 pub(crate) fn into_result(self) -> Result<Self, CudaClientError> {
54 match self {
55 Self::InternalError(e) => Err(CudaClientError::ServerError(e)),
56 Self::ProverError(e) => {
57 Err(CudaClientError::ServerError(e))
59 }
60 _ => Ok(self),
61 }
62 }
63}