-
Notifications
You must be signed in to change notification settings - Fork 77
/
init.sh
executable file
·131 lines (114 loc) · 3.73 KB
/
init.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
#!/bin/bash
# usage:
# env ES_NODE_STORAGE_MINER=<miner> ./init.sh
executable="./build/bin/es-node"
echo "========== build info =================="
$executable --version
echo "========================================"
# ZK prover implementation, 1: snarkjs, 2: go-rapidsnark.
zkp_impl=1
# ZK prover mode, 1: one proof per sample, 2: one proof for multiple samples.
# Note: currently only zk prover mode 2 is supported
zkp_mode=2
data_dir="./es-data"
remaining_args=""
shards="--shard_index 0"
use_miner=1
while [ $# -gt 0 ]; do
if [[ $1 == --miner.zk-prover-impl ]]; then
zkp_impl=$2
shift 2
elif [[ $1 == --miner.zk-prover-mode ]]; then
zkp_mode=$2
shift 2
elif [[ $1 == --datadir ]]; then
data_dir=$2
shift 2
elif [[ $1 == --shard_index ]]; then
shards=""
remaining_args="$remaining_args $1"
shift
elif [[ $1 == --encoding_type=0 ]]; then # from init-rpc.sh
use_miner=0
remaining_args="$remaining_args $1"
shift
else
remaining_args="$remaining_args $1"
shift
fi
done
if [ -n "$zkp_mode" ] && [ "$zkp_mode" != 1 ] && [ "$zkp_mode" != 2 ]; then
echo "Error: zk prover mode can only be 1 or 2."
exit 1
fi
if [ $use_miner = 1 ]; then
# download zkey if not yet
zkey_name="blob_poseidon2.zkey"
zkey_size=560301223
zkey_url="https://es-node-zkey.s3.us-west-1.amazonaws.com/blob_poseidon2_testnet1.zkey"
if [ "$zkp_mode" = 1 ]; then
zkey_name="blob_poseidon.zkey"
zkey_size=280151245
zkey_url="https://drive.usercontent.google.com/download?id=1ZLfhYeCXMnbk6wUiBADRAn1mZ8MI_zg-&export=download&confirm=t&uuid=16ddcd58-2498-4d65-8931-934df3d0065c"
fi
zkey_file="./build/bin/snark_lib/zkey/$zkey_name"
if [ ! -e ${zkey_file} ] || [ $(wc -c < ${zkey_file}) -ne ${zkey_size} ]; then
echo "Start downloading ${zkey_file}..."
curl $zkey_url -o ${zkey_file}
if [ ! -e ${zkey_file} ]; then
echo "Error: The zkey file was not downloaded. Please try again."
exit 1
fi
if [ $(wc -c < ${zkey_file}) -ne ${zkey_size} ]; then
echo "Error: The zkey file was not downloaded correctly. You can check the file content for more information."
exit 1
fi
else
echo "√ ${zkey_file} already exists."
fi
if [ -n "$zkp_impl" ] && [ "$zkp_impl" != 1 ] && [ "$zkp_impl" != 2 ]; then
echo "Error: miner.zk-prover-impl can only be 1 or 2"
exit 1
fi
if [ "$zkp_impl" = 1 ]; then
if ! [ -x "$(command -v node)" ]; then
echo 'Error: Node.js is not installed.'
exit 1
fi
# check node js version
node_version=$(node -v)
major_version=$(echo $node_version | cut -d'v' -f2 | cut -d'.' -f1)
if [ "$major_version" -lt 16 ]; then
echo "Error: Node.js version is too old: $node_version; must be 16 and above."
exit 1
else
echo "√ Node.js version is compatible."
fi
# install snarkjs if not
if ! [ "$(command -v snarkjs)" ]; then
echo "snarkjs not found, start installing..."
snarkjs_install=$(npm install -g snarkjs 2>&1)
if [ $? -eq 0 ]; then
echo "√ snarkjs installed successfully."
else
echo "Error: snarkjs install failed with the following error:"
echo "$snarkjs_install"
exit 1
fi
else
echo "√ snarkjs is already installed."
fi
fi
fi
es_node_init="$executable init $shards \
--datadir $data_dir \
--l1.rpc http://88.99.30.186:8545 \
--storage.l1contract 0x804C520d3c084C805E37A35E90057Ac32831F96f \
$remaining_args"
# es-node will skip init if data files already exist
if $es_node_init ; then
echo "√ Initialized data files successfully."
else
echo "Error: failed to initialize data files."
exit 1
fi