Skip to content

Commit

Permalink
improve evaluation workflow and figure plot scripts; TODO: need to re…
Browse files Browse the repository at this point in the history
…run the evaluation data, provisioning time seems too long
  • Loading branch information
imtypist committed Apr 28, 2023
1 parent 63afa0e commit 47f2138
Show file tree
Hide file tree
Showing 111 changed files with 10,192 additions and 727 deletions.
32 changes: 20 additions & 12 deletions 2.client_deploy_and_call.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/bin/bash

model_name=$1

if [ -z $model_name ];then
echo "please provide a model name!"
exit -1
fi

WORK_DIR=$(pwd)

function getCurTs(){
Expand All @@ -25,34 +32,35 @@ cd console
printLog "deploy smart contract"
contract_address=$(bash console.sh deploy SmartCall | awk 'NR==2' | awk '{print $3}')

# feh $WORK_DIR/tee-provider/non_sgx_gramine/$model_name/input.jpg

## execute model inference with non-SGX gramine
printLog "call inference function (non-sgx-gramine, public alexnet model)"
bash console.sh call SmartCall $contract_address inference "cd $WORK_DIR/tee-provider/non_sgx_gramine/alexnet && gramine-direct ./pytorch pytorchexample.py && cp result.txt ../../"
printLog "call inference function (non-sgx-gramine, public $model_name model)"
bash console.sh call SmartCall $contract_address inference "cd $WORK_DIR/tee-provider/non_sgx_gramine/$model_name && gramine-direct ./pytorch pytorchexample.py && cp result.txt ../../"

## execute model inference with Gramine in SGX
printLog "call inference function (sgx-gramine, public alexnet model)"
bash console.sh call SmartCall $contract_address inference "cd $WORK_DIR/tee-provider/sgx_gramine/plaintext_model/alexnet && gramine-sgx ./pytorch pytorchexample.py && python3 $WORK_DIR/quote-verification/quote-extractor.py result.quote"
printLog "call inference function (sgx-gramine, public $model_name model)"
bash console.sh call SmartCall $contract_address inference "cd $WORK_DIR/tee-provider/sgx_gramine/plaintext_model/$model_name && gramine-sgx ./pytorch pytorchexample.py && python3 $WORK_DIR/quote-verification/quote-extractor.py result.quote"

## execute private model inference with Gramine in SGX
printLog "client or TEE provider starts secret key provisioning server"
cd $WORK_DIR/tee-provider/sgx_gramine/encrypted_model/alexnet/secret_prov_pf
cd $WORK_DIR/tee-provider/sgx_gramine/encrypted_model/$model_name/secret_prov_pf

RA_TLS_ALLOW_DEBUG_ENCLAVE_INSECURE=1 RA_TLS_ALLOW_OUTDATED_TCB_INSECURE=1 ./server_dcap wrap_key &> eval_logs/server_dcap.log &
RA_TLS_ALLOW_DEBUG_ENCLAVE_INSECURE=1 RA_TLS_ALLOW_OUTDATED_TCB_INSECURE=1 ./server_dcap wrap_key > server_dcap.log 2>&1 &

cd $WORK_DIR/console

printLog "call inference function (sgx-gramine, private alexnet model)"
bash console.sh call SmartCall $contract_address inference "cd $WORK_DIR/tee-provider/sgx_gramine/encrypted_model/alexnet && gramine-sgx ./pytorch pytorchexample.py && python3 $WORK_DIR/quote-verification/quote-extractor.py result.quote"
printLog "call inference function (sgx-gramine, private $model_name model)"
bash console.sh call SmartCall $contract_address inference "cd $WORK_DIR/tee-provider/sgx_gramine/encrypted_model/$model_name && gramine-sgx ./pytorch pytorchexample.py && python3 $WORK_DIR/quote-verification/quote-extractor.py result.quote"

printLog "close server_dcap"
killall server_dcap

## verify execution result
printLog "verify execution result (sgx-gramine, public alexnet model)"
$WORK_DIR/quote-verification/app -quote $WORK_DIR/tee-provider/sgx_gramine/plaintext_model/alexnet/result.quote
printLog "verify execution result (sgx-gramine, public $model_name model)"
$WORK_DIR/quote-verification/app -quote $WORK_DIR/tee-provider/sgx_gramine/plaintext_model/$model_name/result.quote

printLog "verify execution result (sgx-gramine, private alexnet model)"
$WORK_DIR/quote-verification/app -quote $WORK_DIR/tee-provider/sgx_gramine/encrypted_model/alexnet/result.quote
printLog "verify execution result (sgx-gramine, private $model_name model)"
$WORK_DIR/quote-verification/app -quote $WORK_DIR/tee-provider/sgx_gramine/encrypted_model/$model_name/result.quote

printLog "on-chain and off-chain execution model test is completed"
32 changes: 32 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
sparklines:
- title: CPU usage
rate-ms: 500
scale: 0
sample: ps -A -o %cpu | awk '{s+=$1} END {print s}'
- title: Free memory pages
rate-ms: 500
scale: 0
sample: free -w | grep 'Mem' | awk '{print $3}'

runcharts:
- title: TEE provider monitor
rate-ms: 1000
scale: 2
items:
- label: TEE provider
sample: top -bn1 | grep sgx | grep -v grep | awk '{print $9}'
- title: blockchain node monitor
rate-ms: 1000 # sampling rate, default = 1000
scale: 2 # number of digits after sample decimal point, default = 1
legend:
enabled: true # enables item labels, default = true
details: true # enables item statistics: cur/min/max/dlt values, default = true
items:
- label: blockchain node0
sample: top -bn1 -p $(ps -ef | grep node0 | grep -v grep | awk '{print $2}') | grep fisco | grep -v grep | awk '{print $9}'
- label: blockchain node1
sample: top -bn1 -p $(ps -ef | grep node1 | grep -v grep | awk '{print $2}') | grep fisco | grep -v grep | awk '{print $9}'
- label: blockchain node2
sample: top -bn1 -p $(ps -ef | grep node2 | grep -v grep | awk '{print $2}') | grep fisco | grep -v grep | awk '{print $9}'
- label: blockchain node3
sample: top -bn1 -p $(ps -ef | grep node3 | grep -v grep | awk '{print $2}') | grep fisco | grep -v grep | awk '{print $9}'
31 changes: 27 additions & 4 deletions dist/figures/das-and-secretprov.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
import matplotlib.pyplot as plt
import matplotlib
import numpy as np
import os
import linecache

matplotlib.rcParams['font.size'] = 14

labels = ['registration/update', 'remote attestation', 'secret provisioning']
all_reg = [9.419, 9.705, 9.512]
all_attest = [1.64, 1.66, 1.69]
secret_prov_time = [1.133, 0.951]
labels = ['TEE provider register/update', 'distributed attestation', 'secret key provisioning']
# all_reg = [4.624, 4.616, 4.764, 4.766, 4.734]
# all_attest = [0.227, 0.209, 0.210, 0.163, 0.171, 0.166, 0.168, 0.172, 0.179, 0.180]
# secret_prov_time = [12.481, 40.978, 16.545, 30.190, 22.880]
all_reg = []
all_attest = []
secret_prov_time = []
files = ['alexnet', 'densenet161', 'resnet18', 'squeezenet1_0', 'vgg16']

for file in files:
st = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 14).split('[')[3][:13])
ed = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 17).split('[')[3][:13])
all_reg.append((ed-st)/1000)
st = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 30).split('[')[3][:13]) + int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 46).split('[')[3][:13])
ed = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 31).split('[')[3][:13]) + int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 47).split('[')[3][:13])
all_attest.append((ed-st)/1000)
st = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 41).split('[')[3][:13]) + int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 47).split('[')[3][:13])
ed = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 42).split('[')[3][:13]) + int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 48).split('[')[3][:13])
all_attest.append((ed-st)/1000)
st = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 38).split('[')[3][:13])
ed = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 39).split('[')[3][:13])
secret_prov_time.append((ed-st)/1000)

all_data = [all_reg, all_attest, secret_prov_time]
print(all_data)

width = 0.35


Expand Down
Binary file added dist/figures/e2e-latency-multi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
112 changes: 112 additions & 0 deletions dist/figures/e2e-latency-multi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import matplotlib.pyplot as plt
import matplotlib
import numpy as np
import linecache

matplotlib.rcParams['font.size'] = 14

labels = ['alex', 'dense161', 'res18', 'squeeze1.0', 'vgg16']
send_contract_call = []
off_chain_pre_check = []
model_inference = []
generate_quote = []
execution_return = []
verify_quote = []

private_send_contract_call = []
private_off_chain_pre_check = []
private_key_provision = []
private_model_inference = []
private_generate_quote = []
private_execution_return = []
private_verify_quote = []

files = ['alexnet', 'densenet161', 'resnet18', 'squeezenet1_0', 'vgg16']
for file in files:
st = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 26).split('[')[3][:13])
ed = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 28).split('[')[3][:13])
send_contract_call.append((ed-st)/1000)
st = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 28).split('[')[3][:13])
ed = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 29).split('[')[3][:13])
off_chain_pre_check.append((ed-st)/1000)
st = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 29).split('[')[3][:13])
ed = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 30).split('[')[3][:13])
model_inference.append((ed-st)/1000)
st = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 30).split('[')[3][:13])
ed = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 31).split('[')[3][:13])
generate_quote.append((ed-st)/1000)
st = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 31).split('[')[3][:13])
ed = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 33).split('[')[3][:13])
execution_return.append((ed-st)/1000)
st = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 46).split('[')[3][:13])
ed = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 47).split('[')[3][:13])
verify_quote.append((ed-st)/1000)

st = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 35).split('[')[3][:13])
ed = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 37).split('[')[3][:13])
private_send_contract_call.append((ed-st)/1000)
st = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 37).split('[')[3][:13])
ed = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 38).split('[')[3][:13])
private_off_chain_pre_check.append((ed-st)/1000)
st = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 38).split('[')[3][:13])
ed = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 39).split('[')[3][:13])
private_key_provision.append((ed-st)/1000)
st = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 40).split('[')[3][:13])
ed = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 41).split('[')[3][:13])
private_model_inference.append((ed-st)/1000)
st = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 41).split('[')[3][:13])
ed = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 42).split('[')[3][:13])
private_generate_quote.append((ed-st)/1000)
st = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 42).split('[')[3][:13])
ed = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 44).split('[')[3][:13])
private_execution_return.append((ed-st)/1000)
st = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 47).split('[')[3][:13])
ed = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 48).split('[')[3][:13])
private_verify_quote.append((ed-st)/1000)

width = 0.35
send_contract_call = np.array(send_contract_call)
off_chain_pre_check = np.array(off_chain_pre_check)
model_inference = np.array(model_inference)
generate_quote = np.array(generate_quote)
execution_return = np.array(execution_return)
verify_quote = np.array(verify_quote)

fig, ax = plt.subplots()
_pos = np.arange(len(labels))
private_send_contract_call = np.array(send_contract_call)
private_off_chain_pre_check = np.array(off_chain_pre_check)
private_key_provision = np.array(private_key_provision)
private_model_inference = np.array(model_inference)
private_generate_quote = np.array(generate_quote)
private_execution_return = np.array(execution_return)
private_verify_quote = np.array(verify_quote)

ax.bar(_pos+width/2, private_send_contract_call, width, label='on-chain contract call (transfer to off-chain)', color='lightyellow', hatch='///', edgecolor='black')
ax.bar(_pos+width/2, private_off_chain_pre_check, width, bottom=private_send_contract_call, label='enclave initialization', color='lightgray', hatch='.', edgecolor='black')
ax.bar(_pos+width/2, private_key_provision, width, bottom=private_send_contract_call+private_off_chain_pre_check, label='secret key provisioning (private model only)', color='orange', hatch='\\', edgecolor='black')
ax.bar(_pos+width/2, private_model_inference, width, bottom=private_send_contract_call+private_off_chain_pre_check+private_key_provision, label='model inference', color='lightblue', hatch='x', edgecolor='black')
ax.bar(_pos+width/2, private_generate_quote, width, bottom=private_send_contract_call+private_off_chain_pre_check+private_key_provision+private_model_inference, label='quote generation', color='lightpink', hatch='o')
ax.bar(_pos+width/2, private_verify_quote, width, bottom=private_send_contract_call+private_off_chain_pre_check+private_key_provision+private_model_inference+private_generate_quote, label='quote verification', color='lightseagreen', hatch='+')
ax.bar(_pos+width/2, private_execution_return, width, bottom=private_send_contract_call+private_off_chain_pre_check+private_key_provision+private_model_inference+private_generate_quote+private_verify_quote, label='contract context recovery (back to on-chain)', color='red', hatch='*')


ax.bar(_pos-width/2, send_contract_call, width, color='lightyellow', hatch='///', edgecolor='black')
ax.bar(_pos-width/2, off_chain_pre_check, width, bottom=send_contract_call, color='lightgray', hatch='.', edgecolor='black')
ax.bar(_pos-width/2, model_inference, width, bottom=off_chain_pre_check+send_contract_call, color='lightblue', hatch='x', edgecolor='black')
ax.bar(_pos-width/2, generate_quote, width, bottom=off_chain_pre_check+send_contract_call+model_inference, color='lightpink', hatch='o')
ax.bar(_pos-width/2, verify_quote, width, bottom=off_chain_pre_check+send_contract_call+model_inference+generate_quote, color='lightseagreen', hatch='+')
ax.bar(_pos-width/2, execution_return, width, bottom=off_chain_pre_check+send_contract_call+model_inference+generate_quote+verify_quote, color='red', hatch='*')

# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('time cost (seconds)')
x = np.arange(len(labels))
ax.set_xticks(x,labels)


# ax.yaxis.grid(True)

fig.tight_layout()
ax.legend(loc='best')

plt.show()
Binary file removed dist/figures/evm-gas-cost-new.png
Binary file not shown.
Binary file modified dist/figures/evm-gas-cost.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 8 additions & 6 deletions dist/figures/evm-gas-cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
MACs = [0.72, 7.63, 11.34, 15.5, 19.67, 1.82, 3.68, 4.12, 7.85, 11.58, 0.83, 0.36, 2.88, 7.82, 3.42, 4.37, 2.85]

fig, ax = plt.subplots()
ax.barh(labels, [8*i for i in MACs], color='lightgrey', edgecolor='black')
ax.bar(labels, [8*i for i in MACs], color='lightgrey', edgecolor='black')
labels = ax.get_xticklabels()

ax.axvline(8e-3, ls='--', color='r')

ax.set(xlabel='estimated gas cost (G)')
ax.set_xscale("log")
ax.xaxis.grid(True)
ax.axhline(30e-3, ls='--', color='r')

ax.set(ylabel='estimated gas cost (G)')
ax.set_yscale("log")
# ax.yaxis.grid(True)
plt.tight_layout()
plt.xticks(rotation=30, ha='right')
plt.annotate(text='Ethereum block gas upper limit 30M', xy=(6, 30e-3), xytext=(8, 0.8), fontsize=18, horizontalalignment='center', bbox={'fc': 'white'}, arrowprops=dict(arrowstyle='fancy'))
plt.show()
Binary file removed dist/figures/sgx-inference-comp-new.png
Binary file not shown.
Binary file modified dist/figures/sgx-inference-comp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 19 additions & 4 deletions dist/figures/sgx-inference-comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,36 @@
import matplotlib
from brokenaxes import brokenaxes
import numpy as np
import os
import linecache

matplotlib.rcParams['font.size'] = 14

labels = ['alex', 'dense161', 'res18', 'squeeze1.0', 'vgg16']
_nonsgx = [0.207, 0.3, 0.097, 0.075, 0.363]
_sgx = [15.225, 14.376, 6.604, 5.312, 31.873]
files = ['alexnet', 'densenet161', 'resnet18', 'squeezenet1_0', 'vgg16']

# _nonsgx = [0.233, 0.318, 0.063, 0.041, 0.546]
# _sgx = [14.737, 14.682, 6.860, 4.676, 29.520]
_nonsgx = []
_sgx = []

for file in files:
st = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 22).split('[')[3][:13])
ed = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 23).split('[')[3][:13])
_nonsgx.append((ed-st)/1000)
st = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 29).split('[')[3][:13])
ed = int(linecache.getline("../../eval_logs/%s.log.sorted" % file, 30).split('[')[3][:13])
_sgx.append((ed-st)/1000)
print(_nonsgx, _sgx)

# macs = [0.72, 7.82, 1.82, 0.83, 15.5] # G
# params = [61.1, 28.68, 11.69, 1.25, 138.36] # M

x = np.arange(len(labels)) # the label locations
width = 0.35 # the width of the bars

fig = plt.figure()
bax = brokenaxes(ylims=((0, .5), (2, 7), (14, 18), (31, 32)), hspace=.05)
bax = brokenaxes(ylims=((0, .6), (2.5, 7), (14, 18), (29, 31)), hspace=.05)

rects1 = bax.bar(x - width/2, _nonsgx, width, label='non-SGX', color='lightyellow', edgecolor='black', hatch='/')
rects2 = bax.bar(x + width/2, _sgx, width, label='SGX', color='lightgrey', edgecolor='black')
Expand All @@ -32,5 +48,4 @@


# ax.yaxis.grid(True)

plt.show()
52 changes: 0 additions & 52 deletions eval_logs/0-1.log

This file was deleted.

Loading

0 comments on commit 47f2138

Please sign in to comment.