Skip to content

Commit cfb6e46

Browse files
njeanssbellem
authored andcommitted
working simple demo
1 parent 1f58ab2 commit cfb6e46

File tree

12 files changed

+237
-67
lines changed

12 files changed

+237
-67
lines changed

app/app.go

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ import (
8585
tmlog "github.com/tendermint/tendermint/libs/log"
8686
tmos "github.com/tendermint/tendermint/libs/os"
8787
dbm "github.com/tendermint/tm-db"
88-
88+
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
89+
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
8990
// unnamed import of statik for swagger UI support
9091
_ "github.com/scrtlabs/SecretNetwork/client/docs/statik"
9192
)
@@ -180,10 +181,52 @@ func (app *SecretNetworkApp) RegisterTendermintService(clientCtx client.Context)
180181

181182
func (app *SecretNetworkApp) DeliverTx(req abci.RequestDeliverTx) (res abci.ResponseDeliverTx) {
182183
fmt.Printf("nerla app/app.go DeliverTx tx %x\n", req.Tx)
183-
if compute.GetFakeDeliver() {
184-
fmt.Printf("nerla app/app.go DeliverTx FAKE_DELIVER is true\n", )
185-
return abci.ResponseDeliverTx{Code: abci.CodeTypeOK}
184+
dTx, err := app.GetTxConfig().TxDecoder()(req.Tx)
185+
if err != nil {
186+
fmt.Println( "nerla app/app.go error TxDecoder")
187+
panic(err)
186188
}
189+
msgs := dTx.GetMsgs()
190+
for _, m := range msgs {
191+
mSecret := m.(compute.SecretNetworkMsg)
192+
if mSecret.Type() == "call_delivertx" || mSecret.Type() == "snapshot" {
193+
fmt.Printf("nerla app/app.go m.Type() %s calling Simulate\n", mSecret.Type())
194+
ctx := app.BaseApp.GetContextForDeliverTx(req.Tx)
195+
sigTx, ok := dTx.(authsigning.SigVerifiableTx)
196+
if !ok {
197+
fmt.Println("nerla app/app.go invalid transaction type")
198+
panic(sdkerrors.ErrTxDecode)
199+
}
200+
201+
sigs, err := sigTx.GetSignaturesV2()
202+
if err != nil {
203+
fmt.Println("nerla app/app.go GetSignaturesV2 err")
204+
panic(err)
205+
}
206+
signerAddrs := sigTx.GetSigners()
207+
208+
for i, sig := range sigs {
209+
addr := signerAddrs[i]
210+
acc := app.AppKeepers.AccountKeeper.GetAccount(ctx, addr)
211+
fmt.Printf("nerla app/app.go before addr %s acc.seq %d sig.seq %d\n", addr.String(), acc.GetSequence(), sig.Sequence+1)
212+
if err := acc.SetSequence(sig.Sequence+1); err != nil {
213+
panic(err)
214+
}
215+
app.AppKeepers.AccountKeeper.SetAccount(ctx, acc)
216+
acc2 := app.AppKeepers.AccountKeeper.GetAccount(ctx, addr)
217+
fmt.Printf("nerla app/app.go after addr %s acc.seq %d\n", addr.String(), acc2.GetSequence())
218+
}
219+
220+
gasInfo, resp, err := app.BaseApp.Simulate(req.Tx)
221+
fmt.Printf("nerla app/app.go Simulate gasInfo %d res %v err %v\n", gasInfo, resp, err)
222+
return abci.ResponseDeliverTx{Code: abci.CodeTypeOK}
223+
}
224+
}
225+
226+
// if compute.GetFakeDeliver() {
227+
// fmt.Printf("nerla app/app.go DeliverTx FAKE_DELIVER is true\n", )
228+
// return abci.ResponseDeliverTx{Code: abci.CodeTypeOK}
229+
// }
187230
resp := app.BaseApp.DeliverTx(req)
188231
fmt.Printf("nerla app/app.go DeliverTx res %v\n", resp)
189232
return resp

hacking/docker-compose.yml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "3.9"
22
services:
33
localsecret-1:
4-
image: devlocalsecret
4+
image: devlocalsecret-1
55
build:
66
context: ..
77
dockerfile: hacking/Dockerfile
@@ -19,24 +19,24 @@ services:
1919
# ports are only here in case interaction
2020
# between localhost and container is desired
2121
ports:
22-
- "26657:26657"
23-
- "26656:26656"
24-
- "9090:9090"
25-
- "9091:9091"
26-
- "1317:1317"
22+
- "26658:26657"
23+
- "26659:26656"
24+
- "9092:9090"
25+
- "9093:9091"
26+
- "1318:1317"
2727
# faucet
28-
- "5000:5000"
28+
- "5001:5000"
2929
environment:
3030
LOG_LEVEL: "TRACE"
3131
SECRET_NODE_TYPE: BOOTSTRAP
3232
# NOTE: mount source code that may be changed and rebuilt in a container
3333
volumes:
34-
# - ../go-cosmwasm/src:/go/src/github.com/enigmampc/SecretNetwork/go-cosmwasm/src
34+
# - ../go-cosmwasm/src:/go/src/github.com/enigmampc/SecretNetwork/go-cosmwasm/src
3535
- ./secretd-1:/root/.secretd/
3636
- ./scripts/:/root/scripts
3737

3838
localsecret-2:
39-
image: devlocalsecret
39+
image: devlocalsecret-1
4040
build:
4141
context: ..
4242
dockerfile: hacking/Dockerfile
@@ -53,25 +53,25 @@ services:
5353
# ports are only here in case interaction
5454
# between localhost and container is desired
5555
ports:
56-
- "36657:26657"
57-
- "36656:26656"
58-
- "9391:9091"
59-
- "9390:9090"
60-
- "3317:1317"
56+
- "36658:26657"
57+
- "36659:26656"
58+
- "9392:9091"
59+
- "9393:9090"
60+
- "3318:1317"
6161
# faucet
62-
- "5300:5000"
62+
- "5400:5000"
6363
environment:
6464
CHAINID: "secretdev-1"
6565
LOG_LEVEL: "TRACE"
6666
SECRET_NODE_TYPE: NODE
6767
DUMMY_STORE: "true"
6868
# NOTE: mount source code that may be changed and rebuilt in a container
6969
volumes:
70-
# - ../go-cosmwasm/src:/go/src/github.com/enigmampc/SecretNetwork/go-cosmwasm/src
71-
# - ../go-cosmwasm/api:/go/src/github.com/enigmampc/SecretNetwork/go-cosmwasm/api
72-
# - ../app:/go/src/github.com/enigmampc/SecretNetwork/app
73-
# - ../proto:/go/src/github.com/enigmampc/SecretNetwork/proto
74-
# - ../x:/go/src/github.com/enigmampc/SecretNetwork/x
70+
# - ../go-cosmwasm/src:/go/src/github.com/enigmampc/SecretNetwork/go-cosmwasm/src
71+
# - ../go-cosmwasm/api:/go/src/github.com/enigmampc/SecretNetwork/go-cosmwasm/api
72+
# - ../app:/go/src/github.com/enigmampc/SecretNetwork/app
73+
# - ../proto:/go/src/github.com/enigmampc/SecretNetwork/proto
74+
# - ../x:/go/src/github.com/enigmampc/SecretNetwork/x
7575
- ./scripts/:/root/scripts
7676
- ./secretd-2:/root/.secretd/
7777
- ./genesis:/tmp/genesis

hacking/rebuild_node.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
2-
set +x
3-
docker-compose exec -d localsecret-2 /bin/bash -c "./scripts/rebuild.sh &> /root/out"
2+
set -x
3+
# docker-compose start localsecret-1
4+
docker-compose exec -d localsecret-2 /bin/bash -c "./scripts/rebuild2.sh &> /root/out"
45
sleep 5
56

67
#waiting to build secretd and start
@@ -13,13 +14,12 @@ do
1314
sleep 5
1415
done
1516

16-
logs=$(docker-compose exec localsecret-2 cat /root/out )
17-
while [[ "$logs" != *"finalizing commit of block"* ]]
18-
do
19-
logs=$(docker-compose exec localsecret-2 cat /root/out )
20-
./logs.sh
21-
echo "Waiting for blocks to be produced..."
22-
sleep 5
23-
done
24-
17+
# logs=$(docker-compose exec localsecret-2 cat /root/out )
18+
# while [[ "$logs" != *"finalizing commit of block"* ]]
19+
# do
20+
# logs=$(docker-compose exec localsecret-2 cat /root/out )
21+
# ./logs.sh
22+
# echo "Waiting for blocks to be produced..."
23+
# sleep 5
24+
# done
2525
./logs.sh

hacking/run.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
set -x
3+
#docker-compose stop localsecret-1
4+
5+
docker-compose exec localsecret-2 ./scripts/test_simple.sh
6+
# docker-compose exec localsecret-2 cp -rf /root/hist_data /root/.secretd/data/
7+
# ./rebuild_node.sh &
8+
# docker-compose start localsecret-1

hacking/scripts/backup.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
set -x
3+
SECRETD=secretd
4+
ADV='secret1fc3fzy78ttp0lwuujw7e52rhspxn8uj52zfyne'
5+
6+
start_secretd() {
7+
dev=$($SECRETD q account $ADV)
8+
echo "$?"
9+
}
10+
11+
query_tx_res() {
12+
dev=$($SECRETD q tx $1)
13+
echo "$?"
14+
}
15+
16+
pkill -f "secretd start --rpc.laddr tcp://0.0.0.0:26657"
17+
sleep_time=3
18+
cnt=0
19+
cnt_max=5
20+
while true; do
21+
((cnt=cnt+1))
22+
sleep $sleep_time
23+
if [ $(start_secretd) != 0 ]; then break; fi
24+
if [ $((cnt%cnt_max)) == 0 ]; then (pkill -f $SECRETD); fi
25+
done
26+
27+
mkdir -p /root/hist_data
28+
mkdir -p /root/hist_data2
29+
files=$(ls -1 -a /root/.secretd)
30+
cp -r /root/.secretd/ /root/hist_data4
31+
cp -r /root/.secretd/* /root/hist_data2
32+
33+
RUST_BACKTRACE=1 secretd start --rpc.laddr "tcp://0.0.0.0:26657" &
34+
sleep infinity

hacking/scripts/node_init.sh

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ set -euo pipefail
99
set -x
1010
export RPC_URL="localsecret-1:26657"
1111
export CHAINID="secretdev-1"
12+
# curr_dir=$(pwd)
13+
# cd /go/src/github.com/enigmampc/SecretNetwork/
14+
# # make build_cli
15+
# ls
16+
# make build_local_no_rust
17+
# cp secretd /usr/bin/secretd
18+
# chmod +x secretd
19+
# cd $curr_dir
1220
file=/root/.secretd/config/started.txt
1321
if [ ! -e "$file" ]
1422
then
@@ -53,7 +61,7 @@ then
5361

5462
secretd parse /opt/secret/.sgx_secrets/attestation_cert.der
5563
ls /opt/secret/.sgx_secrets/attestation_cert.der
56-
secretd tx register auth /opt/secret/.sgx_secrets/attestation_cert.der -y --from b --broadcast-mode block --gas-prices 0.25uscrt > out
64+
secretd tx register auth /opt/secret/.sgx_secrets/attestation_cert.der -y --from b --broadcast-mode sync --gas-prices 0.25uscrt > out
5765
cat out
5866
tx_hash="$(cat out | jq -r '.txhash')"
5967

@@ -71,7 +79,7 @@ then
7179
cp /tmp/genesis/genesis.json /root/.secretd/config/genesis.json
7280

7381
secretd validate-genesis
74-
RUST_BACKTRACE=1 secretd start --rpc.laddr tcp://0.0.0.0:26657 &> output &
82+
RUST_BACKTRACE=1 secretd start --rpc.laddr tcp://0.0.0.0:26657 &> /root/out &
7583
PID=$!
7684
echo "waiting for state sync to end.."
7785
sleep 5
@@ -82,27 +90,25 @@ then
8290
sleep 5
8391
state_sync=$(secretd status | jq .SyncInfo.catching_up)
8492
echo "state_sync $state_sync"
85-
done
86-
87-
kill $PID
88-
cat output
89-
echo "joininng as validator now"
90-
secretd tx staking create-validator -y \
91-
--amount=100000000uscrt \
92-
--pubkey=$(secretd tendermint show-validator) \
93-
--details="To infinity and beyond!" \
94-
--commission-rate="0.10" \
95-
--commission-max-rate="0.20" \
96-
--commission-max-change-rate="0.01" \
97-
--min-self-delegation="1" \
98-
--moniker="hack0r" \
99-
--broadcast-mode block \
100-
--from=b > out2
101-
tx_hash="$(cat out2 | jq -r '.txhash')"
102-
sleep 10
103-
secretd q tx "$tx_hash" | jq .
104-
secretd q staking validators | grep moniker | jq .
105-
secretd q staking validators | grep moniker
93+
done
94+
cat /root/out
95+
# echo "joininng as validator now"
96+
# secretd tx staking create-validator -y \
97+
# --amount=100000000uscrt \
98+
# --pubkey=$(secretd tendermint show-validator) \
99+
# --details="To infinity and beyond!" \
100+
# --commission-rate="0.10" \
101+
# --commission-max-rate="0.20" \
102+
# --commission-max-change-rate="0.01" \
103+
# --min-self-delegation="1" \
104+
# --moniker="hack0r" \
105+
# --broadcast-mode sync \
106+
# --from=b > out2
107+
# tx_hash="$(cat out2 | jq -r '.txhash')"
108+
# sleep 10
109+
# secretd q tx "$tx_hash" | jq .
110+
# secretd q staking validators | grep moniker | jq .
111+
# secretd q staking validators | grep moniker
106112
echo "started" > $file
107113
secretd config node "http://localhost:26657"
108114
# hack to change permission of data after starting node
@@ -112,6 +118,7 @@ else
112118
curr_dir=$(pwd)
113119
cd /go/src/github.com/enigmampc/SecretNetwork/
114120
# make build_cli
121+
ls
115122
make build_local_no_rust
116123
cp secretd /usr/bin/secretd
117124
chmod +x secretd
@@ -125,4 +132,4 @@ else
125132
fi
126133
# sed -i 's/pex = true/pex = false/g' ~/.secretd/config/config.toml
127134
# echo "Set pex = false"
128-
# RUST_BACKTRACE=1 secretd start --rpc.laddr tcp://0.0.0.0:26657
135+
# RUST_BACKTRACE=1 secretd start --rpc.laddr tcp://0.0.0.0:26657

hacking/scripts/rebuild2.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
set -x
3+
pkill -f "secretd start --rpc.laddr tcp://0.0.0.0:26657"
4+
5+
sleep 3
6+
rm -rf /root/.secretd/.*
7+
rm -rf /root/.secretd/*
8+
cp -rf /root/hist_data/. /root/.secretd/
9+
10+
cd /go/src/github.com/enigmampc/SecretNetwork/
11+
rm secretd
12+
set -e
13+
CGO_LDFLAGS=$CGO_LDFLAGS DB_BACKEND=goleveldb MITIGATION_CVE_2020_0551=LOAD VERSION=$VERSION FEATURES=$FEATURES SGX_MODE=$SGX_MODE make build_local_no_rust
14+
chmod +x secretd
15+
cp secretd /usr/bin/secretd
16+
cd /root
17+
18+
RUST_BACKTRACE=1 secretd start --rpc.laddr "tcp://0.0.0.0:26657" &
19+
sleep infinity

hacking/scripts/setup_simple.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
set -x
3+
set -e
4+
secretd query register secret-network-params
5+
UNIQUE_LABEL=$(date '+%Y-%m-%d-%H:%M:%S')
6+
ADDR=$(secretd keys show --address b)
7+
VICTIM_ADDR=$(secretd keys show --address c)
8+
echo "Storing contract"
9+
STORE_TX=$(secretd tx compute store /root/contract-simple/contract.wasm --from b -y --broadcast-mode sync --gas=5000000)
10+
eval STORE_TX_HASH=$(echo $STORE_TX | jq .txhash )
11+
eval CODE_ID=$(secretd q tx $STORE_TX_HASH | jq '.logs[].events[].attributes[] | select(.key=="code_id") | .value ')
12+
while [ "$CODE_ID" == "" ]; do
13+
echo -e "\twaiting for secred tx compute store to be included"
14+
sleep 2
15+
eval CODE_ID=$(secretd q tx $STORE_TX_HASH | jq '.logs[].events[].attributes[] | select(.key=="code_id") | .value ')
16+
done
17+
echo "Instantiating contract"
18+
INIT_TX=$(secretd tx compute instantiate $CODE_ID "{\"nop\":{}}" --from b --label $UNIQUE_LABEL -y --broadcast-mode block )
19+
eval INIT_TX_HASH=$(echo $INIT_TX | jq .txhash )
20+
eval CONTRACT_ADDRESS=$(secretd q tx $INIT_TX_HASH | jq '.logs[].events[] | select(.type=="instantiate") | .attributes[] | select(.key=="contract_address") | .value ')
21+
while [ "$CONTRACT_ADDRESS" == "" ]; do
22+
echo -e "\t waiting for secred tx compute instatiate to be included"
23+
sleep 2
24+
eval CONTRACT_ADDRESS=$(secretd q tx $INIT_TX_HASH | jq '.logs[].events[] | select(.type=="instantiate") | .attributes[] | select(.key=="contract_address") | .value ')
25+
done
26+
eval CODE_HASH=$(secretd q compute contract-hash $CONTRACT_ADDRESS)
27+
CODE_HASH=${CODE_HASH:2} #strip of 0x.. from CODE_HASH hex string
28+
29+
echo "Generating Victim tx"
30+
secretd tx compute execute $CONTRACT_ADDRESS --generate-only "{\"store1\":{\"message\":\"hello2\"}}" --from $VICTIM_ADDR --enclave-key io-master-cert.der --code-hash $CODE_HASH --label $UNIQUE_LABEL -y --broadcast-mode sync > tx_victim.json
31+
echo "Signing Victim tx"
32+
secretd tx sign tx_victim.json --chain-id secretdev-1 --from $VICTIM_ADDR > tx_victim_sign.json
33+
34+
cp -rf /root/.secretd/data/ /root/hist_data
35+
echo $CONTRACT_ADDRESS > CONTRACT_ADDRESS
36+
exit 0
37+
38+

hacking/scripts/test_simple.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
set -x
3+
ADDR=$(secretd keys show --address b)
4+
CONTRACT_ADDRESS=$(cat CONTRACT_ADDRESS)
5+
secretd tx compute delivertx tx_victim_sign.json --from $ADDR -y
6+
secretd q compute query $CONTRACT_ADDRESS "{\"store1_q\":{}}"
7+
8+
eval STORE_1_VALUE=$(secretd q compute query $CONTRACT_ADDRESS "{\"store1_q\":{}}" )
9+
if [ "$STORE_1_VALUE" != "hello2" ]; then
10+
echo "ERROR: value in store_1 \"$STORE_1_VALUE\" != \"hello2\""
11+
exit 1
12+
fi
13+
echo "SUCCESS: value in store_1 \"$STORE_1_VALUE\" == \"hello2\""

hacking/setup_simple.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
docker-compose exec localsecret-2 ./scripts/setup_simple.sh
4+
docker-compose stop localsecret-1
5+
docker-compose exec -d localsecret-2 /bin/bash -c "./scripts/backup.sh &> /root/out"

0 commit comments

Comments
 (0)