-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathprover.rs
73 lines (62 loc) · 2.04 KB
/
prover.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use reth_primitives::{ChainId, B256};
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
use crate::input::{AggregationGuestInput, AggregationGuestOutput, GuestInput, GuestOutput};
#[derive(thiserror::Error, Debug)]
pub enum ProverError {
#[error("ProverError::GuestError `{0}`")]
GuestError(String),
#[error("ProverError::FileIo `{0}`")]
FileIo(#[from] std::io::Error),
#[error("ProverError::Param `{0}`")]
Param(#[from] serde_json::Error),
#[error("Store error `{0}`")]
StoreError(String),
}
impl From<String> for ProverError {
fn from(e: String) -> Self {
ProverError::GuestError(e)
}
}
pub type ProverResult<T, E = ProverError> = core::result::Result<T, E>;
pub type ProverConfig = serde_json::Value;
pub type ProofKey = (ChainId, B256, u8);
#[derive(Clone, Debug, Serialize, ToSchema, Deserialize, Default)]
/// The response body of a proof request.
pub struct Proof {
/// The proof either TEE or ZK.
pub proof: Option<String>,
/// The public input
pub input: Option<B256>,
/// The TEE quote.
pub quote: Option<String>,
/// The assumption UUID.
pub uuid: Option<String>,
/// The kzg proof.
pub kzg_proof: Option<String>,
}
#[async_trait::async_trait]
pub trait IdWrite: Send {
async fn store_id(&mut self, key: ProofKey, id: String) -> ProverResult<()>;
async fn remove_id(&mut self, key: ProofKey) -> ProverResult<()>;
}
#[async_trait::async_trait]
pub trait IdStore: IdWrite {
async fn read_id(&self, key: ProofKey) -> ProverResult<String>;
}
#[allow(async_fn_in_trait)]
pub trait Prover {
async fn run(
input: GuestInput,
output: &GuestOutput,
config: &ProverConfig,
store: Option<&mut dyn IdWrite>,
) -> ProverResult<Proof>;
async fn aggregate(
input: AggregationGuestInput,
output: &AggregationGuestOutput,
config: &ProverConfig,
store: Option<&mut dyn IdWrite>,
) -> ProverResult<Proof>;
async fn cancel(proof_key: ProofKey, read: Box<&mut dyn IdStore>) -> ProverResult<()>;
}