Skip to content

Commit b758aa7

Browse files
zhizming-zhongjingleizhangBillyWooozTgxKailai-Wang
authored
Query tee strorage via RPC (#1286)
* support query storage via rpc * update * remove useless code * update * make subcommand `get-storage` more generic * minor update * minor update * replace `getter` commands with `get-storage` * Implementation without subx * remove test code * minor update * Update comment * Try to fix CI --------- Co-authored-by: ericzhang <jingleizhang@users.noreply.github.com> Co-authored-by: BillyWooo <thedreamofbilly@gmail.com> Co-authored-by: zTgx <49638837+zTgx@users.noreply.github.com> Co-authored-by: Kai <7630809+Kailai-Wang@users.noreply.github.com> Co-authored-by: Kailai Wang <Kailai.Wang@hotmail.com>
1 parent a57ba59 commit b758aa7

File tree

13 files changed

+601
-191
lines changed

13 files changed

+601
-191
lines changed

tee-worker/Cargo.lock

Lines changed: 225 additions & 155 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tee-worker/build.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ RUN ldd /usr/local/bin/integritee-cli && \
103103

104104
## ts-tests
105105
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash
106-
RUN apt-get install -y nodejs
106+
RUN apt-get install -y nodejs jq
107107
RUN npm install -g yarn
108108

109109
ENTRYPOINT ["/usr/local/bin/integritee-cli"]

tee-worker/cli/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ chrono = "*"
1111
clap = { version = "3.1.6", features = ["derive"] }
1212
codec = { version = "3.0.0", package = "parity-scale-codec", features = ["derive"] }
1313
env_logger = "0.10.0"
14+
frame-metadata = "15.0.0"
1415
hdrhistogram = "7.5.0"
1516
hex = "0.4.2"
1617
log = "0.4"
1718
primitive-types = { version = "0.12.1", features = ["codec"] }
1819
rand = "0.8.5"
1920
rayon = "1.5.1"
21+
scale-value = "0.6.0"
2022
serde = { version = "1.0", features = ["derive"] }
2123
serde_json = "1.0"
2224
sgx_crypto_helper = { branch = "master", git = "https://github.com/apache/teaclave-sgx-sdk.git" }
25+
sp-core-hashing = "6.0.0"
2326
ws = { version = "0.9.1", features = ["ssl"] }
2427

2528
# scs / integritee
@@ -38,6 +41,7 @@ sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "polka
3841
sp-keyring = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" }
3942
sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" }
4043

44+
4145
# local dependencies
4246
ita-sgx-runtime = { path = "../app-libs/sgx-runtime" }
4347
ita-stf = { path = "../app-libs/stf" }

tee-worker/cli/demo_direct_call.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,13 @@ read -r MRENCLAVE <<< "$($CLIENT list-workers | awk '/ MRENCLAVE: / { print $2;
7070
echo ""
7171
echo "* Create a new incognito account for Alice"
7272
ICGACCOUNTALICE=//AliceIncognito
73+
ICGACCOUNTALICE_PUBKEY=0x50503350955afe8a107d6f115dc253eb5d75a3fe37a90b373db26cc12e3c6661
7374
echo " Alice's incognito account = ${ICGACCOUNTALICE}"
7475
echo ""
7576

7677
echo "* Create a new incognito account for Bob"
7778
ICGACCOUNTBOB=//BobIncognito
79+
ICGACCOUNTBOB_PUBKEY=0xc24c5b3969d8ec4ca8a655a98dcc136d5d4c29d1206ffe7721e80ebdfa1d0b77
7880
echo " Bob's incognito account = ${ICGACCOUNTBOB}"
7981
echo ""
8082

@@ -92,17 +94,19 @@ $CLIENT trusted --mrenclave ${MRENCLAVE} --direct transfer ${ICGACCOUNTALICE} ${
9294
echo ""
9395

9496
# Prevent getter being executed too early and returning an outdated result, before the transfer was made.
95-
echo "* Waiting 2 seconds"
96-
sleep 2
97+
echo "* Waiting 6 seconds"
98+
sleep 6
9799
echo ""
98100

99101
echo "* Get balance of Alice's incognito account"
100-
RESULT=$(${CLIENT} trusted --mrenclave ${MRENCLAVE} balance ${ICGACCOUNTALICE} | xargs)
102+
# RESULT=$(${CLIENT} trusted --mrenclave ${MRENCLAVE} balance ${ICGACCOUNTALICE} | xargs)
103+
RESULT=$(${CLIENT} trusted --mrenclave ${MRENCLAVE} get-storage System Account ${ICGACCOUNTALICE_PUBKEY} | jq ".data.free" | xargs)
101104
echo $RESULT
102105
echo ""
103106

104107
echo "* Bob's incognito account balance"
105-
RESULT=$(${CLIENT} trusted --mrenclave ${MRENCLAVE} balance ${ICGACCOUNTBOB} | xargs)
108+
# RESULT=$(${CLIENT} trusted --mrenclave ${MRENCLAVE} balance ${ICGACCOUNTBOB} | xargs)
109+
RESULT=$(${CLIENT} trusted --mrenclave ${MRENCLAVE} get-storage System Account ${ICGACCOUNTBOB_PUBKEY} | jq ".data.free" | xargs)
106110
echo $RESULT
107111
echo ""
108112

tee-worker/cli/demo_shielding_unshielding.sh

Lines changed: 73 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,23 @@ function wait_assert_state()
100100
exit 1
101101
}
102102

103+
# usage:
104+
# wait_assert_account_state <mrenclave> <account-pub-key> <jq-filter> <expected-state>
105+
function wait_assert_account_state()
106+
{
107+
for i in $(seq 1 $WAIT_ROUNDS); do
108+
state=$(${CLIENT} trusted --mrenclave "$1" get-storage System Account "$2" | jq "$3")
109+
if [ $state -eq "$4" ]; then
110+
return
111+
else
112+
sleep $WAIT_INTERVAL_SECONDS
113+
fi
114+
done
115+
echo
116+
echo "Assert $2 $3 failed, expected = $4, actual = $state"
117+
exit 1
118+
}
119+
103120
# Do a live query and assert the given account's state is equal to expected
104121
# usage:
105122
# assert_state <mrenclave> <account> <state-name> <expected-state>
@@ -119,6 +136,25 @@ function assert_state()
119136
exit 1
120137
}
121138

139+
# usage:
140+
# assert_account_state <mrenclave> <account-pub-key> <jq-filter> <expected-state>
141+
function assert_account_state()
142+
{
143+
state=$(${CLIENT} trusted --mrenclave "$1" get-storage System Account "$2" | jq "$3")
144+
if [ -z "$state" ]; then
145+
echo "Query Account $2 $3 failed"
146+
exit 1
147+
fi
148+
149+
if [ $state -eq "$4" ]; then
150+
return
151+
fi
152+
echo
153+
echo "Assert $2 $3 failed, expected = $4, actual = $state"
154+
exit 1
155+
156+
}
157+
122158
echo "* Query on-chain enclave registry:"
123159
WORKERS=$($CLIENT list-workers)
124160
echo "WORKERS: "
@@ -138,38 +174,46 @@ fi
138174

139175
echo "* Create a new incognito account for Alice"
140176
ICGACCOUNTALICE=//AliceIncognito
177+
ICGACCOUNTALICE_PUBKEY=0x50503350955afe8a107d6f115dc253eb5d75a3fe37a90b373db26cc12e3c6661
141178
echo " Alice's incognito account = ${ICGACCOUNTALICE}"
142179
echo ""
143180

144-
echo "* Create a new incognito account for Bob"
145-
ICGACCOUNTBOB=$(${CLIENT} trusted --mrenclave ${MRENCLAVE} new-account)
146-
echo " Bob's incognito account = ${ICGACCOUNTBOB}"
147-
echo ""
148-
149181
# Asssert the initial balance of Alice incognito
150-
# The initial balance of Bob incognito should always be 0, as Bob is newly created
182+
# We create different (new) accounts for Bob incognito, hence his initial balance is always 0
151183
BALANCE_INCOGNITO_ALICE=0
152184
case $TEST in
153185
first)
154-
wait_assert_state ${MRENCLAVE} ${ICGACCOUNTALICE} balance 0 ;;
186+
# wait_assert_state ${MRENCLAVE} ${ICGACCOUNTALICE} balance 0 ;;
187+
wait_assert_account_state ${MRENCLAVE} ${ICGACCOUNTALICE_PUBKEY} ".data.free" 0
188+
ICGACCOUNTBOB=//BobIncognitoFirst
189+
ICGACCOUNTBOB_PUBKEY=0xf073e0349517dcd85f4058d22d8bf585e3027b0d9826a4e2294c407aa55b7605 ;;
155190
second)
156-
wait_assert_state ${MRENCLAVE} ${ICGACCOUNTALICE} balance $(( AMOUNT_SHIELD - AMOUNT_TRANSFER - AMOUNT_UNSHIELD ))
157-
BALANCE_INCOGNITO_ALICE=$(( AMOUNT_SHIELD - AMOUNT_TRANSFER - AMOUNT_UNSHIELD )) ;;
191+
# wait_assert_state ${MRENCLAVE} ${ICGACCOUNTALICE} balance $(( AMOUNT_SHIELD - AMOUNT_TRANSFER - AMOUNT_UNSHIELD ))
192+
wait_assert_account_state ${MRENCLAVE} ${ICGACCOUNTALICE_PUBKEY} ".data.free" $(( AMOUNT_SHIELD - AMOUNT_TRANSFER - AMOUNT_UNSHIELD ))
193+
BALANCE_INCOGNITO_ALICE=$(( AMOUNT_SHIELD - AMOUNT_TRANSFER - AMOUNT_UNSHIELD ))
194+
ICGACCOUNTBOB=//BobIncognitoSecond
195+
ICGACCOUNTBOB_PUBKEY=0x061d0c6eb3e940c885626236050a469eb2d44222f17d80e38d72a9379a073f46 ;;
158196
*)
159197
echo "unsupported test mode"
160198
exit 1 ;;
161199
esac
162200

201+
echo "* Create a new incognito account for Bob"
202+
echo " Bob's incognito account = ${ICGACCOUNTBOB}"
203+
echo ""
204+
163205
echo "* Shield ${AMOUNT_SHIELD} tokens to Alice's incognito account"
164206
${CLIENT} shield-funds //Alice ${ICGACCOUNTALICE} ${AMOUNT_SHIELD} ${MRENCLAVE}
165207
echo ""
166208

167209
echo "* Wait and assert Alice's incognito account balance... "
168-
wait_assert_state ${MRENCLAVE} ${ICGACCOUNTALICE} balance $(( BALANCE_INCOGNITO_ALICE + AMOUNT_SHIELD ))
210+
# wait_assert_state ${MRENCLAVE} ${ICGACCOUNTALICE} balance $(( BALANCE_INCOGNITO_ALICE + AMOUNT_SHIELD ))
211+
wait_assert_account_state ${MRENCLAVE} ${ICGACCOUNTALICE_PUBKEY} ".data.free" $(( BALANCE_INCOGNITO_ALICE + AMOUNT_SHIELD ))
169212
echo "✔ ok"
170213

171214
echo "* Wait and assert Bob's incognito account balance... "
172-
wait_assert_state ${MRENCLAVE} ${ICGACCOUNTBOB} balance 0
215+
# wait_assert_state ${MRENCLAVE} ${ICGACCOUNTBOB} balance 0
216+
wait_assert_account_state ${MRENCLAVE} ${ICGACCOUNTBOB_PUBKEY} ".data.free" 0
173217
echo "✔ ok"
174218
echo ""
175219

@@ -178,11 +222,13 @@ $CLIENT trusted --mrenclave ${MRENCLAVE} transfer ${ICGACCOUNTALICE} ${ICGACCOUN
178222
echo ""
179223

180224
echo "* Wait and assert Alice's incognito account balance... "
181-
wait_assert_state ${MRENCLAVE} ${ICGACCOUNTALICE} balance $(( BALANCE_INCOGNITO_ALICE + AMOUNT_SHIELD - AMOUNT_TRANSFER ))
225+
# wait_assert_state ${MRENCLAVE} ${ICGACCOUNTALICE} balance $(( BALANCE_INCOGNITO_ALICE + AMOUNT_SHIELD - AMOUNT_TRANSFER ))
226+
wait_assert_account_state ${MRENCLAVE} ${ICGACCOUNTALICE_PUBKEY} ".data.free" $(( BALANCE_INCOGNITO_ALICE + AMOUNT_SHIELD - AMOUNT_TRANSFER ))
182227
echo "✔ ok"
183228

184229
echo "* Wait and assert Bob's incognito account balance... "
185-
wait_assert_state ${MRENCLAVE} ${ICGACCOUNTBOB} balance ${AMOUNT_TRANSFER}
230+
# wait_assert_state ${MRENCLAVE} ${ICGACCOUNTBOB} balance ${AMOUNT_TRANSFER}
231+
wait_assert_account_state ${MRENCLAVE} ${ICGACCOUNTBOB_PUBKEY} ".data.free" ${AMOUNT_TRANSFER}
186232
echo "✔ ok"
187233
echo ""
188234

@@ -191,11 +237,13 @@ ${CLIENT} trusted --mrenclave ${MRENCLAVE} --xt-signer //Alice unshield-funds ${
191237
echo ""
192238

193239
echo "* Wait and assert Alice's incognito account balance... "
194-
wait_assert_state ${MRENCLAVE} ${ICGACCOUNTALICE} balance $(( BALANCE_INCOGNITO_ALICE + AMOUNT_SHIELD - AMOUNT_TRANSFER - AMOUNT_UNSHIELD ))
240+
# wait_assert_state ${MRENCLAVE} ${ICGACCOUNTALICE} balance $(( BALANCE_INCOGNITO_ALICE + AMOUNT_SHIELD - AMOUNT_TRANSFER - AMOUNT_UNSHIELD ))
241+
wait_assert_account_state ${MRENCLAVE} ${ICGACCOUNTALICE_PUBKEY} ".data.free" $(( BALANCE_INCOGNITO_ALICE + AMOUNT_SHIELD - AMOUNT_TRANSFER - AMOUNT_UNSHIELD ))
195242
echo "✔ ok"
196243

197244
echo "* Wait and assert Bob's incognito account balance... "
198-
wait_assert_state ${MRENCLAVE} ${ICGACCOUNTBOB} balance ${AMOUNT_TRANSFER}
245+
# wait_assert_state ${MRENCLAVE} ${ICGACCOUNTBOB} balance ${AMOUNT_TRANSFER}
246+
wait_assert_account_state ${MRENCLAVE} ${ICGACCOUNTBOB_PUBKEY} ".data.free" ${AMOUNT_TRANSFER}
199247
echo "✔ ok"
200248

201249
# Test the nonce handling, using Bob's incognito account as the sender as Alice's
@@ -207,7 +255,8 @@ echo " Charlie's incognito account = ${ICGACCOUNTCHARLIE}"
207255
echo ""
208256

209257
echo "* Assert Bob's incognito initial nonce..."
210-
assert_state ${MRENCLAVE} ${ICGACCOUNTBOB} nonce 0
258+
# assert_state ${MRENCLAVE} ${ICGACCOUNTBOB} nonce 0
259+
assert_account_state ${MRENCLAVE} ${ICGACCOUNTBOB_PUBKEY} ".nonce" 0
211260
echo "✔ ok"
212261
echo ""
213262

@@ -219,7 +268,8 @@ done
219268
echo ""
220269

221270
echo "* Assert Bob's incognito current nonce..."
222-
wait_assert_state ${MRENCLAVE} ${ICGACCOUNTBOB} nonce 3
271+
# wait_assert_state ${MRENCLAVE} ${ICGACCOUNTBOB} nonce 3
272+
wait_assert_account_state ${MRENCLAVE} ${ICGACCOUNTBOB_PUBKEY} ".nonce" 3
223273
echo "✔ ok"
224274
echo ""
225275

@@ -229,7 +279,8 @@ echo ""
229279

230280
echo "* Assert Bob's incognito nonce..."
231281
# the nonce should be increased nontheless, even for the failed tx
232-
wait_assert_state ${MRENCLAVE} ${ICGACCOUNTBOB} nonce 4
282+
# wait_assert_state ${MRENCLAVE} ${ICGACCOUNTBOB} nonce 4
283+
wait_assert_account_state ${MRENCLAVE} ${ICGACCOUNTBOB_PUBKEY} ".nonce" 4
233284
echo "✔ ok"
234285
echo ""
235286

@@ -238,13 +289,15 @@ $CLIENT trusted --direct --mrenclave ${MRENCLAVE} transfer ${ICGACCOUNTBOB} ${IC
238289
echo ""
239290

240291
echo "* Assert Bob's incognito nonce..."
241-
wait_assert_state ${MRENCLAVE} ${ICGACCOUNTBOB} nonce 5
292+
# wait_assert_state ${MRENCLAVE} ${ICGACCOUNTBOB} nonce 5
293+
wait_assert_account_state ${MRENCLAVE} ${ICGACCOUNTBOB_PUBKEY} ".nonce" 5
242294
echo "✔ ok"
243295
echo ""
244296

245297
echo "* Wait and assert Bob's incognito account balance... "
246298
# in total 4 balance transfer should go through => 1.2 UNIT remaining
247-
wait_assert_state ${MRENCLAVE} ${ICGACCOUNTBOB} balance $(( AMOUNT_TRANSFER * 6 / 10 ))
299+
# wait_assert_state ${MRENCLAVE} ${ICGACCOUNTBOB} balance $(( AMOUNT_TRANSFER * 6 / 10 ))
300+
wait_assert_account_state ${MRENCLAVE} ${ICGACCOUNTBOB_PUBKEY} ".data.free" $(( AMOUNT_TRANSFER * 6 / 10 ))
248301
echo "✔ ok"
249302

250303
echo ""

tee-worker/cli/demo_sidechain.sh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,13 @@ fi
9494
echo ""
9595
echo "* Create a new incognito account for Alice"
9696
ICGACCOUNTALICE=//AliceIncognito
97+
ICGACCOUNTALICE_PUBKEY=0x50503350955afe8a107d6f115dc253eb5d75a3fe37a90b373db26cc12e3c6661
9798
echo " Alice's incognito account = ${ICGACCOUNTALICE}"
9899
echo ""
99100

100101
echo "* Create a new incognito account for Bob"
101102
ICGACCOUNTBOB=//BobIncognito
103+
ICGACCOUNTBOB_PUBKEY=0xc24c5b3969d8ec4ca8a655a98dcc136d5d4c29d1206ffe7721e80ebdfa1d0b77
102104
echo " Bob's incognito account = ${ICGACCOUNTBOB}"
103105
echo ""
104106

@@ -110,7 +112,9 @@ echo ""
110112
${CLIENTWORKER1} trusted --mrenclave ${MRENCLAVE} --direct set-balance ${ICGACCOUNTBOB} 0
111113

112114
echo "Get balance of Alice's incognito account (on worker 1)"
113-
${CLIENTWORKER1} trusted --mrenclave ${MRENCLAVE} balance ${ICGACCOUNTALICE}
115+
# ${CLIENTWORKER1} trusted --mrenclave ${MRENCLAVE} balance ${ICGACCOUNTALICE}
116+
# ICGACCOUNTALICE's public key is 0x50503350955afe8a107d6f115dc253eb5d75a3fe37a90b373db26cc12e3c6661
117+
${CLIENTWORKER1} trusted --mrenclave ${MRENCLAVE} get-storage System Account ${ICGACCOUNTALICE_PUBKEY}
114118
echo ""
115119

116120
# Send funds from Alice to Bobs account, on worker 1.
@@ -129,17 +133,19 @@ $CLIENTWORKER2 trusted --mrenclave ${MRENCLAVE} --direct transfer ${ICGACCOUNTAL
129133
echo ""
130134

131135
# Prevent getter being executed too early and returning an outdated result, before the transfer was made.
132-
echo "* Waiting 2 seconds"
133-
sleep 2
136+
echo "* Waiting 6 seconds"
137+
sleep 6
134138
echo ""
135139

136140
echo "* Get balance of Alice's incognito account (on worker 1)"
137-
ALICE_BALANCE=$(${CLIENTWORKER1} trusted --mrenclave ${MRENCLAVE} balance ${ICGACCOUNTALICE} | xargs)
141+
# ALICE_BALANCE=$(${CLIENTWORKER1} trusted --mrenclave ${MRENCLAVE} balance ${ICGACCOUNTALICE} | xargs)
142+
ALICE_BALANCE=$(${CLIENTWORKER1} trusted --mrenclave ${MRENCLAVE} get-storage System Account ${ICGACCOUNTALICE_PUBKEY} | jq ".data.free" | xargs)
138143
echo "$ALICE_BALANCE"
139144
echo ""
140145

141146
echo "* Get balance of Bob's incognito account (on worker 1)"
142-
BOB_BALANCE=$(${CLIENTWORKER1} trusted --mrenclave ${MRENCLAVE} balance ${ICGACCOUNTBOB} | xargs)
147+
# BOB_BALANCE=$(${CLIENTWORKER1} trusted --mrenclave ${MRENCLAVE} balance ${ICGACCOUNTBOB} | xargs)
148+
BOB_BALANCE=$(${CLIENTWORKER1} trusted --mrenclave ${MRENCLAVE} get-storage System Account ${ICGACCOUNTBOB_PUBKEY} | jq ".data.free" | xargs)
143149
echo "$BOB_BALANCE"
144150
echo ""
145151

0 commit comments

Comments
 (0)