5 PARAMS_DIR="$HOME/.zcash-params"
7 SPROUT_PKEY_NAME='sprout-proving.key'
8 SPROUT_VKEY_NAME='sprout-verifying.key'
9 SPROUT_URL="https://z.cash/downloads"
10 SPROUT_IPFS="/ipfs/QmZKKx7Xup7LiAtFRhYsE1M7waXcv9ir9eCECyXAFGxhEo"
12 SHA256CMD="$(command -v sha256sum || echo shasum)"
13 SHA256ARGS="$(command -v sha256sum >/dev/null || echo '-a 256')"
15 WGETCMD="$(command -v wget || echo '')"
16 IPFSCMD="$(command -v ipfs || echo '')"
18 # fetch methods can be disabled with ZC_DISABLE_SOMETHING=1
19 ZC_DISABLE_WGET="${ZC_DISABLE_WGET:-}"
20 ZC_DISABLE_IPFS="${ZC_DISABLE_IPFS:-}"
23 if [ -z "$WGETCMD" ] || ! [ -z "$ZC_DISABLE_WGET" ]; then
32 Retrieving (wget): $SPROUT_URL/$filename
37 --output-document="$dlname" \
39 --retry-connrefused --waitretry=3 --timeout=30 \
40 "$SPROUT_URL/$filename"
44 if [ -z "$IPFSCMD" ] || ! [ -z "$ZC_DISABLE_IPFS" ]; then
53 Retrieving (ipfs): $SPROUT_IPFS/$filename
56 ipfs get --output "$dlname" "$SPROUT_IPFS/$filename"
59 function fetch_failure {
62 Failed to fetch the Zcash zkSNARK parameters!
63 Try installing one of the following programs and make sure you're online:
72 function fetch_params {
75 local dlname="${output}.dl"
76 local expectedhash="$3"
80 for method in wget ipfs failure; do
81 if "fetch_$method" "$filename" "$dlname"; then
82 echo "Download successful!"
87 "$SHA256CMD" $SHA256ARGS -c <<EOF
91 # Check the exit code of the shasum command:
93 if [ $CHECKSUM_RESULT -eq 0 ]; then
94 mv -v "$dlname" "$output"
96 echo "Failed to verify parameter checksums!" >&2
102 # Use flock to prevent parallel execution.
104 local lockfile=/tmp/fetch_params.lock
106 eval "exec 200>/$lockfile"
113 function exit_locked_error {
114 echo "Only one instance of fetch-params.sh can be run at a time." >&2
120 lock fetch-params.sh \
124 Zcash - fetch-params.sh
126 This script will fetch the Zcash zkSNARK parameters and verify their
127 integrity with sha256sum.
129 If they already exist locally, it will exit now and do nothing else.
132 # Now create PARAMS_DIR and insert a README if necessary:
133 if ! [ -d "$PARAMS_DIR" ]
135 mkdir -p "$PARAMS_DIR"
136 README_PATH="$PARAMS_DIR/README"
137 cat >> "$README_PATH" <<EOF
138 This directory stores common Zcash zkSNARK parameters. Note that it is
139 distinct from the daemon's -datadir argument because the parameters are
140 large and may be shared across multiple distinct -datadir's such as when
141 setting up test networks.
144 # This may be the first time the user's run this script, so give
145 # them some info, especially about bandwidth usage:
147 The parameters are currently just under 911MB in size, so plan accordingly
148 for your bandwidth constraints. If the files are already present and
149 have the correct sha256sum, no networking is used.
151 Creating params directory. For details about this directory, see:
159 fetch_params "$SPROUT_PKEY_NAME" "$PARAMS_DIR/$SPROUT_PKEY_NAME" "8bc20a7f013b2b58970cddd2e7ea028975c88ae7ceb9259a5344a16bc2c0eef7"
160 fetch_params "$SPROUT_VKEY_NAME" "$PARAMS_DIR/$SPROUT_VKEY_NAME" "4bd498dae0aacfd8e98dc306338d017d9c08dd0918ead18172bd0aec2fc5df82"
164 rm -f /tmp/fetch_params.lock