diff --git a/crates/contracts/core/src/handler/instantiate.rs b/crates/contracts/core/src/handler/instantiate.rs
index 34f1bf60..65393254 100644
--- a/crates/contracts/core/src/handler/instantiate.rs
+++ b/crates/contracts/core/src/handler/instantiate.rs
@@ -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::{
@@ -8,7 +8,7 @@ use crate::{
execute::attested::{Attestation, HasUserData},
instantiate::{CoreInstantiate, Instantiate},
},
- state::{RawConfig, CONFIG, EPOCH_COUNTER},
+ state::{RawConfig, CONFIG},
};
impl Handler for Instantiate
@@ -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"))
}
diff --git a/crates/contracts/core/src/state.rs b/crates/contracts/core/src/state.rs
index caad0f83..e4bc2691 100644
--- a/crates/contracts/core/src/state.rs
+++ b/crates/contracts/core/src/state.rs
@@ -1,5 +1,3 @@
-use core::time::Duration;
-
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{HexBinary, StdError, Uint64};
use cw_storage_plus::Item;
@@ -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 = Item::new(CONFIG_KEY);
pub const SESSION: Item = Item::new(SESSION_KEY);
-pub const EPOCH_COUNTER: Item = Item::new(EPOCH_COUNTER_KEY);
pub const SEQUENCE_NUM: Item = 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,
dcap_verifier_contract: Option,
@@ -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,
dcap_verifier_contract: Option,
) -> Self {
Self {
mr_enclave,
- epoch_duration,
light_client_opts,
tcbinfo_contract,
dcap_verifier_contract,
@@ -63,7 +56,6 @@ impl Config {
#[cw_serde]
pub struct RawConfig {
mr_enclave: HexBinary,
- epoch_duration: Duration,
light_client_opts: RawLightClientOpts,
tcbinfo_contract: Option,
dcap_verifier_contract: Option,
@@ -88,7 +80,6 @@ impl TryFrom for Config {
fn try_from(value: RawConfig) -> Result {
Ok(Self {
mr_enclave: value.mr_enclave.to_array()?,
- epoch_duration: value.epoch_duration,
light_client_opts: value
.light_client_opts
.try_into()
@@ -103,7 +94,6 @@ impl From 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,
diff --git a/examples/pingpong/contracts/bin/schema.rs b/examples/pingpong/contracts/bin/schema.rs
index f0451ee3..734092e0 100644
--- a/examples/pingpong/contracts/bin/schema.rs
+++ b/examples/pingpong/contracts/bin/schema.rs
@@ -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! {
diff --git a/examples/pingpong/contracts/src/msg.rs b/examples/pingpong/contracts/src/msg.rs
index e2236051..339d537b 100644
--- a/examples/pingpong/contracts/src/msg.rs
+++ b/examples/pingpong/contracts/src/msg.rs
@@ -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 = RawAttested, RA>;
+pub type AttestedMsg = RawAttested, RA>;
#[cw_serde]
pub struct InstantiateMsg {
diff --git a/examples/pingpong/contracts/src/state.rs b/examples/pingpong/contracts/src/state.rs
index 8497e9c7..a5479b1d 100644
--- a/examples/pingpong/contracts/src/state.rs
+++ b/examples/pingpong/contracts/src/state.rs
@@ -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 = Map::new("pings");
+pub const PINGS: Map = Map::new(PINGS_KEY);
diff --git a/examples/pingpong/enclave/src/bin/send_message.rs b/examples/pingpong/enclave/src/bin/send_message.rs
index a45016e6..1786de73 100644
--- a/examples/pingpong/enclave/src/bin/send_message.rs
+++ b/examples/pingpong/enclave/src/bin/send_message.rs
@@ -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;
diff --git a/examples/pingpong/enclave/src/main.rs b/examples/pingpong/enclave/src/main.rs
index 2aab18eb..12a21624 100644
--- a/examples/pingpong/enclave/src/main.rs
+++ b/examples/pingpong/enclave/src/main.rs
@@ -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;
@@ -69,7 +66,6 @@ async fn main() -> Result<(), Box> {
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()),
@@ -86,6 +82,7 @@ async fn main() -> Result<(), Box> {
admin_sk,
};
+ let contract = Arc::new(Mutex::new(None));
let sk = Arc::new(Mutex::new(None));
// Event queue
@@ -99,10 +96,16 @@ async fn main() -> Result<(), Box> {
}
});
- 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(())
}
diff --git a/examples/pingpong/enclave/src/ping_pong_server.rs b/examples/pingpong/enclave/src/ping_pong_server.rs
index 2def1189..4e5e1fdb 100644
--- a/examples/pingpong/enclave/src/ping_pong_server.rs
+++ b/examples/pingpong/enclave/src/ping_pong_server.rs
@@ -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::{
@@ -45,6 +48,7 @@ pub struct PongOp {
#[derive(Clone, Debug)]
pub struct PingPongService {
config: Config,
+ contract: Arc>>,
sk: Arc>>,
attestor: A,
pub queue_producer: Sender>,
@@ -56,12 +60,14 @@ where
{
pub fn new(
config: Config,
+ contract: Arc>>,
sk: Arc>>,
attestor: A,
queue_producer: Sender>,
) -> Self {
Self {
config,
+ contract,
sk,
attestor,
queue_producer,
@@ -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
diff --git a/examples/pingpong/enclave/src/wslistener.rs b/examples/pingpong/enclave/src/wslistener.rs
index 5a92d26d..1470b1a7 100644
--- a/examples/pingpong/enclave/src/wslistener.rs
+++ b/examples/pingpong/enclave/src/wslistener.rs
@@ -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},
@@ -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,
});
diff --git a/examples/transfers/enclave/src/main.rs b/examples/transfers/enclave/src/main.rs
index 1548c3ca..8c1129cb 100644
--- a/examples/transfers/enclave/src/main.rs
+++ b/examples/transfers/enclave/src/main.rs
@@ -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;
@@ -69,7 +66,6 @@ async fn main() -> Result<(), Box> {
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()),