verify 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/bash
  2. set -euo pipefail
  3. usage="Usage:
  4. $(basename "$0") [-h] [-n network] <.wasm file> <code id> -- Verify that the deployed on-chain bytecode matches the local object file
  5. where:
  6. -h show this help text
  7. -n set the network (mainnet, testnet, devnet. defaults to \$NETWORK if set)"
  8. network=$NETWORK
  9. while getopts ':hn:' option; do
  10. case "$option" in
  11. h) echo "$usage"
  12. exit
  13. ;;
  14. n) network=$OPTARG
  15. ;;
  16. :) printf "missing argument for -%s\n" "$OPTARG" >&2
  17. echo "$usage" >&2
  18. exit 1
  19. ;;
  20. \?) printf "illegal option: -%s\n" "$OPTARG" >&2
  21. echo "$usage" >&2
  22. exit 1
  23. ;;
  24. esac
  25. done
  26. shift $((OPTIND - 1))
  27. case "$network" in
  28. mainnet) url="https://lcd.terra.dev";;
  29. testnet) url="https://bombay-lcd.terra.dev";;
  30. devnet) url="http://localhost:1317";;
  31. *) printf "Network not set. Specify with -n\n" >&2
  32. echo "$usage" >&2
  33. exit 1
  34. ;;
  35. esac
  36. [ $# -ne 2 ] && { echo "$usage" >&2; exit 1; }
  37. obj_file=$1
  38. code_id=$2
  39. hash1=`curl "$url"/terra/wasm/v1beta1/codes/"$code_id" --silent | jq '.code_info.code_hash' -r | base64 -d | hexdump -v -e '/1 "%02x" '`
  40. hash2=`sha256sum $obj_file | cut -f1 -d' '`
  41. echo "Deployed bytecode hash (on $network):"
  42. echo $hash1
  43. echo "$obj_file hash:"
  44. echo $hash2
  45. if [ "$hash1" == "$hash2" ]; then
  46. printf "\033[0;32mSuccessfully verified\033[0m\n";
  47. exit 0;
  48. else
  49. printf "\033[0;31mFailed to verify\033[0m\n";
  50. exit 1;
  51. fi