]> Git Repo - VerusCoin.git/blobdiff - zcutil/fetch-params.sh
Auto merge of #1575 - arcalinea:document-rpc-security, r=daira
[VerusCoin.git] / zcutil / fetch-params.sh
index 6112c62465db49d1cf93fb0b0f0d4287c6fac0ac..bf6a123f1b284055eade8554b75a86f9d63b0a36 100755 (executable)
@@ -4,48 +4,87 @@ set -eu
 
 PARAMS_DIR="$HOME/.zcash-params"
 
-REGTEST_PKEY_NAME='zc-testnet-public-alpha-proving.key'
-REGTEST_VKEY_NAME='zc-testnet-public-alpha-verification.key'
-REGTEST_PKEY_URL="https://zca.sh/downloads/$REGTEST_PKEY_NAME"
-REGTEST_VKEY_URL="https://zca.sh/downloads/$REGTEST_VKEY_NAME"
-REGTEST_DIR="$PARAMS_DIR/regtest"
+BETA2_PKEY_NAME='beta2-proving.key'
+BETA2_VKEY_NAME='beta2-verifying.key'
+BETA2_PKEY_URL="https://z.cash/downloads/$BETA2_PKEY_NAME"
+BETA2_VKEY_URL="https://z.cash/downloads/$BETA2_VKEY_NAME"
 
-
-# Note: This assumes cwd is set appropriately!
 function fetch_params {
     local url="$1"
-    local filename="$(echo "$url" | sed 's,^.*/,,')"
-    if ! [ -f "$filename" ]
+    local output="$2"
+    local dlname="${output}.dl"
+    local expectedhash="$3"
+
+    if ! [ -f "$output" ]
     then
         echo "Retrieving: $url"
-        wget --progress=dot:giga "$url"
+        wget \
+            --progress=dot:giga \
+            --output-document="$dlname" \
+            --continue \
+            --retry-connrefused --waitretry=3 --timeout=30 \
+            "$url"
+
+        shasum -a 256 --check <<EOF
+$expectedhash  $dlname
+EOF
+
+        # Check the exit code of the shasum command:
+        CHECKSUM_RESULT=$?
+        if [ $CHECKSUM_RESULT -eq 0 ]; then
+            mv -v "$dlname" "$output"
+        else
+           echo "Failed to verify parameter checksums!"
+           exit 1
+        fi
     fi
 }
 
-cat <<EOF
-zcash - fetch-params.sh
+# Use flock to prevent parallel execution.
+function lock() {
+    local lockfile=/tmp/fetch_params.lock
+    # create lock file
+    eval "exec 200>/$lockfile"
+    # acquire the lock
+    flock -n 200 \
+        && return 0 \
+        || return 1
+}
+
+function exit_locked_error {
+    echo "Only one instance of fetch-params.sh can be run at a time." >&2
+    exit 1
+}
+
+function main() {
+
+    lock fetch-params.sh \
+    || exit_locked_error
+
+    cat <<EOF
+Zcash - fetch-params.sh
 
 EOF
 
-# Now create PARAMS_DIR and insert a README if necessary:
-if ! [ -d "$PARAMS_DIR" ]
-then
-    mkdir -p "$PARAMS_DIR"
-    README_PATH="$PARAMS_DIR/README"
-    cat >> "$README_PATH" <<EOF
-This directory stores common zcash zkSNARK parameters. Note that is is
+    # Now create PARAMS_DIR and insert a README if necessary:
+    if ! [ -d "$PARAMS_DIR" ]
+    then
+        mkdir -p "$PARAMS_DIR"
+        README_PATH="$PARAMS_DIR/README"
+        cat >> "$README_PATH" <<EOF
+This directory stores common Zcash zkSNARK parameters. Note that it is
 distinct from the daemon's -datadir argument because the parameters are
 large and may be shared across multiple distinct -datadir's such as when
 setting up test networks.
 EOF
 
-    # This may be the first time the user's run this script, so give
-    # them some info, especially about bandwidth usage:
-    cat <<EOF
+        # This may be the first time the user's run this script, so give
+        # them some info, especially about bandwidth usage:
+        cat <<EOF
 This script will fetch the Zcash zkSNARK parameters and verify their
 integrity with sha256sum.
 
-The parameters currently are about 2GiB in size, so plan accordingly
+The parameters are currently just under 911MB in size, so plan accordingly
 for your bandwidth constraints. If the files are already present and
 have the correct sha256sum, no networking is used.
 
@@ -53,17 +92,13 @@ Creating params directory. For details about this directory, see:
 $README_PATH
 
 EOF
-fi
+    fi
 
-mkdir -p "$REGTEST_DIR"
-cd "$REGTEST_DIR"
+    cd "$PARAMS_DIR"
 
-fetch_params "$REGTEST_PKEY_URL"
-fetch_params "$REGTEST_VKEY_URL"
+    fetch_params "$BETA2_PKEY_URL" "$PARAMS_DIR/$BETA2_PKEY_NAME" "cca9887becf803c8ca801bc9da8fcba4f5fb3ba13af9d17e8603021a150cb4b7"
+    fetch_params "$BETA2_VKEY_URL" "$PARAMS_DIR/$BETA2_VKEY_NAME" "2faffd2a5e2e67276c3471c48068a0c16f62286d2e4622a733d7cd1f82ffa860"
+}
 
-# Now verify their hashes:
-echo 'Verifying parameter file integrity via sha256sum...'
-sha256sum --check - <<EOF
-7844a96933979158886a5b69fb163f49de76120fa1dcfc33b16c83c134e61817  $REGTEST_PKEY_NAME
-6902fd687bface72e572a7cda57f6da5a0c606c7b9769f30becd255e57924f41  $REGTEST_VKEY_NAME
-EOF
+main
+exit 0
This page took 0.027118 seconds and 4 git commands to generate.