solana: fix network handling in verify script (#1340)
This commit is contained in:
parent
ce87cb6a6e
commit
9b4ac93c0a
|
@ -2,28 +2,33 @@
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
usage="Usage:
|
function usage() {
|
||||||
$(basename "$0") <.so file> <account address> [-h] [-n network] -- Verify that the deployed on-chain bytecode matches the local object file
|
cat<<-EOF >&2
|
||||||
|
Usage:
|
||||||
|
$(basename "$0") [-h] [-n network] <.so file> <account address> -- Verify that the deployed on-chain bytecode matches the local object file
|
||||||
|
|
||||||
where:
|
where:
|
||||||
-h show this help text
|
-h show this help text
|
||||||
-n set the network (mainnet, testnet, devnet. defaults to \$NETWORK if set)"
|
-n set the network (mainnet, testnet, devnet. defaults to \$NETWORK if set)
|
||||||
|
EOF
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
network=$NETWORK
|
network=""
|
||||||
|
if [[ -n $NETWORK ]]; then
|
||||||
|
network=$NETWORK
|
||||||
|
fi
|
||||||
while getopts ':hn:' option; do
|
while getopts ':hn:' option; do
|
||||||
case "$option" in
|
case "$option" in
|
||||||
h) echo "$usage"
|
h) usage
|
||||||
exit
|
|
||||||
;;
|
;;
|
||||||
n) network=$OPTARG
|
n) network=$OPTARG
|
||||||
;;
|
;;
|
||||||
:) printf "missing argument for -%s\n" "$OPTARG" >&2
|
:) printf "missing argument for -%s\n" "$OPTARG" >&2
|
||||||
echo "$usage" >&2
|
usage
|
||||||
exit 1
|
|
||||||
;;
|
;;
|
||||||
\?) printf "illegal option: -%s\n" "$OPTARG" >&2
|
\?) printf "illegal option: -%s\n" "$OPTARG" >&2
|
||||||
echo "$usage" >&2
|
usage
|
||||||
exit 1
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
@ -34,19 +39,21 @@ case "$network" in
|
||||||
testnet) moniker="d";;
|
testnet) moniker="d";;
|
||||||
devnet) moniker="l";;
|
devnet) moniker="l";;
|
||||||
*) printf "Network not set. Specify with -n\n" >&2
|
*) printf "Network not set. Specify with -n\n" >&2
|
||||||
echo "$usage" >&2
|
usage
|
||||||
exit 1
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
[ $# -ne 2 ] && { echo "$usage" >&2; exit 1; }
|
[ $# -ne 2 ] && usage
|
||||||
obj_file=$1
|
obj_file=$1
|
||||||
sol_addr=$2
|
sol_addr=$2
|
||||||
|
|
||||||
|
account_json=$(mktemp)
|
||||||
|
account_dump=$(mktemp)
|
||||||
|
|
||||||
# Grab account content as JSON
|
# Grab account content as JSON
|
||||||
solana account $sol_addr -u $moniker --output-file /tmp/account.json --output json-compact >/dev/null
|
solana account "$sol_addr" -u $moniker --output-file "$account_json" --output json-compact >/dev/null
|
||||||
# decode the base64 account data to binary
|
# decode the base64 account data to binary
|
||||||
cat /tmp/account.json | jq '.account.data[0]' | sed s/\"//g | base64 -d > /tmp/account.dump
|
jq '.account.data[0]' "$account_json" | sed s/\"//g | base64 -d > "$account_dump"
|
||||||
|
|
||||||
# The first 37 bytes are irrelevant, the actual ELF object code starts after,
|
# The first 37 bytes are irrelevant, the actual ELF object code starts after,
|
||||||
# so we drop these bytes. Presumably those bytes correspond to an encoded rust
|
# so we drop these bytes. Presumably those bytes correspond to an encoded rust
|
||||||
|
@ -54,18 +61,18 @@ cat /tmp/account.json | jq '.account.data[0]' | sed s/\"//g | base64 -d > /tmp/a
|
||||||
# Set the block size to 37 bytes and skip the first block.
|
# Set the block size to 37 bytes and skip the first block.
|
||||||
dd bs=37 skip=1 if=/tmp/account.dump of=/tmp/bytecode.dump 2>/dev/null
|
dd bs=37 skip=1 if=/tmp/account.dump of=/tmp/bytecode.dump 2>/dev/null
|
||||||
|
|
||||||
hash1=`sha256sum /tmp/bytecode.dump | cut -f1 -d' '`
|
hash1=$(sha256sum /tmp/bytecode.dump | cut -f1 -d' ')
|
||||||
hash2=`sha256sum $obj_file | cut -f1 -d' '`
|
hash2=$(sha256sum "$obj_file" | cut -f1 -d' ')
|
||||||
|
|
||||||
echo "Deployed bytecode hash (on $network):"
|
echo "Deployed bytecode hash (on $network):"
|
||||||
echo $hash1
|
echo "$hash1"
|
||||||
echo "$obj_file hash:"
|
echo "$obj_file hash:"
|
||||||
echo $hash2
|
echo "$hash2"
|
||||||
|
|
||||||
if [ "$hash1" == "$hash2" ]; then
|
if [ "$hash1" == "$hash2" ]; then
|
||||||
printf "\033[0;32mSuccessfully verified\033[0m\n";
|
printf "\033[0;32mSuccessfully verified\033[0m\n";
|
||||||
exit 0;
|
exit 0;
|
||||||
else
|
else
|
||||||
printf "\033[0;31mFailed to verify\033[0m\n";
|
printf "\033[0;31mFailed to verify\033[0m\n" >&2;
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue