interplane.Get Omega
Read in your language

omega-seed-challenge

aien-dev/omega-seed-challenge

Brought by drakestapleton

branch main Branches Tags History

omega-seed-challenge / check-result.sh

43 lines · 2170 bytes Raw Blame History
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.
9set -u
10[ $# -eq 2 ] && [ -r "$1" ] && [ -r "$2" ] || { echo "usage: check-result.sh <expected.txt> <challenge.log>" >&2; exit 2; }
11exp=$1
12log=$(mktemp) || exit 2
13trap 'rm -f "$log"' EXIT
14tr -d '\r' < "$2" > "$log"
15bad=0
16no() { printf 'REFUSED %s\n' "$*"; bad=$((bad+1)); }
17has() { grep -qxF -- "$1" "$log" || grep -qx -- "$(printf '%s' "$1" | sed 's/[][\.*^$/]/\\&/g') [0-9]*ms" "$log"; }
18
19pin=$(awk '$1=="pin"{print $2}' "$exp")
20[ -n "$pin" ] || { echo "usage: $exp names no pin" >&2; exit 2; }
21grep -qxF "pin $pin" "$log" || no "log does not name pin $pin"
22grep -q '^host .*aarch64' "$log" || no "host line does not say aarch64"
23
24while 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
35done < "$exp"
36
37if grep -qE '(^|^stage[123] )(FAIL|NOT_RUN) ' "$log"; then no "log contains FAIL or NOT_RUN lines"; fi
38last=$(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
41if [ "$bad" = 0 ]; then echo "RESULT ACCEPTED pin=$pin omc=$omc"; exit 0; fi
42echo "RESULT REFUSED reasons=$bad"
43exit 1