Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions apps/mtcs/enclave/src/mtcs_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use mtcs::{
};
use quartz_common::{
contract::{msg::execute::attested::RawAttested, state::Config},
enclave::attestor::Attestor,
enclave::{attestor::Attestor, server::ProofOfPublication},
};
use serde::{Deserialize, Serialize};
use tonic::{Request, Response, Result as TonicResult, Status};
Expand Down Expand Up @@ -64,10 +64,21 @@ where
&self,
request: Request<RunClearingRequest>,
) -> TonicResult<Response<RunClearingResponse>> {
let message: RunClearingMessage = {
// Light client check
let message: ProofOfPublication<RunClearingMessage> = {
let message = request.into_inner().message;
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!
let liquidity_sources: Vec<LiquiditySource> =
message.liquidity_sources.into_iter().collect();
Expand Down
2 changes: 1 addition & 1 deletion cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ pub enum EnclaveCommand {
#[clap(long)]
path: Option<PathBuf>,
},
}
}
Loading