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

Merge in quartz-decouple and transfers app #64

Merged
merged 36 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
2ff9808
Private Transfers with Quartz
dangush Jun 17, 2024
c2e57b6
Get contract to build
hu55a1n1 Jun 18, 2024
14e720d
Example for attested quartz app message
hu55a1n1 Jun 18, 2024
87da05d
Example for attested msg with the framework
hu55a1n1 Jun 18, 2024
bcbd46f
todos for quartz logic for transfers
dangush Jun 18, 2024
d1d6251
add schema
ebuchman Jun 18, 2024
6bba9eb
refactor: decouple mtcs_server from quartz
dangush Jun 18, 2024
5e79819
satisfied some docs errors
dangush Jun 18, 2024
87898f6
fmt
dangush Jun 18, 2024
3c857e9
Remove attestation on Transfer, put it on Update
davekaj Jun 18, 2024
004643f
missed some stuff
dangush Jun 18, 2024
f0cd4c0
fmt
dangush Jun 18, 2024
0b7ad14
Merge branch 'dangush/quartz-decouple' into transfers-enclave
dangush Jun 18, 2024
6ea389d
merge decouple into transfers
dangush Jun 18, 2024
4474668
merge
dangush Jun 18, 2024
a5e3cb4
move the build script out as well
dangush Jun 18, 2024
83eb709
merge decouple with transfers
dangush Jun 18, 2024
050c628
WIP enclave work for transfers app
davekaj Jun 18, 2024
bc92584
transfers enclave logic wip
dangush Jun 18, 2024
c4ab85c
initialize state and change Request::Ciphertext to Request::Transfer
ebuchman Jun 19, 2024
d81fabd
Merge branch 'main' into transfers
hu55a1n1 Jun 19, 2024
4f3cb27
Use RawAttestedMsgSansHandler
hu55a1n1 Jun 19, 2024
508b513
finished transfers enclave logic, added handling withdraw/deposit req…
dangush Jun 19, 2024
41b7ad7
encrypt binary
dangush Jun 19, 2024
a3f86ea
build error fixes + adding balance overdraft checks for withdraw and …
dangush Jun 19, 2024
e21a978
withdraw balances fixed
dangush Jun 19, 2024
4da4828
check if state is 0 for initialization
dangush Jun 19, 2024
2ade6a2
remove attestations
dangush Jun 19, 2024
772efc2
switch btreemap to vec
dangush Jun 19, 2024
ba315ef
requests draining bug
dangush Jun 19, 2024
be7bfaa
perf: error handling everywhere in transfers_server
dangush Jun 19, 2024
7b13f5f
fix: known bugs patched, no error propagation yet
dangush Jun 20, 2024
4c8c91b
added attestations to update
dangush Jun 20, 2024
0f7b6d9
Merge branch 'main' into transfers
dangush Jun 26, 2024
d1ca751
refactor: AttestedMsg struct should be within quartz-cw and imported …
dangush Jun 26, 2024
23ad585
fmt
dangush Jun 26, 2024
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", "apps/transfers/enclave"]

[workspace.package]
version = "0.1.0"
Expand Down
52 changes: 52 additions & 0 deletions apps/mtcs/enclave/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[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"}
tonic-build = "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.
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 @@ -5,9 +5,10 @@ use std::{

use cosmrs::{tendermint::account::Id as TmAccountId, AccountId};
use cosmwasm_std::HexBinary;
//TODO: get rid of this
use cw_tee_mtcs::{
msg::execute::SubmitSetoffsMsg,
state::{RawCipherText, RawHash, SettleOff, Transfer},
state::{RawHash, SettleOff, Transfer},
};
use cycles_sync::types::RawObligation;
use ecies::{decrypt, encrypt};
Expand All @@ -16,13 +17,14 @@ use mtcs::{
algo::mcmf::primal_dual::PrimalDual, impls::complex_id::ComplexIdMtcs,
obligation::SimpleObligation, prelude::DefaultMtcs, setoff::SimpleSetoff, Mtcs,
};
use quartz_cw::msg::execute::attested::RawAttested;
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};

pub type RawCipherText = HexBinary;

#[derive(Clone, Debug)]
pub struct MtcsService<A> {
Expand Down Expand Up @@ -60,6 +62,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 Expand Up @@ -93,12 +112,12 @@ where

let msg = SubmitSetoffsMsg { setoffs_enc };

let quote = self
let attestation = self
.attestor
.quote(msg.clone())
.map_err(|e| Status::internal(e.to_string()))?;

let attested_msg = AttestedMsg { msg, quote };
let attested_msg = RawAttested { msg, attestation };
let message = serde_json::to_string(&attested_msg).unwrap();
Ok(Response::new(RunClearingResponse { message }))
}
Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions apps/transfers/contracts/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[alias]
wasm = "build --target wasm32-unknown-unknown --release --lib"
wasm-debug = "build --target wasm32-unknown-unknown --lib"
schema = "run schema"

Loading
Loading