Skip to content

Commit

Permalink
feat(raiko): unity sgx & native proof response (#223)
Browse files Browse the repository at this point in the history
* update revm to v35_taiko_v2 + enable c-kzg for revm for cancun precompile

* change beacon rpc back to blastapi

* change beacon enpoint

* fix MPT check

* verify chain spec inside the guest

* remove unused gas_used in GuestInput

* unity sgx & native proof response

* remove comment

---------

Co-authored-by: Brechtpd <Brechtp.devos@gmail.com>
  • Loading branch information
smtmfft and Brechtpd authored May 20, 2024
1 parent d90acd0 commit bead6e9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
6 changes: 1 addition & 5 deletions host/src/raiko.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,7 @@ impl Raiko {
}
}

pub async fn prove(
&self,
input: GuestInput,
output: &GuestOutput,
) -> HostResult<serde_json::Value> {
pub async fn prove(&self, input: GuestInput, output: &GuestOutput) -> HostResult<Proof> {
self.request
.proof_type
.run_prover(
Expand Down
14 changes: 12 additions & 2 deletions host/src/server/api/v1/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::interfaces::error::HostError;
use axum::{response::IntoResponse, Router};
use raiko_lib::input::GuestOutput;
use serde::Serialize;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use tower::ServiceBuilder;
use utoipa::{OpenApi, ToSchema};
use utoipa_scalar::{Scalar, Servable};
Expand Down Expand Up @@ -47,7 +49,7 @@ mod proof;
/// The root API struct which is generated from the `OpenApi` derive macro.
pub struct Docs;

#[derive(Debug, Serialize, ToSchema)]
#[derive(Debug, Serialize, ToSchema, Deserialize)]
/// The response body of a proof request.
pub struct ProofResponse {
#[schema(value_type = Option<GuestOutputDoc>)]
Expand All @@ -69,6 +71,14 @@ impl IntoResponse for ProofResponse {
}
}

impl TryFrom<Value> for ProofResponse {
type Error = HostError;

fn try_from(proof: Value) -> Result<Self, Self::Error> {
serde_json::from_value(proof).map_err(|err| HostError::Conversion(err.to_string()))
}
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(tag = "status", rename_all = "lowercase")]
#[allow(dead_code)]
Expand Down
22 changes: 11 additions & 11 deletions host/src/server/api/v1/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ use std::{fs::File, path::PathBuf};

use crate::metrics::observe_guest_time;
use crate::metrics::observe_prepare_input_time;
use axum::{debug_handler, extract::State, routing::post, Json, Router};
use raiko_lib::{
input::{get_input_path, GuestInput},
Measurement,
};
use serde_json::Value;
use tracing::{debug, info};
use utoipa::OpenApi;

use crate::{
interfaces::{
error::{HostError, HostResult},
Expand All @@ -23,8 +14,17 @@ use crate::{
},
provider::rpc::RpcBlockDataProvider,
raiko::Raiko,
server::api::v1::ProofResponse,
ProverState,
};
use axum::{debug_handler, extract::State, routing::post, Json, Router};
use raiko_lib::{
input::{get_input_path, GuestInput},
Measurement,
};
use serde_json::Value;
use tracing::{debug, info};
use utoipa::OpenApi;

fn get_cached_input(
cache_path: &Option<PathBuf>,
Expand Down Expand Up @@ -86,7 +86,7 @@ async fn proof_handler(
chain_specs: support_chain_specs,
}): State<ProverState>,
Json(req): Json<Value>,
) -> HostResult<Json<Value>> {
) -> HostResult<ProofResponse> {
inc_current_req();
// Override the existing proof request config from the config file and command line
// options with the request from the client.
Expand Down Expand Up @@ -199,7 +199,7 @@ async fn proof_handler(

dec_current_req();

Ok(Json(proof))
ProofResponse::try_from(proof)
}

#[derive(OpenApi)]
Expand Down

0 comments on commit bead6e9

Please sign in to comment.