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

refactor: decouple mtcs_server from quartz #53

Closed
wants to merge 6 commits into from
Closed
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
61 changes: 59 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[workspace]
resolver = "2"
members = [
members = [ "apps/mtcs/enclave",
"core/light-client-proofs/*",
"core/quartz",
"cosmwasm/packages/*",
"utils/*",
]
exclude = ["apps/mtcs/contracts/cw-tee-mtcs"]
exclude = ["apps/mtcs/contracts/cw-tee-mtcs", "apps/mtcs/enclave", "apps/transfers"]

[workspace.package]
version = "0.1.0"
Expand Down
51 changes: 51 additions & 0 deletions apps/mtcs/enclave/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[package]
name = "enclave"
version = "0.1.0"
edition = "2021"

[profile.release]
opt-level = 3
debug = false
rpath = false
lto = true
debug-assertions = false
codegen-units = 1
panic = 'abort'
incremental = false
overflow-checks = true

[dependencies]
# external
hex = { version = "0.4.3", default-features = false }
k256 = { version = "0.13.2", default-features = false, features = ["ecdsa"] }
schemars = "0.8.15"
serde = { version = "1.0.189", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.49" }
tonic = { version = "0.11.0"}
cosmrs = { version = "0.16.0"}
cosmwasm-std = { version = "1.5.2", default-features = false }
serde_json = { version = "1.0.94", default-features = false }
ecies = { version = "0.2.3", default-features = false, features = ["pure"] }
clap = { version = "4.1.8", default-features = false, features = ["derive", "std"] }
tokio = { version = "1.0", default-features = false, features = ["macros", "rt-multi-thread"] }
tendermint = { version = "=0.36.0", default-features = false }
tendermint-light-client = { version = "=0.36.0", default-features = false, features = ["rust-crypto"] }
color-eyre = { version = "0.6.2", default-features = false }
prost = { version = "0.12.3", default-features = false }

# local
cw-tee-mtcs.workspace = true
cycles-sync.workspace = true
mtcs.workspace = true

# quartz
quartz-cw = { path = "../../../cosmwasm/packages/quartz-cw" }
quartz-proto = { path = "../../../core/quartz-proto" }
quartz-enclave = { path = "../../../core/quartz"}

[dev-dependencies]
cw-multi-test = "0.17.0"
serde_json = "1.0.113"

[build-dependencies]
tonic-build.workspace = true
1 change: 1 addition & 0 deletions apps/mtcs/enclave/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## MTCS Server
File renamed without changes.
2 changes: 1 addition & 1 deletion core/quartz/src/cli.rs → apps/mtcs/enclave/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::net::SocketAddr;

use clap::Parser;
use color_eyre::eyre::{eyre, Result};
use tendermint::Hash;
use cosmrs::tendermint::Hash;
use tendermint_light_client::types::{Height, TrustThreshold};

fn parse_trust_threshold(s: &str) -> Result<TrustThreshold> {
Expand Down
15 changes: 6 additions & 9 deletions core/quartz/src/main.rs → apps/mtcs/enclave/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,26 @@
unused_qualifications
)]

mod attestor;
mod cli;
mod mtcs_server;
mod proto;
mod server;

use std::{
sync::{Arc, Mutex},
time::Duration,
};

use clap::Parser;
use cli::Cli;
use mtcs_server::MtcsService;
use proto::clearing_server::ClearingServer as MtcsServer;
use quartz_cw::state::{Config, LightClientOpts};
use quartz_proto::quartz::core_server::CoreServer;
use tonic::transport::Server;

use crate::{
use quartz_enclave::{
attestor::{Attestor, EpidAttestor},
cli::Cli,
mtcs_server::MtcsService,
proto::clearing_server::ClearingServer as MtcsServer,
server::CoreService,
};
use quartz_proto::quartz::core_server::CoreServer;
use tonic::transport::Server;

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ use mtcs::{
algo::mcmf::primal_dual::PrimalDual, impls::complex_id::ComplexIdMtcs,
obligation::SimpleObligation, prelude::DefaultMtcs, setoff::SimpleSetoff, Mtcs,
};
use quartz_enclave::attestor::Attestor;
use serde::{Deserialize, Serialize};
use tonic::{Request, Response, Result as TonicResult, Status};

use crate::{
attestor::Attestor,
proto::{clearing_server::Clearing, RunClearingRequest, RunClearingResponse},
};
use crate::proto::{clearing_server::Clearing, RunClearingRequest, RunClearingResponse};

#[derive(Clone, Debug)]
pub struct MtcsService<A> {
Expand Down Expand Up @@ -54,6 +52,23 @@ where
&self,
request: Request<RunClearingRequest>,
) -> TonicResult<Response<RunClearingResponse>> {
// Pass in JSON of Requests vector and the STATE

// Serialize into Requests enum
// Loop through, decrypt the ciphertexts

// Read the state blob from chain

// Decrypt and deserialize

// Loop through requests and apply onto state

// Encrypt state

// Create withdraw requests

// Send to chain

let message: RunClearingMessage = {
let message = request.into_inner().message;
serde_json::from_str(&message).map_err(|e| Status::invalid_argument(e.to_string()))?
Expand Down
File renamed without changes.
File renamed without changes.
9 changes: 4 additions & 5 deletions core/quartz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ repository.workspace = true
keywords = ["blockchain", "cosmos", "tendermint", "cycles", "quartz"]
readme = "README.md"

[lib]
path = "src/lib.rs"

[dependencies]
# external
clap.workspace = true
color-eyre.workspace = true
ecies.workspace = true
hex.workspace = true
k256.workspace = true
prost.workspace = true
rand.workspace = true
serde.workspace = true
serde_json.workspace = true
Expand All @@ -38,7 +40,4 @@ quartz-cw.workspace = true
quartz-proto.workspace = true
quartz-relayer.workspace = true
quartz-tee-ra.workspace = true
tm-stateless-verifier.workspace = true

[build-dependencies]
tonic-build.workspace = true
tm-stateless-verifier.workspace = true
17 changes: 17 additions & 0 deletions core/quartz/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#![doc = include_str!("../README.md")]
#![forbid(unsafe_code)]
#![warn(
clippy::checked_conversions,
clippy::panic,
clippy::panic_in_result_fn,
missing_docs,
trivial_casts,
trivial_numeric_casts,
rust_2018_idioms,
unused_lifetimes,
unused_import_braces,
unused_qualifications
)]

pub mod attestor;

Check warning on line 16 in core/quartz/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a module

warning: missing documentation for a module --> core/quartz/src/lib.rs:16:1 | 16 | pub mod attestor; | ^^^^^^^^^^^^^^^^ | note: the lint level is defined here --> core/quartz/src/lib.rs:7:5 | 7 | missing_docs, | ^^^^^^^^^^^^
pub mod server;

Check warning on line 17 in core/quartz/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a module

warning: missing documentation for a module --> core/quartz/src/lib.rs:17:1 | 17 | pub mod server; | ^^^^^^^^^^^^^^
Loading