omega-seed-challenge
aien-dev/omega-seed-challenge
Brought by drakestapleton
omega-seed-challenge / check-result.sh
| 1 | #!/bin/sh |
| 2 | # check-result.sh <expected.txt> <challenge.log> -- compare a submitted seed-challenge hash log with the |
| 3 | # published table (omega-mv seed/challenge/expected-v1.txt, or another expected*.txt that names its pin). |
| 4 | # Prints RESULT ACCEPTED (exit 0) or RESULT REFUSED with each reason (exit 1); exit 2 = usage. |
| 5 | # What this proves: the log is complete and every hash in it equals the published value. It cannot |
| 6 | # prove that the run happened on the machine the log names; anyone can type a log. The run that counts |
| 7 | # is the one on your own machine. |
| 8 | # Host glue (POSIX sh + awk), kept outside the chain it checks on purpose; no .om successor planned. |
| 9 | set -u |
| 10 | [ $# -eq 2 ] && [ -r "$1" ] && [ -r "$2" ] || { echo "usage: check-result.sh <expected.txt> <challenge.log>" >&2; exit 2; } |
| 11 | exp=$1 |
| 12 | log=$(mktemp) || exit 2 |
| 13 | trap 'rm -f "$log"' EXIT |
| 14 | tr -d '\r' < "$2" > "$log" |
| 15 | bad=0 |
| 16 | no() { printf 'REFUSED %s\n' "$*"; bad=$((bad+1)); } |
| 17 | has() { grep -qxF -- "$1" "$log" || grep -qx -- "$(printf '%s' "$1" | sed 's/[][\.*^$/]/\\&/g') [0-9]*ms" "$log"; } |
| 18 | |
| 19 | pin=$(awk '$1=="pin"{print $2}' "$exp") |
| 20 | [ -n "$pin" ] || { echo "usage: $exp names no pin" >&2; exit 2; } |
| 21 | grep -qxF "pin $pin" "$log" || no "log does not name pin $pin" |
| 22 | grep -q '^host .*aarch64' "$log" || no "host line does not say aarch64" |
| 23 | |
| 24 | while read -r kind name sha bytes; do |
| 25 | case $kind in |
| 26 | input) grep -qxF "PASS input $name $sha $bytes" "$log" || no "input $name: no PASS line with $sha $bytes" ;; |
| 27 | rung) |
| 28 | if [ "$name" = omc ]; then |
| 29 | for st in 1 2 3; do has "stage$st PASS rung omc $sha $bytes" || no "omc stage$st: no PASS line with $sha $bytes"; done |
| 30 | omc=$sha |
| 31 | else |
| 32 | has "PASS rung $name $sha $bytes" || no "rung $name: no PASS line with $sha $bytes" |
| 33 | fi ;; |
| 34 | esac |
| 35 | done < "$exp" |
| 36 | |
| 37 | if grep -qE '(^|^stage[123] )(FAIL|NOT_RUN) ' "$log"; then no "log contains FAIL or NOT_RUN lines"; fi |
| 38 | last=$(grep '^CHALLENGE ' "$log" | tail -n 1) |
| 39 | [ "$last" = "CHALLENGE PASS pin=$pin omc=${omc:-}" ] || no "final line is '$last', not CHALLENGE PASS pin=$pin omc=${omc:-}" |
| 40 | |
| 41 | if [ "$bad" = 0 ]; then echo "RESULT ACCEPTED pin=$pin omc=$omc"; exit 0; fi |
| 42 | echo "RESULT REFUSED reasons=$bad" |
| 43 | exit 1 |