-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add script to verify parameter checksums in parameters.json (#1251
) * feat: add script to verify parameter checksums in parameters.json This commit adds a script to verify that a `.params` file (and the corresponding `.vk file`) is part of the `parameters.json` and has the correct checksums. * fix: update typos and parameter count checking Co-authored-by: nemo <nemo@protocol.ai>
- Loading branch information
1 parent
8e7c5a0
commit feb0862
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/bin/sh | ||
|
||
# This script verifies that a given `.params` file (and the corresponding | ||
# `.vk` file) is part of `parameters.json` and has the correct digest. | ||
# | ||
# This script runs on POSIX compatible shells. You need to have standard | ||
# utilities (`basename`, `head`, `grep`) as well as have `jq` and `b2sum` | ||
# installed. | ||
# | ||
# The inputs are a `parameter.json` file and a `.params' file. | ||
|
||
if [ "${#}" -ne 2 ]; then | ||
echo "Verify that a given .params file (and the corresponding .vk file)" | ||
echo "is part of parameters.json and has the correct digest." | ||
echo "" | ||
echo "Usage: $(basename "${0}") parameters.json parameter-file.params" | ||
exit 1 | ||
fi | ||
|
||
if ! command -v b2sum >/dev/null 2>&1 | ||
then | ||
echo "ERROR: 'b2sum' needs to be installed." | ||
exit 1 | ||
fi | ||
|
||
if ! command -v jq >/dev/null 2>&1 | ||
then | ||
echo "ERROR: 'jq' needs to be installed." | ||
exit 1 | ||
fi | ||
|
||
PARAMS_JSON=${1} | ||
PARAMS_ID="${2%.*}" | ||
|
||
PARAMS_FILE="${PARAMS_ID}.params" | ||
VK_FILE="${PARAMS_ID}.vk" | ||
|
||
# Transforms the `parameters.json` into a string that consists of digest and | ||
# filename pairs. | ||
PARAMS_JSON_DATA=$(jq -r 'to_entries[] | "\(.value.digest) \(.key)"' "${PARAMS_JSON}") | ||
|
||
VK_HASH_SHORT=$(b2sum "${VK_FILE}"|head --bytes 32) | ||
if echo "${PARAMS_JSON_DATA}"|grep --silent "${VK_HASH_SHORT} ${VK_FILE}"; then | ||
echo "ok Correct digest of VK file was found in ${PARAMS_JSON}." | ||
else | ||
echo "not ok ERROR: Digest of VK file was *not* found/correct in ${PARAMS_JSON}." | ||
exit 1 | ||
fi | ||
|
||
PARAMS_HASH_SHORT=$(b2sum "${PARAMS_FILE}"|head --bytes 32) | ||
if echo "${PARAMS_JSON_DATA}"|grep --silent "${PARAMS_HASH_SHORT} ${PARAMS_FILE}"; then | ||
echo "ok Correct digest of params file was found in ${PARAMS_JSON}." | ||
else | ||
echo "not ok ERROR: Digest of params file was *not* found/correct in ${PARAMS_JSON}." | ||
exit 1 | ||
fi | ||
|
||
echo "# Verification successfully completed." |