fix(mtcs): re-introduce light client check in enclave (#148)

This commit is contained in:
dusterbloom 2024-08-06 11:49:35 +02:00 committed by GitHub
parent 3f1cd0b463
commit b65f6b45de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 3 deletions

View file

@ -17,7 +17,7 @@ use mtcs::{
}; };
use quartz_common::{ use quartz_common::{
contract::{msg::execute::attested::RawAttested, state::Config}, contract::{msg::execute::attested::RawAttested, state::Config},
enclave::attestor::Attestor, enclave::{attestor::Attestor, server::ProofOfPublication},
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tonic::{Request, Response, Result as TonicResult, Status}; use tonic::{Request, Response, Result as TonicResult, Status};
@ -64,10 +64,21 @@ where
&self, &self,
request: Request<RunClearingRequest>, request: Request<RunClearingRequest>,
) -> TonicResult<Response<RunClearingResponse>> { ) -> TonicResult<Response<RunClearingResponse>> {
let message: RunClearingMessage = { // Light client check
let message: ProofOfPublication<RunClearingMessage> = {
let message = request.into_inner().message; let message = request.into_inner().message;
serde_json::from_str(&message).map_err(|e| Status::invalid_argument(e.to_string()))? serde_json::from_str(&message).map_err(|e| Status::invalid_argument(e.to_string()))?
}; };
let (proof_value, message) = message
.verify(self.config.light_client_opts())
.map_err(Status::failed_precondition)?;
let proof_value_matches_msg =
serde_json::to_string(&message.intents).is_ok_and(|s| s.as_bytes() == proof_value);
if !proof_value_matches_msg {
return Err(Status::failed_precondition("proof verification"));
}
// TODO: ensure no duplicates somewhere else! // TODO: ensure no duplicates somewhere else!
let liquidity_sources: Vec<LiquiditySource> = let liquidity_sources: Vec<LiquiditySource> =
message.liquidity_sources.into_iter().collect(); message.liquidity_sources.into_iter().collect();

View file

@ -65,4 +65,4 @@ pub enum EnclaveCommand {
#[clap(long)] #[clap(long)]
path: Option<PathBuf>, path: Option<PathBuf>,
}, },
} }