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

Mock attestation #82

Merged
merged 18 commits into from
Jul 18, 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
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions apps/mtcs/contracts/cw-tee-mtcs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ panic = 'abort'
incremental = false
overflow-checks = true

[features]
mock-sgx = ["quartz-cw/mock-sgx"]

[dependencies]
# external
hex = { version = "0.4.3", default-features = false }
Expand Down
10 changes: 5 additions & 5 deletions apps/mtcs/contracts/cw-tee-mtcs/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ use std::collections::BTreeMap;
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{HexBinary, Uint64};
use quartz_cw::{
msg::execute::attested::{RawAttested, RawAttestedMsgSansHandler, RawEpidAttestation},
msg::execute::attested::{RawAttested, RawAttestedMsgSansHandler, RawDefaultAttestation},
prelude::*,
};

use crate::state::{RawHash, SettleOff};

type AttestedMsg<M> = RawAttested<RawAttestedMsgSansHandler<M>, RawEpidAttestation>;
type AttestedMsg<M, RA> = RawAttested<RawAttestedMsgSansHandler<M>, RA>;

#[cw_serde]
pub struct InstantiateMsg(pub QuartzInstantiateMsg);
pub struct InstantiateMsg<RA = RawDefaultAttestation>(pub QuartzInstantiateMsg<RA>);

#[cw_serde]
#[allow(clippy::large_enum_variant)]
pub enum ExecuteMsg {
pub enum ExecuteMsg<RA = RawDefaultAttestation> {
Quartz(QuartzExecuteMsg),
FaucetMint(execute::FaucetMintMsg),
Transfer(execute::Cw20Transfer),
SubmitObligation(execute::SubmitObligationMsg),
SubmitObligations(execute::SubmitObligationsMsg),
SubmitSetoffs(AttestedMsg<execute::SubmitSetoffsMsg>),
SubmitSetoffs(AttestedMsg<execute::SubmitSetoffsMsg, RA>),
InitClearing,
SetLiquiditySources(execute::SetLiquiditySourcesMsg),
}
Expand Down
3 changes: 3 additions & 0 deletions apps/mtcs/enclave/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ version = "0.1.0"
edition = "2021"
authors = ["Informal Systems <[email protected]>"]

[features]
mock-sgx = ["quartz-cw/mock-sgx", "quartz-enclave/mock-sgx"]

[dependencies]
# external
clap.workspace = true
Expand Down
10 changes: 6 additions & 4 deletions apps/mtcs/enclave/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use mtcs_server::MtcsService;
use proto::clearing_server::ClearingServer as MtcsServer;
use quartz_cw::state::{Config, LightClientOpts};
use quartz_enclave::{
attestor::{Attestor, EpidAttestor},
attestor::{Attestor, DefaultAttestor},
server::CoreService,
};
use quartz_proto::quartz::core_server::CoreServer;
Expand All @@ -53,8 +53,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
args.max_block_lag,
)?;

let attestor = DefaultAttestor::default();

let config = Config::new(
EpidAttestor.mr_enclave()?,
attestor.mr_enclave()?,
Duration::from_secs(30 * 24 * 60),
light_client_opts,
);
Expand All @@ -65,9 +67,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.add_service(CoreServer::new(CoreService::new(
config,
sk.clone(),
EpidAttestor,
attestor.clone(),
)))
.add_service(MtcsServer::new(MtcsService::new(sk.clone(), EpidAttestor)))
.add_service(MtcsServer::new(MtcsService::new(sk, attestor)))
.serve(args.rpc_addr)
.await?;

Expand Down
19 changes: 16 additions & 3 deletions apps/transfers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ You may want to exit and start a new terminal session to get the rust toolchain
Now downgrade rust to v1.76.0:

```
rustup install v1.76.0
rustup default v1.76.0
rustup install 1.76.0
rustup default 1.76.0
```

Check the version with `cargo version`.
Expand Down Expand Up @@ -61,7 +61,7 @@ git checkout v0.44.0
go install ./cmd/wasmd
```

Check that both work by running `grpccurl` and `wasmd`.
Check that both work by running `grpcurl` and `wasmd`.

Finally, you neeed `websocat`:

Expand Down Expand Up @@ -114,6 +114,19 @@ First set the `NODE_URL` variable to the address of the blockchain node. If it's
The `scripts` dir contains some bash scripts to help run the app.
These scripts should be replaced by a new `quartz` tool. See [issue](https://github.com/informalsystems/cycles-quartz/issues/61).

Note: to build/run on a non-SGX machine you must set the `MOCK_SGX` env var for all bash scripts below
```
# 1st Terminal
$ export MOCK_SGX=1
$ bash scripts/build.sh
$ bash scripts/start.sh

# 2nd Terminal
$ export MOCK_SGX=1
$ bash scripts/deploy.sh
$ ...
```

### Build the Binaries

Build the enclave binary and the smart contract binary:
Expand Down
3 changes: 3 additions & 0 deletions apps/transfers/contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ panic = 'abort'
incremental = false
overflow-checks = true

[features]
mock-sgx = ["quartz-cw/mock-sgx"]

[dependencies]
# external
sha2 = "0.10.8"
Expand Down
2 changes: 1 addition & 1 deletion apps/transfers/contracts/bin/schema.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_schema::write_api;
use transfers_contracts::msg::{ExecuteMsg, InstantiateMsg};
use transfers_contract::msg::{ExecuteMsg, InstantiateMsg};

fn main() {
write_api! {
Expand Down
9 changes: 8 additions & 1 deletion apps/transfers/contracts/build.sh
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
RUSTFLAGS='-C link-arg=-s' cargo wasm
FEATURES=

if [ -n "$MOCK_SGX" ]; then
echo "MOCK_SGX is set. Adding mock-sgx feature."
FEATURES="--features=mock-sgx"
fi

RUSTFLAGS='-C link-arg=-s' cargo wasm $FEATURES
2 changes: 1 addition & 1 deletion apps/transfers/contracts/deploy-contract.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ TX_HASH=$(echo $RES | jq -r '.["txhash"]')

echo ""
while ! $CMD query tx $TX_HASH &> /dev/null; do
echo "... 🕐 waiting for contract to be queryable"
echo "... 🕐 waiting for contract to be queryable from tx hash $TX_HASH"
sleep 1
done

Expand Down
10 changes: 5 additions & 5 deletions apps/transfers/contracts/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Addr, HexBinary, Uint128};
use quartz_cw::{
msg::execute::attested::{RawAttested, RawEpidAttestation},
msg::execute::attested::{RawAttested, RawDefaultAttestation},
prelude::*,
};

#[cw_serde]
pub struct InstantiateMsg {
pub quartz: QuartzInstantiateMsg,
pub struct InstantiateMsg<RA = RawDefaultAttestation> {
pub quartz: QuartzInstantiateMsg<RA>,
pub denom: String,
}

#[cw_serde]
#[allow(clippy::large_enum_variant)]
pub enum ExecuteMsg {
pub enum ExecuteMsg<RA = RawDefaultAttestation> {
// quartz initialization
Quartz(QuartzExecuteMsg),

Expand All @@ -28,7 +28,7 @@ pub enum ExecuteMsg {
ClearTextTransferRequest(execute::ClearTextTransferRequestMsg),

// enclave msg
Update(RawAttested<execute::RawUpdateMsg, RawEpidAttestation>),
Update(RawAttested<execute::RawUpdateMsg, RA>),
}

pub mod execute {
Expand Down
Loading
Loading