Skip to content

Commit c6c4c85

Browse files
committed
lint: verify that all expected theorems are present
We add a check to the linting script called check-theorems that ensures that all HOL-Light proofs provide the expected set of theorems depending on the architecture. Signed-off-by: Andreas Hatziiliou <andreas.hatziiliou@savoirfairelinux.com>
1 parent 66a7ccf commit c6c4c85

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

scripts/lint

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,80 @@ gh_group_start "Linting Doxygen comments"
353353
check-doxygen
354354
gh_group_end
355355

356+
# Derive the theorem-name prefix from a proof routine's basename:
357+
# - strip the platform suffix (_aarch64_asm or _avx2_asm)
358+
# - uppercase
359+
# - prepend MLKEM_ unless the routine is a keccak proof
360+
theorem-prefix()
361+
{
362+
local routine="$1"
363+
local platform_suffix="$2"
364+
local base="${routine%${platform_suffix}}"
365+
base=$(echo "$base" | tr '[:lower:]' '[:upper:]')
366+
[[ "$base" == KECCAK_* ]] || base="MLKEM_${base}"
367+
echo "$base"
368+
}
369+
370+
check-theorems()
371+
{
372+
local success=true
373+
for arch in aarch64 x86_64; do
374+
local proofs_dir="$ROOT/proofs/hol_light/$arch/proofs"
375+
local platform_suffix="_aarch64_asm"
376+
[[ $arch == "x86_64" ]] && platform_suffix="_avx2_asm"
377+
local proofs
378+
proofs=$("$ROOT/proofs/hol_light/$arch/list_proofs.sh")
379+
380+
for routine in $proofs; do
381+
local file="$proofs_dir/${routine}.ml"
382+
local prefix
383+
prefix=$(theorem-prefix "$routine" "$platform_suffix")
384+
385+
# rej_uniform uses MEMSAFE in place of SAFE because no constant-time proof exists
386+
local safe="SAFE"
387+
[[ ${routine} == rej_uniform_* ]] && safe="MEMSAFE"
388+
389+
local expected=(
390+
"${prefix}_CORRECT"
391+
"${prefix}_SUBROUTINE_CORRECT"
392+
"${prefix}_SUBROUTINE_${safe}"
393+
)
394+
if [[ $arch == "x86_64" ]]; then
395+
expected+=(
396+
"${prefix}_${safe}"
397+
"${prefix}_NOIBT_SUBROUTINE_CORRECT"
398+
"${prefix}_NOIBT_SUBROUTINE_${safe}"
399+
)
400+
fi
401+
402+
for theorem in "${expected[@]}"; do
403+
if ! grep -qE "^[[:space:]]*let ${theorem}[[:space:]]+=[[:space:]]+(time[[:space:]]+)?prove" "$file"; then
404+
gh_error "${routine}" "" "Missing theorem" "${file}: ${theorem} not found"
405+
success=false
406+
fi
407+
done
408+
409+
if grep -q "CHEAT_TAC" "$file"; then
410+
gh_error "${routine}" "" "CHEAT_TAC detected" "${file}: uses CHEAT_TAC"
411+
success=false
412+
fi
413+
done
414+
done
415+
416+
if $success; then
417+
info "Check HOL-Light theorems"
418+
gh_summary_success "Check HOL-Light theorems"
419+
else
420+
error "Check HOL-Light theorems"
421+
SUCCESS=false
422+
gh_summary_failure "Check HOL-Light theorems"
423+
fi
424+
}
425+
426+
gh_group_start "Check HOL-Light theorems"
427+
check-theorems
428+
gh_group_end
429+
356430
if ! $SUCCESS; then
357431
if $IN_GITHUB_CONTEXT; then
358432
printf "%b%s%b\n" "${RED}" "The following checks failed, expand each for more details." "${NORMAL}"

0 commit comments

Comments
 (0)