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

Remove all epoch related code #285

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
9 changes: 2 additions & 7 deletions crates/contracts/core/src/handler/instantiate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{DepsMut, Env, MessageInfo, Response, Uint64};
use cosmwasm_std::{DepsMut, Env, MessageInfo, Response};
use quartz_tee_ra::Error as RaVerificationError;

use crate::{
Expand All @@ -8,7 +8,7 @@ use crate::{
execute::attested::{Attestation, HasUserData},
instantiate::{CoreInstantiate, Instantiate},
},
state::{RawConfig, CONFIG, EPOCH_COUNTER},
state::{RawConfig, CONFIG},
};

impl<A> Handler for Instantiate<A>
Expand All @@ -28,11 +28,6 @@ impl Handler for CoreInstantiate {
CONFIG
.save(deps.storage, &RawConfig::from(self.config().clone()))
.map_err(Error::Std)?;
let epoch_counter = Uint64::new(1);

EPOCH_COUNTER
.save(deps.storage, &epoch_counter)
.map_err(Error::Std)?;

Ok(Response::new().add_attribute("action", "instantiate"))
}
Expand Down
10 changes: 0 additions & 10 deletions crates/contracts/core/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use core::time::Duration;

use cosmwasm_schema::cw_serde;
use cosmwasm_std::{HexBinary, StdError, Uint64};
use cw_storage_plus::Item;
Expand All @@ -14,17 +12,14 @@ pub type TrustThreshold = (u64, u64);

pub const CONFIG_KEY: &str = "quartz_config";
pub const SESSION_KEY: &str = "quartz_session";
pub const EPOCH_COUNTER_KEY: &str = "epoch_counter";
pub const SEQUENCE_NUM_KEY: &str = "quartz_seq_num";
pub const CONFIG: Item<RawConfig> = Item::new(CONFIG_KEY);
pub const SESSION: Item<Session> = Item::new(SESSION_KEY);
pub const EPOCH_COUNTER: Item<Uint64> = Item::new(EPOCH_COUNTER_KEY);
pub const SEQUENCE_NUM: Item<Uint64> = Item::new(SEQUENCE_NUM_KEY);

#[derive(Clone, Debug, PartialEq)]
pub struct Config {
mr_enclave: MrEnclave,
epoch_duration: Duration,
light_client_opts: LightClientOpts,
tcbinfo_contract: Option<String>,
dcap_verifier_contract: Option<String>,
Expand All @@ -33,14 +28,12 @@ pub struct Config {
impl Config {
pub fn new(
mr_enclave: MrEnclave,
epoch_duration: Duration,
light_client_opts: LightClientOpts,
tcbinfo_contract: Option<String>,
dcap_verifier_contract: Option<String>,
) -> Self {
Self {
mr_enclave,
epoch_duration,
light_client_opts,
tcbinfo_contract,
dcap_verifier_contract,
Expand All @@ -63,7 +56,6 @@ impl Config {
#[cw_serde]
pub struct RawConfig {
mr_enclave: HexBinary,
epoch_duration: Duration,
light_client_opts: RawLightClientOpts,
tcbinfo_contract: Option<String>,
dcap_verifier_contract: Option<String>,
Expand All @@ -88,7 +80,6 @@ impl TryFrom<RawConfig> for Config {
fn try_from(value: RawConfig) -> Result<Self, Self::Error> {
Ok(Self {
mr_enclave: value.mr_enclave.to_array()?,
epoch_duration: value.epoch_duration,
light_client_opts: value
.light_client_opts
.try_into()
Expand All @@ -103,7 +94,6 @@ impl From<Config> for RawConfig {
fn from(value: Config) -> Self {
Self {
mr_enclave: value.mr_enclave.into(),
epoch_duration: value.epoch_duration,
light_client_opts: value.light_client_opts.into(),
tcbinfo_contract: value.tcbinfo_contract,
dcap_verifier_contract: value.dcap_verifier_contract,
Expand Down
2 changes: 1 addition & 1 deletion examples/pingpong/contracts/bin/schema.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ping_pong_contract::msg::{ExecuteMsg, InstantiateMsg};
use cosmwasm_schema::write_api;
use ping_pong_contract::msg::{ExecuteMsg, InstantiateMsg};

fn main() {
write_api! {
Expand Down
4 changes: 2 additions & 2 deletions examples/pingpong/contracts/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use cosmwasm_schema::cw_serde;
use quartz_common::contract::{
msg::execute::attested::{RawAttested, RawAttestedMsgSansHandler, RawDefaultAttestation},
msg::execute::attested::{RawAttested, RawDefaultAttestation, RawMsgSansHandler},
prelude::*,
};

pub type AttestedMsg<M, RA = RawDefaultAttestation> = RawAttested<RawAttestedMsgSansHandler<M>, RA>;
pub type AttestedMsg<M, RA = RawDefaultAttestation> = RawAttested<RawMsgSansHandler<M>, RA>;

#[cw_serde]
pub struct InstantiateMsg<RA = RawDefaultAttestation> {
Expand Down
4 changes: 3 additions & 1 deletion examples/pingpong/contracts/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use cosmwasm_std::HexBinary;
use cw_storage_plus::Map;

pub const PINGS_KEY: &str = "pings";

// Maps pubkeys (String representation of HexBinary) to messages (HexBinary representaton of encrypted data)
// The message that a pubkey maps to is encrypted either to that pubkey or the enclave's pubkey
pub const PINGS: Map<String, HexBinary> = Map::new("pings");
pub const PINGS: Map<String, HexBinary> = Map::new(PINGS_KEY);
7 changes: 3 additions & 4 deletions examples/pingpong/enclave/src/bin/send_message.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use std::str::FromStr;

use ping_pong_contract::msg::{execute::Ping, ExecuteMsg};
use cosmrs::{tendermint::chain::Id as ChainId, AccountId};
use cosmwasm_std::HexBinary;
use cw_client::{CliClient, CwClient};
use ecies::{decrypt, encrypt};
use ecies::encrypt;
use hex;
use k256::ecdsa::{SigningKey, VerifyingKey};
use rand_core::OsRng;
use k256::ecdsa::VerifyingKey;
use ping_pong_contract::msg::{execute::Ping, ExecuteMsg};
use reqwest::Url;
use serde_json::json;

Expand Down
21 changes: 12 additions & 9 deletions examples/pingpong/enclave/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ pub mod proto;
pub mod state;
pub mod wslistener;

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

use clap::Parser;
use cli::Cli;
Expand Down Expand Up @@ -69,7 +66,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let config = Config::new(
attestor.mr_enclave()?,
Duration::from_secs(30 * 24 * 60),
light_client_opts,
args.tcbinfo_contract.map(|c| c.to_string()),
args.dcap_verifier_contract.map(|c| c.to_string()),
Expand All @@ -86,6 +82,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
admin_sk,
};

let contract = Arc::new(Mutex::new(None));
let sk = Arc::new(Mutex::new(None));

// Event queue
Expand All @@ -99,10 +96,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
});

QuartzServer::new(config.clone(), sk.clone(), attestor.clone(), ws_config)
.add_service(PingPongService::new(config, sk, attestor, tx))
.serve(args.rpc_addr)
.await?;
QuartzServer::new(
config.clone(),
contract.clone(),
sk.clone(),
attestor.clone(),
ws_config,
)
.add_service(PingPongService::new(config, sk, contract, attestor, tx))
.serve(args.rpc_addr)
.await?;

Ok(())
}
16 changes: 14 additions & 2 deletions examples/pingpong/enclave/src/ping_pong_server.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use std::sync::{Arc, Mutex};

use ping_pong_contract::msg::execute::{Ping, Pong};
use cosmrs::AccountId;
use cosmwasm_std::HexBinary;
use ecies::{decrypt, encrypt};
use k256::ecdsa::SigningKey;
use ping_pong_contract::{
msg::execute::{Ping, Pong},
state::PINGS_KEY,
};
use quartz_common::{
contract::{msg::execute::attested::RawAttested, state::Config},
enclave::{
Expand Down Expand Up @@ -45,6 +48,7 @@ pub struct PongOp<A: Attestor> {
#[derive(Clone, Debug)]
pub struct PingPongService<A: Attestor> {
config: Config,
contract: Arc<Mutex<Option<AccountId>>>,
sk: Arc<Mutex<Option<SigningKey>>>,
attestor: A,
pub queue_producer: Sender<PongOp<A>>,
Expand All @@ -56,12 +60,14 @@ where
{
pub fn new(
config: Config,
contract: Arc<Mutex<Option<AccountId>>>,
sk: Arc<Mutex<Option<SigningKey>>>,
attestor: A,
queue_producer: Sender<PongOp<A>>,
) -> Self {
Self {
config,
contract,
sk,
attestor,
queue_producer,
Expand All @@ -81,8 +87,14 @@ where
serde_json::from_str(&message).map_err(|e| Status::invalid_argument(e.to_string()))?
};

let contract = self.contract.lock().unwrap().clone();
let (proof_value, ping) = message
.verify(self.config.light_client_opts())
.verify(
self.config.light_client_opts(),
contract.expect("contract not set"),
PINGS_KEY.to_string(),
None,
)
.map_err(Status::failed_precondition)?;

// Verify that the ping.message contents match the value of the storage proof
Expand Down
10 changes: 5 additions & 5 deletions examples/pingpong/enclave/src/wslistener.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::{collections::BTreeMap, str::FromStr};

use anyhow::{anyhow, Error, Result};
use cosmrs::{tendermint::chain::Id as ChainId, AccountId};
use cw_client::{CwClient, GrpcClient};
use futures_util::StreamExt;
use ping_pong_contract::msg::{
execute::{Ping, Pong},
AttestedMsg, ExecuteMsg,
};
use cosmrs::{tendermint::chain::Id as ChainId, AccountId};
use cw_client::{CwClient, GrpcClient};
use futures_util::StreamExt;
use quartz_common::{
contract::msg::execute::attested::{RawAttested, RawAttestedMsgSansHandler},
contract::msg::execute::attested::{RawAttested, RawMsgSansHandler},
enclave::{
attestor::Attestor,
server::{WebSocketHandler, WsListenerConfig},
Expand Down Expand Up @@ -187,7 +187,7 @@ where
// Build on-chain response
// TODO add non-mock support
let pong_msg = ExecuteMsg::Pong(AttestedMsg {
msg: RawAttestedMsgSansHandler(attested.msg),
msg: RawMsgSansHandler(attested.msg),
attestation: attested.attestation,
});

Expand Down
6 changes: 1 addition & 5 deletions examples/transfers/enclave/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ pub mod state;
pub mod transfers_server;
pub mod wslistener;

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

use clap::Parser;
use cli::Cli;
Expand Down Expand Up @@ -69,7 +66,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let config = Config::new(
attestor.mr_enclave()?,
Duration::from_secs(30 * 24 * 60),
light_client_opts,
args.tcbinfo_contract.map(|c| c.to_string()),
args.dcap_verifier_contract.map(|c| c.to_string()),
Expand Down
Loading