Skip to main content

risc0_zkvm/host/
rpc.rs

1// Copyright 2025 RISC Zero, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::{sync::Arc, time::Duration};
16
17use serde::{Deserialize, Serialize};
18
19use crate::{AssumptionReceipt, Journal, Receipt};
20
21/// TODO
22#[derive(Serialize, Deserialize)]
23pub struct ProofRequest {
24    /// TODO
25    pub binary: Vec<u8>,
26
27    /// TODO
28    pub input: Vec<u8>,
29
30    /// TODO
31    pub assumptions: Vec<AssumptionReceipt>,
32
33    /// TODO
34    pub segment_limit_po2: Option<u32>,
35}
36
37/// TODO
38#[derive(Clone, Debug, Serialize, Deserialize)]
39pub struct JobInfo {
40    /// TODO
41    pub status: JobStatus,
42
43    /// TODO
44    pub elapsed_time: Duration,
45}
46
47/// TODO
48#[derive(Clone, Debug, Serialize, Deserialize)]
49pub enum JobStatus {
50    /// TODO
51    Running(String),
52
53    /// TODO
54    Succeeded(ProofResult),
55
56    /// TODO
57    Failed(TaskError),
58
59    /// TODO
60    TimedOut,
61
62    /// TODO
63    Aborted,
64}
65
66/// TODO
67#[derive(Clone, Debug, Serialize, Deserialize)]
68pub struct ProofResult {
69    /// TODO
70    pub session: Arc<Session>,
71
72    /// TODO
73    pub receipt: Arc<Receipt>,
74}
75
76/// TODO
77#[derive(Debug, Serialize, Deserialize)]
78pub struct Session {
79    /// TODO
80    pub segment_count: usize,
81
82    /// TODO
83    pub user_cycles: u64,
84
85    /// TODO
86    pub total_cycles: u64,
87
88    /// TODO
89    pub journal: Option<Journal>,
90
91    /// TODO
92    pub assumptions: Vec<Arc<AssumptionReceipt>>,
93}
94
95/// TODO
96#[derive(Clone, Debug, Serialize, Deserialize)]
97pub enum TaskError {
98    /// TODO
99    Generic(String),
100}
101
102impl JobStatus {
103    /// TODO
104    pub fn bonsai_status(&self) -> &str {
105        match self {
106            JobStatus::Running(_) => "RUNNING",
107            JobStatus::Succeeded(_) => "SUCCEEDED",
108            JobStatus::Failed(_) => "FAILED",
109            JobStatus::TimedOut => "TIMED_OUT",
110            JobStatus::Aborted => "ABORTED",
111        }
112    }
113}
114
115impl From<anyhow::Error> for TaskError {
116    fn from(value: anyhow::Error) -> Self {
117        Self::Generic(value.to_string())
118    }
119}