-
Notifications
You must be signed in to change notification settings - Fork 11
/
install.sh
executable file
·254 lines (225 loc) · 8.5 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#!/bin/bash
#***************
#* Environment *
#***************
# Account for starknet-devnet-rs (cargo run -- --seed 0)
export STARKNET_PRIVATE_KEY="0x71d7bb07b9a64f6f78ac4c816aff4da9"
STARKNET_ACCOUNT="~/devnet-ssc-acct.json"
STARKNET_RPC="http://localhost:5050"
#****************************************
#* Cairo challenge filenames and points *
#****************************************
declare -A cairo1_challenge
cairo1_challenge["challenge1"]=50
cairo1_challenge["challenge2"]=100
cairo1_challenge["challenge3"]=200
cairo1_challenge["challenge4"]=200
cairo1_challenge["challenge5"]=300
cairo1_challenge["challenge6"]=300
cairo1_challenge["challenge7"]=500
cairo1_challenge["challenge7_erc20"]=0
cairo1_challenge["challenge9"]=500
cairo1_challenge["challenge10"]=700
cairo1_challenge["challenge11"]=300
cairo1_challenge["challenge12"]=700
cairo1_challenge["challenge13"]=700
cairo1_challenge["challenge14"]=1000
cairo1_challenge["challenge14_coin"]=0
cairo1_challenge["challenge14_wallet"]=0
declare -A cairo0_challenge
cairo0_challenge["challenge8"]=1500
cairo0_challenge["challenge8_dex"]=0
cairo0_challenge["challenge8_erc20"]=0
cairo0_challenge["challenge8_erc223"]=0
#**************************
#* Constants (not change) *
#**************************
COMPILED_MAIN_FILE="target/dev/ssc_SecurityChallenge.contract_class.json"
COMPILED_NFT_FILE="target/dev/ssc_StarknetChallengeNft.contract_class.json"
#*************
#* Compile *
#*************
echo -e "\033[1;32mCompiling...\033[0m"
COMPILE_STATEMENT="scarb build"
echo ${COMPILE_STATEMENT}
eval ${COMPILE_STATEMENT}
if [ $? -ne 0 ]
then
echo -e "\n\033[0;41mFailed command:\033[0m\n"${COMPILE_STATEMENT}
exit
fi
#*****************************
#* Declare and deploy MAIN *
#*****************************
echo -e "\033[1;32mDeclaring main...\033[0m"
DECLARE_STATEMENT="starkli declare --watch --rpc ${STARKNET_RPC} --account ${STARKNET_ACCOUNT} ${COMPILED_MAIN_FILE} > install.tmp"
echo ${DECLARE_STATEMENT}
eval ${DECLARE_STATEMENT}
if [ $? -ne 0 ]
then
echo -e "\n\033[0;41mFailed command:\033[0m\n"${DECLARE_STATEMENT}
exit
fi
MAIN_CLASS_HASH=$(tail -n 1 install.tmp)
echo -e "\033[1;32mDeploying main...\033[0m"
DEPLOY_STATEMENT="starkli deploy --watch --rpc ${STARKNET_RPC} --account ${STARKNET_ACCOUNT} ${MAIN_CLASS_HASH} > install.tmp"
echo ${DEPLOY_STATEMENT}
eval ${DEPLOY_STATEMENT}
if [ $? -ne 0 ]
then
echo -e "\n\033[0;41mFailed command:\033[0m\n"${DEPLOY_STATEMENT}
exit
fi
MAIN_CONTRACT_ADDRESS=$(tail -n 1 install.tmp)
echo ${MAIN_CONTRACT_ADDRESS}
#**************************
#* Declare and deploy NFT *
#**************************
echo -e "\033[1;32mDeclaring nft...\033[0m"
DECLARE_STATEMENT="starkli declare --watch --rpc ${STARKNET_RPC} --account ${STARKNET_ACCOUNT} ${COMPILED_NFT_FILE} > install.tmp"
echo ${DECLARE_STATEMENT}
eval ${DECLARE_STATEMENT}
if [ $? -ne 0 ]
then
echo -e "\n\033[0;41mFailed command:\033[0m\n"${DECLARE_STATEMENT}
exit
fi
NFT_CLASS_HASH=$(tail -n 1 install.tmp)
echo -e "\033[1;32mDeploying nft...\033[0m"
DEPLOY_STATEMENT="starkli deploy --watch --rpc ${STARKNET_RPC} --account ${STARKNET_ACCOUNT} ${NFT_CLASS_HASH} > install.tmp"
echo ${DEPLOY_STATEMENT}
eval ${DEPLOY_STATEMENT}
if [ $? -ne 0 ]
then
echo -e "\n\033[0;41mFailed command:\033[0m\n"${DEPLOY_STATEMENT}
exit
fi
NFT_CONTRACT_ADDRESS=$(tail -n 1 install.tmp)
echo ${NFT_CONTRACT_ADDRESS}
#*********************
#* UPDATE global.jsx *
#*********************
echo -e "\033[1;32mUpdating global.jsx...\033[0m"
echo "const global = {}" > ./src/global.jsx
echo "global.MAIN_CONTRACT_ADDRESS = \"${MAIN_CONTRACT_ADDRESS}\";" >> ./src/global.jsx
echo "export default global" >> ./src/global.jsx
#***************************
#* SET NFT ADDRESS ON MAIN *
#***************************
echo -e "\033[1;32mSetting nft address on main...\033[0m"
INVOKE_STATEMENT="starkli invoke --watch --rpc ${STARKNET_RPC} --account ${STARKNET_ACCOUNT} ${MAIN_CONTRACT_ADDRESS} setNFTAddress ${NFT_CONTRACT_ADDRESS} > install.tmp"
echo ${INVOKE_STATEMENT}
eval ${INVOKE_STATEMENT}
if [ $? -ne 0 ]
then
echo -e "\n\033[0;41mFailed command:\033[0m\n"${INVOKE_STATEMENT}
exit
fi
#*********************
#* SET NFT OWNERSHIP *
#*********************
echo -e "\033[1;32mSetting nft ownership to main...\033[0m"
INVOKE_STATEMENT="starkli invoke --watch --rpc ${STARKNET_RPC} --account ${STARKNET_ACCOUNT} ${NFT_CONTRACT_ADDRESS} transferOwnership ${MAIN_CONTRACT_ADDRESS} > install.tmp"
echo ${INVOKE_STATEMENT}
eval ${INVOKE_STATEMENT}
if [ $? -ne 0 ]
then
echo -e "\n\033[0;41mFailed command:\033[0m\n"${INVOKE_STATEMENT}
exit
fi
#***********************************
#* Declare and register challenges *
#***********************************
echo -e "\033[1;32mDeclaring and registering challenges...\033[0m"
for challenge_name in "${!cairo1_challenge[@]}"
do
echo -e "\033[1;32mDeclaring challenge $challenge_name...\033[0m"
MOD_NAME=`grep "mod " src/assets/$challenge_name.cairo | awk '{print $2}' | head -1`
FILE_NAME="target/dev/ssc_${MOD_NAME}.contract_class.json"
DECLARE_STATEMENT="starkli declare --watch --rpc ${STARKNET_RPC} --account ${STARKNET_ACCOUNT} ${FILE_NAME} > install.tmp"
echo ${DECLARE_STATEMENT}
eval ${DECLARE_STATEMENT}
if [ $? -ne 0 ]
then
echo -e "\n\033[0;41mFailed command:\033[0m\n"${DECLARE_STATEMENT}
exit
fi
CHALLENGE_CLASS_HASH=$(tail -n 1 install.tmp)
POINTS=${cairo1_challenge[$challenge_name]}
if [ ${POINTS} -gt 0 ]
then
echo -e "\033[1;32mRegistering challenge $challenge_name...\033[0m"
CHALLENGE_NUMBER=$(echo $challenge_name | grep -o -E '[0-9]+' | head -1)
INVOKE_STATEMENT="starkli invoke --watch --rpc ${STARKNET_RPC} --account ${STARKNET_ACCOUNT} ${MAIN_CONTRACT_ADDRESS} updateChallenge ${CHALLENGE_NUMBER} ${CHALLENGE_CLASS_HASH} ${POINTS} > install.tmp"
echo ${INVOKE_STATEMENT}
eval ${INVOKE_STATEMENT}
if [ $? -ne 0 ]
then
echo -e "\n\033[0;41mFailed command:\033[0m\n"${INVOKE_STATEMENT}
exit
fi
else
echo -e "\033[1;32mAuxiliary challenge $challenge_name not registered...\033[0m"
fi
done
#*****************************
#* Optional cairo0 challenges *
#*****************************
read -p "Do you want to install cairo0 challenges? (require access to starknet-compile-deprecated) (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
rm install.tmp
echo -e "\033[1;32mDone.\033[0m"
exit
fi
#*****************************
#* COMPILE cairo0 challenges *
#*****************************
echo -e "\033[1;32mCompiling cairo0 challenges...\033[0m"
for challenge_name in "${!cairo0_challenge[@]}"
do
echo -e "\033[1;32mCompiling cairo0 challenge ${challenge_name}...\033[0m"
MOD_NAME=`grep "mod " src/assets/$challenge_name.cairo | awk '{print $2}'`
FILE_NAME="target/dev/ssc_${MOD_NAME}.contract_class.json"
COMPILE_STATEMENT="starknet-compile-deprecated ./src/assets/$challenge_name.cairo --output target/dev/$challenge_name.cairo_compiled.json"
echo ${COMPILE_STATEMENT}
eval ${COMPILE_STATEMENT}
if [ $? -ne 0 ]
then
echo -e "\n\033[0;41mFailed command:\033[0m\n"${COMPILE_STATEMENT}
exit
fi
done
for challenge_name in "${!cairo0_challenge[@]}"
do
echo -e "\033[1;32mDeclaring and registering challenge $challenge_name...\033[0m"
FILE_NAME="target/dev/$challenge_name.cairo_compiled.json"
DECLARE_STATEMENT="starkli declare --watch --rpc ${STARKNET_RPC} --account ${STARKNET_ACCOUNT} ${FILE_NAME} > install.tmp"
echo ${DECLARE_STATEMENT}
eval ${DECLARE_STATEMENT}
if [ $? -ne 0 ]
then
echo -e "\n\033[0;41mFailed command:\033[0m\n"${DECLARE_STATEMENT}
exit
fi
CHALLENGE_CLASS_HASH=$(tail -n 1 install.tmp)
POINTS=${cairo0_challenge[$challenge_name]}
if [ ${POINTS} -gt 0 ]
then
echo -e "\033[1;32mRegistering cairo0 challenge $challenge_name...\033[0m"
CHALLENGE_NUMBER=$(echo $challenge_name | grep -o -E '[0-9]+' | head -1)
INVOKE_STATEMENT="starkli invoke --watch --rpc ${STARKNET_RPC} --account ${STARKNET_ACCOUNT} ${MAIN_CONTRACT_ADDRESS} updateChallenge ${CHALLENGE_NUMBER} ${POINTS} ${CHALLENGE_CLASS_HASH} > install.tmp"
echo ${INVOKE_STATEMENT}
eval ${INVOKE_STATEMENT}
if [ $? -ne 0 ]
then
echo -e "\n\033[0;41mFailed command:\033[0m\n"${INVOKE_STATEMENT}
exit
fi
else
echo -e "\033[1;32mAuxiliary challenge $challenge_name not registered...\033[0m"
fi
done
rm install.tmp
echo -e "\033[1;32mDone.\033[0m"