#!/usr/bin/env bash set -uo pipefail # CASAN H5 — Detect audit rollback / evidence deletion vs the WORM ledger (C5/V21). # Verifies the external anchor ledger is internally intact (hash-linked) AND that # the local audit head has not been rolled back below the durable anchor. Deleting # the tail of the local audit log surfaces as AUDIT_GAP_DETECTED because the WORM # ledger still holds the later head. # # Usage: verify-audit-gap.sh [head-file] [ledger-file] # Exit: 0 in-sync, 1 tamper/gap/unshipped, 64 usage. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "$SCRIPT_DIR/casan-paths.sh" PROJECT_ROOT="$CASAN_APP_ROOT" HEAD_FILE="${1:-$CASAN_STATE_ROOT/logs/audit/audit-head.txt}" LEDGER="${2:-${CASAN_WORM_LEDGER:-$CASAN_STATE_ROOT/logs/worm/anchor-ledger.jsonl}}" [[ -f "$HEAD_FILE" ]] || { echo "AUDIT_GAP_NO_HEAD file=$HEAD_FILE" >&2; exit 1; } python "$SCRIPT_DIR/worm-ledger.py" verify "$HEAD_FILE" "$LEDGER"