Skip to content

Commit d924756

Browse files
authored
new template app (#271)
1 parent bc24db6 commit d924756

30 files changed

+8418
-1
lines changed

crates/utils/tm-prover/src/config.rs

+6
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ impl Default for Config {
8787
.parse()
8888
.unwrap(),
8989
storage_key: String::default(),
90+
storage_namespace: None,
9091
}
9192
}
9293
}
@@ -141,4 +142,9 @@ pub struct Config {
141142
/// Storage key of the state item for which proofs must be retrieved
142143
#[clap(long)]
143144
pub storage_key: String,
145+
146+
/// Storage namespace of the state item for which proofs must be retrieved
147+
/// (only makes sense when dealing with maps)
148+
#[clap(long)]
149+
pub storage_namespace: Option<String>,
144150
}

crates/utils/tm-prover/src/prover.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub async fn prove(
4747
verbose: _,
4848
contract_address,
4949
storage_key,
50+
storage_namespace,
5051
}: TmProverConfig,
5152
) -> Result<ProofOutput> {
5253
let options = Options {
@@ -115,7 +116,7 @@ pub async fn prove(
115116
.await?;
116117

117118
let path = WASM_STORE_KEY.to_owned();
118-
let data = CwAbciKey::new(contract_address, storage_key, None);
119+
let data = CwAbciKey::new(contract_address, storage_key, storage_namespace);
119120
let result = client
120121
.abci_query(Some(path), data, Some(proof_height), true)
121122
.await?;

examples/pingpong/.cargo/config.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
target-dir = "target"

examples/pingpong/README.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Ping Pong
2+
3+
This is a minimal Quartz demo app to serve as a scaffold to learn and build off of.
4+
5+
It allows users to submit a message encrypted to the enclave's pubkey,
6+
and receive a response from the enclave encrypted to their own pubkey.
7+
<!--
8+
See the [getting started guide](/docs/getting_started.md) to get it quickly
9+
setup on a local testnet without SGX or on a real testnet using an Azure SGX
10+
node.
11+
12+
See this [video of an early demo of the app at the Flashbots
13+
TEE-salon](https://www.youtube.com/watch?v=3Tv6k02zvBc&t=2517s).
14+
-->
15+
16+
# Step by Step
17+
18+
1) Run
19+
20+
```
21+
quartz --mock-sgx dev --unsafe-trust-latest --contract-manifest contracts/Cargo.toml
22+
```
23+
24+
2. Copy the contract address from the output and paste it onto line 46 of the `send_message.rs` script.
25+
3. Copy the pub key from the handshake and paste it onto line 18 of `send_message.rs`.
26+
27+
The pubkey in the `Ping` struct will be the user's pubkey, which you can leave untouched.
28+
29+
4. Next, send this transaction to "Ping" the enclave.
30+
```
31+
cargo run --bin send_message
32+
```
33+
34+
5. Watch the logs from `quartz dev`. You should see the decrypted message printed.
35+
36+
Now let's find the enclave's response.
37+
38+
6. Query the contract for its messages
39+
```
40+
neutrond query wasm contract-state smart $CONTRACT '{
41+
"get_all_messages": {}
42+
}' -o json
43+
```
44+
45+
7. Copy the value from, what should be, the only entry in the map.
46+
47+
8. Go to `send_message.rs` and paste the hex value onto line 67. Run `decrypt_enclave_response` to see the decrypted output.

examples/pingpong/cargo-generate.toml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[template]
2+
description = "An functioning example of a quartz app"
3+
4+
ignore = [
5+
"target/",
6+
"contracts/target",
7+
"contracts/schema",
8+
"enclave/target",
9+
"enclave/src/prost/*",
10+
"frontend/package-lock.json",
11+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[alias]
2+
wasm = "build --target wasm32-unknown-unknown --release --lib"
3+
wasm-debug = "build --target wasm32-unknown-unknown --lib"
4+
schema = "run schema"
5+
unit-test = "test --lib"

0 commit comments

Comments
 (0)