Files
ruvnet--RuView/verify
T
ruv 6c230ed928 fix(verify): repoint wrapper to archive/v1 paths (#559) + cross-platform FFT probe (#560)
#559: Fix ./verify wrapper

The repo moved v1/ -> archive/v1/ but ./verify still pointed at the old
paths and failed before reaching the proof script with:
  FAIL: Reference signal not found at .../v1/data/proof/sample_csi_data.json
  FAIL: verify.py not found at .../v1/data/proof/verify.py

Update PROOF_DIR, V1_SRC, and two diagnostic strings to use archive/v1/.

#560: Add platform probe + root-cause evidence

Add scripts/probe-fft-platform.py that runs verify.py's hash-relevant
scipy.fft.fft / scipy.signal.windows.hamming calls in isolation on a
deterministic input (no pydantic Settings stack), so the source of
divergence can be located across platforms.

Tested on three machines via Tailscale:

  Windows (Intel AVX-512, numpy 2.4.2 / scipy 1.17.1):
    first4_psd_floats = [..., 94.40426770856882, ..., 51.677496924642476]
    sha256 = 78b3fb4acb8cc18c3e870f92e29ee98143c7cac4767f2f71b0fc384a82b92f6e

  ruvultra (Linux x86_64, numpy 1.26.4 / scipy 1.14.1):
    first4_psd_floats = [..., 94.40426770856882, ..., 51.677496924642476]
    sha256 = 41dc56416b6e8346d6457b1e3c9ca5d4b9035f645658e40e2eb668d08efaf9b6

  ruv-mac-mini (Apple Silicon arm64/NEON, numpy 2.4.4 / scipy 1.17.1):
    first4_psd_floats = [..., 94.4042677085688, ..., 51.67749692464246]
    sha256 = 9b5e192b56d26a486eefe5dff6bb0e05f6223163a4246043fc168002d495efca

Win and Linux agree on the first PSD/doppler values but produce
different SHA-256s (later FFT bins diverge due to scipy version's
pocketfft SIMD path). Mac arm64 differs from x86_64 at ULP precision
(~2e-14 at value ~94 = ~1 ULP) on index 1 of the FIRST PSD bins.

Root cause: SIMD-vectorized FFT reorders floating-point operations.
NEON on Apple Silicon vs AVX2/AVX-512 on x86_64 produce ULP-different
results, which a bit-exact SHA-256 cannot tolerate. The verify.py
docstring at line 172 ("platform-independent for IEEE 754 compliant
systems") is incorrect -- IEEE 754 guarantees per-operation
determinism but vectorized FFT reorders ops.

This commit ships the diagnostic probe + the #559 path fix only. The
verify.py hash function itself (quantize-before-hash to absorb ULP
divergence + regeneration of expected_features.sha256 on a canonical
CI platform) is a follow-up that affects a published trust-anchor
artifact -- left for maintainer decision.

Verification:
  cd <repo> && ./verify
  # before: FAIL before reaching pipeline (v1/... not found)
  # after:  reaches verify.py and runs the pipeline

  python3 scripts/probe-fft-platform.py
  # prints JSON with sha256 + first-few-floats per platform

Refs: #559, #560

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-05-15 11:35:33 -04:00

221 lines
7.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# ======================================================================
# WiFi-DensePose: Trust Kill Switch
#
# One-command proof replay that makes "it is mocked" a falsifiable,
# measurable claim that fails against evidence.
#
# Usage:
# ./verify Run the full proof pipeline
# ./verify --verbose Show detailed feature statistics
# ./verify --audit Also scan codebase for mock/random patterns
#
# Exit codes:
# 0 PASS -- pipeline hash matches published expected hash
# 1 FAIL -- hash mismatch or error
# 2 SKIP -- no expected hash file to compare against
# ======================================================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROOF_DIR="${SCRIPT_DIR}/archive/v1/data/proof"
VERIFY_PY="${PROOF_DIR}/verify.py"
V1_SRC="${SCRIPT_DIR}/archive/v1/src"
# Colors (disabled if not a terminal)
if [ -t 1 ]; then
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
RESET='\033[0m'
else
RED=''
GREEN=''
YELLOW=''
CYAN=''
BOLD=''
RESET=''
fi
echo ""
echo -e "${BOLD}======================================================================"
echo " WiFi-DensePose: Trust Kill Switch"
echo " One-command proof that the signal processing pipeline is real."
echo -e "======================================================================${RESET}"
echo ""
# ------------------------------------------------------------------
# PHASE 1: Environment checks
# ------------------------------------------------------------------
echo -e "${CYAN}[PHASE 1] ENVIRONMENT CHECKS${RESET}"
echo ""
ERRORS=0
# Check Python
if command -v python3 &>/dev/null; then
PYTHON=python3
elif command -v python &>/dev/null; then
PYTHON=python
else
echo -e " ${RED}FAIL${RESET}: Python 3 not found. Install python3."
exit 1
fi
PY_VERSION=$($PYTHON --version 2>&1)
echo " Python: $PY_VERSION ($( command -v $PYTHON ))"
# Check numpy
if $PYTHON -c "import numpy; print(f' numpy: {numpy.__version__} ({numpy.__file__})')" 2>/dev/null; then
:
else
echo -e " ${RED}FAIL${RESET}: numpy not installed. Run: pip install numpy"
ERRORS=$((ERRORS + 1))
fi
# Check scipy
if $PYTHON -c "import scipy; print(f' scipy: {scipy.__version__} ({scipy.__file__})')" 2>/dev/null; then
:
else
echo -e " ${RED}FAIL${RESET}: scipy not installed. Run: pip install scipy"
ERRORS=$((ERRORS + 1))
fi
# Check proof files exist
echo ""
if [ -f "${PROOF_DIR}/sample_csi_data.json" ]; then
SIZE=$(wc -c < "${PROOF_DIR}/sample_csi_data.json" | tr -d ' ')
echo " Reference signal: sample_csi_data.json (${SIZE} bytes)"
else
echo -e " ${RED}FAIL${RESET}: Reference signal not found at ${PROOF_DIR}/sample_csi_data.json"
ERRORS=$((ERRORS + 1))
fi
if [ -f "${PROOF_DIR}/expected_features.sha256" ]; then
EXPECTED=$(cat "${PROOF_DIR}/expected_features.sha256" | tr -d '[:space:]')
echo " Expected hash: ${EXPECTED}"
else
echo -e " ${YELLOW}WARN${RESET}: No expected hash file found"
fi
if [ -f "${VERIFY_PY}" ]; then
echo " Verify script: ${VERIFY_PY}"
else
echo -e " ${RED}FAIL${RESET}: verify.py not found at ${VERIFY_PY}"
ERRORS=$((ERRORS + 1))
fi
echo ""
if [ $ERRORS -gt 0 ]; then
echo -e "${RED}Cannot proceed: $ERRORS prerequisite(s) missing.${RESET}"
exit 1
fi
echo -e " ${GREEN}All prerequisites satisfied.${RESET}"
echo ""
# ------------------------------------------------------------------
# PHASE 2: Run the proof pipeline
# ------------------------------------------------------------------
echo -e "${CYAN}[PHASE 2] PROOF PIPELINE REPLAY${RESET}"
echo ""
# Pass through any flags (--verbose, --audit, --generate-hash)
PIPELINE_EXIT=0
$PYTHON "${VERIFY_PY}" "$@" || PIPELINE_EXIT=$?
echo ""
# ------------------------------------------------------------------
# PHASE 3: Mock/random scan of production codebase
# ------------------------------------------------------------------
echo -e "${CYAN}[PHASE 3] PRODUCTION CODE INTEGRITY SCAN${RESET}"
echo ""
echo " Scanning ${V1_SRC} for np.random.rand / np.random.randn calls..."
echo " (Excluding archive/v1/src/testing/ -- test helpers are allowed to use random.)"
echo ""
MOCK_FINDINGS=0
# Scan for np.random.rand and np.random.randn in production code
# We exclude testing/ directories
while IFS= read -r line; do
if [ -n "$line" ]; then
echo -e " ${YELLOW}FOUND${RESET}: $line"
MOCK_FINDINGS=$((MOCK_FINDINGS + 1))
fi
done < <(
find "${V1_SRC}" -name "*.py" -type f \
! -path "*/testing/*" \
! -path "*/tests/*" \
! -path "*/test/*" \
! -path "*__pycache__*" \
-exec grep -Hn 'np\.random\.rand\b\|np\.random\.randn\b' {} \; 2>/dev/null || true
)
if [ $MOCK_FINDINGS -eq 0 ]; then
echo -e " ${GREEN}CLEAN${RESET}: No np.random.rand/randn calls in production code."
else
echo ""
echo -e " ${YELLOW}WARNING${RESET}: Found ${MOCK_FINDINGS} random generator call(s) in production code."
echo " These should be reviewed -- production signal processing should"
echo " never generate random data."
fi
echo ""
# ------------------------------------------------------------------
# FINAL SUMMARY
# ------------------------------------------------------------------
echo -e "${BOLD}======================================================================${RESET}"
if [ $PIPELINE_EXIT -eq 0 ]; then
echo ""
echo -e " ${GREEN}${BOLD}RESULT: PASS${RESET}"
echo ""
echo " The production pipeline replayed the published reference signal"
echo " and produced a SHA-256 hash that MATCHES the published expected hash."
echo ""
echo " What this proves:"
echo " - The signal processing code is REAL (not mocked)"
echo " - The pipeline is DETERMINISTIC (same input -> same hash)"
echo " - The code path includes: noise filtering, Hamming windowing,"
echo " amplitude normalization, FFT-based Doppler extraction,"
echo " and power spectral density computation via scipy.fft"
echo " - No randomness was injected (the hash is exact)"
echo ""
echo " To falsify: change any signal processing code and re-run."
echo " The hash will break. That is the point."
echo ""
if [ $MOCK_FINDINGS -eq 0 ]; then
echo -e " Mock scan: ${GREEN}CLEAN${RESET} (no random generators in production code)"
else
echo -e " Mock scan: ${YELLOW}${MOCK_FINDINGS} finding(s)${RESET} (review recommended)"
fi
echo ""
echo -e "${BOLD}======================================================================${RESET}"
exit 0
elif [ $PIPELINE_EXIT -eq 2 ]; then
echo ""
echo -e " ${YELLOW}${BOLD}RESULT: SKIP${RESET}"
echo ""
echo " No expected hash file to compare against."
echo " Run: python archive/v1/data/proof/verify.py --generate-hash"
echo ""
echo -e "${BOLD}======================================================================${RESET}"
exit 2
else
echo ""
echo -e " ${RED}${BOLD}RESULT: FAIL${RESET}"
echo ""
echo " The pipeline hash does NOT match the expected hash."
echo " Something changed in the signal processing code."
echo ""
echo -e "${BOLD}======================================================================${RESET}"
exit 1
fi