Skip to content

Commit

Permalink
Merge pull request aws#102 from aqjune-aws/ci-log-time2
Browse files Browse the repository at this point in the history
Print running times of proofs, factor out proof runner
  • Loading branch information
aqjune-aws authored Jan 5, 2024
2 parents 4097178 + 76a8cf5 commit e21b2e7
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 42 deletions.
42 changes: 21 additions & 21 deletions arm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -371,30 +371,30 @@ PROOFS = $(OBJ:.o=.correct)

# Cases where a proof uses other proofs for lemmas and/or subroutines

curve25519/curve25519_x25519.correct: curve25519/bignum_inv_p25519.o proofs/curve25519_x25519.ml curve25519/curve25519_x25519.o ; (cd ..; (echo 'loadt "arm/proofs/base.ml";;'; echo 'loadt "arm/proofs/curve25519_x25519.ml";;') | $(HOLLIGHT) 2>&1) >$@
curve25519/curve25519_x25519_alt.correct: curve25519/bignum_inv_p25519.o proofs/curve25519_x25519_alt.ml curve25519/curve25519_x25519_alt.o ; (cd ..; (echo 'loadt "arm/proofs/base.ml";;'; echo 'loadt "arm/proofs/curve25519_x25519_alt.ml";;') | $(HOLLIGHT) 2>&1) >$@
curve25519/curve25519_x25519_byte.correct: curve25519/bignum_inv_p25519.o proofs/curve25519_x25519_byte.ml curve25519/curve25519_x25519_byte.o ; (cd ..; (echo 'loadt "arm/proofs/base.ml";;'; echo 'loadt "arm/proofs/curve25519_x25519_byte.ml";;') | $(HOLLIGHT) 2>&1) >$@
curve25519/curve25519_x25519_byte_alt.correct: curve25519/bignum_inv_p25519.o proofs/curve25519_x25519_byte_alt.ml curve25519/curve25519_x25519_byte_alt.o ; (cd ..; (echo 'loadt "arm/proofs/base.ml";;'; echo 'loadt "arm/proofs/curve25519_x25519_byte_alt.ml";;') | $(HOLLIGHT) 2>&1) >$@
curve25519/curve25519_x25519base.correct: curve25519/bignum_inv_p25519.o proofs/curve25519_x25519base.ml curve25519/curve25519_x25519base.o ; (cd ..; (echo 'loadt "arm/proofs/base.ml";;'; echo 'loadt "arm/proofs/curve25519_x25519base.ml";;') | $(HOLLIGHT) 2>&1) >$@
curve25519/curve25519_x25519base_alt.correct: curve25519/bignum_inv_p25519.o proofs/curve25519_x25519base_alt.ml curve25519/curve25519_x25519base_alt.o ; (cd ..; (echo 'loadt "arm/proofs/base.ml";;'; echo 'loadt "arm/proofs/curve25519_x25519base_alt.ml";;') | $(HOLLIGHT) 2>&1) >$@
curve25519/curve25519_x25519base_byte.correct: curve25519/bignum_inv_p25519.o proofs/curve25519_x25519base_byte.ml curve25519/curve25519_x25519base_byte.o ; (cd ..; (echo 'loadt "arm/proofs/base.ml";;'; echo 'loadt "arm/proofs/curve25519_x25519base_byte.ml";;') | $(HOLLIGHT) 2>&1) >$@
curve25519/curve25519_x25519base_byte_alt.correct: curve25519/bignum_inv_p25519.o proofs/curve25519_x25519base_byte_alt.ml curve25519/curve25519_x25519base_byte_alt.o ; (cd ..; (echo 'loadt "arm/proofs/base.ml";;'; echo 'loadt "arm/proofs/curve25519_x25519base_byte_alt.ml";;') | $(HOLLIGHT) 2>&1) >$@
curve25519/edwards25519_scalarmulbase.correct: curve25519/bignum_inv_p25519.o proofs/edwards25519_scalarmulbase.ml curve25519/edwards25519_scalarmulbase.o ; (cd ..; (echo 'loadt "arm/proofs/base.ml";;'; echo 'loadt "arm/proofs/edwards25519_scalarmulbase.ml";;') | $(HOLLIGHT) 2>&1) >$@
curve25519/edwards25519_scalarmulbase_alt.correct: curve25519/bignum_inv_p25519.o proofs/edwards25519_scalarmulbase_alt.ml curve25519/edwards25519_scalarmulbase_alt.o ; (cd ..; (echo 'loadt "arm/proofs/base.ml";;'; echo 'loadt "arm/proofs/edwards25519_scalarmulbase_alt.ml";;') | $(HOLLIGHT) 2>&1) >$@
curve25519/edwards25519_scalarmuldouble.correct: curve25519/bignum_inv_p25519.o proofs/edwards25519_scalarmuldouble.ml curve25519/edwards25519_scalarmuldouble.o ; (cd ..; (echo 'loadt "arm/proofs/base.ml";;'; echo 'loadt "arm/proofs/edwards25519_scalarmuldouble.ml";;') | $(HOLLIGHT) 2>&1) >$@
curve25519/edwards25519_scalarmuldouble_alt.correct: curve25519/bignum_inv_p25519.o proofs/edwards25519_scalarmuldouble_alt.ml curve25519/edwards25519_scalarmuldouble_alt.o ; (cd ..; (echo 'loadt "arm/proofs/base.ml";;'; echo 'loadt "arm/proofs/edwards25519_scalarmuldouble_alt.ml";;') | $(HOLLIGHT) 2>&1) >$@
generic/bignum_modexp.correct: generic/bignum_amontifier.correct generic/bignum_amontmul.correct generic/bignum_demont.correct generic/bignum_mux.correct proofs/bignum_modexp.ml generic/bignum_modexp.o ; (cd ..; (echo 'loadt "arm/proofs/base.ml";;'; echo 'loadt "arm/proofs/bignum_modexp.ml";;') | $(HOLLIGHT) 2>&1) >$@
curve25519/curve25519_x25519.correct: curve25519/bignum_inv_p25519.o proofs/curve25519_x25519.ml curve25519/curve25519_x25519.o ; ../tools/run-proof.sh arm curve25519_x25519 "$(HOLLIGHT)" >$@
curve25519/curve25519_x25519_alt.correct: curve25519/bignum_inv_p25519.o proofs/curve25519_x25519_alt.ml curve25519/curve25519_x25519_alt.o ; ../tools/run-proof.sh arm curve25519_x25519_alt "$(HOLLIGHT)" >$@
curve25519/curve25519_x25519_byte.correct: curve25519/bignum_inv_p25519.o proofs/curve25519_x25519_byte.ml curve25519/curve25519_x25519_byte.o ; ../tools/run-proof.sh arm curve25519_x25519_byte "$(HOLLIGHT)" >$@
curve25519/curve25519_x25519_byte_alt.correct: curve25519/bignum_inv_p25519.o proofs/curve25519_x25519_byte_alt.ml curve25519/curve25519_x25519_byte_alt.o ; ../tools/run-proof.sh arm curve25519_x25519_byte_alt "$(HOLLIGHT)" >$@
curve25519/curve25519_x25519base.correct: curve25519/bignum_inv_p25519.o proofs/curve25519_x25519base.ml curve25519/curve25519_x25519base.o ; ../tools/run-proof.sh arm curve25519_x25519base "$(HOLLIGHT)" >$@
curve25519/curve25519_x25519base_alt.correct: curve25519/bignum_inv_p25519.o proofs/curve25519_x25519base_alt.ml curve25519/curve25519_x25519base_alt.o ; ../tools/run-proof.sh arm curve25519_x25519base_alt "$(HOLLIGHT)" >$@
curve25519/curve25519_x25519base_byte.correct: curve25519/bignum_inv_p25519.o proofs/curve25519_x25519base_byte.ml curve25519/curve25519_x25519base_byte.o ; ../tools/run-proof.sh arm curve25519_x25519base_byte "$(HOLLIGHT)" >$@
curve25519/curve25519_x25519base_byte_alt.correct: curve25519/bignum_inv_p25519.o proofs/curve25519_x25519base_byte_alt.ml curve25519/curve25519_x25519base_byte_alt.o ; ../tools/run-proof.sh arm curve25519_x25519base_byte_alt "$(HOLLIGHT)" >$@
curve25519/edwards25519_scalarmulbase.correct: curve25519/bignum_inv_p25519.o proofs/edwards25519_scalarmulbase.ml curve25519/edwards25519_scalarmulbase.o ; ../tools/run-proof.sh arm edwards25519_scalarmulbase "$(HOLLIGHT)" >$@
curve25519/edwards25519_scalarmulbase_alt.correct: curve25519/bignum_inv_p25519.o proofs/edwards25519_scalarmulbase_alt.ml curve25519/edwards25519_scalarmulbase_alt.o ; ../tools/run-proof.sh arm edwards25519_scalarmulbase_alt "$(HOLLIGHT)" >$@
curve25519/edwards25519_scalarmuldouble.correct: curve25519/bignum_inv_p25519.o proofs/edwards25519_scalarmuldouble.ml curve25519/edwards25519_scalarmuldouble.o ; ../tools/run-proof.sh arm edwards25519_scalarmuldouble "$(HOLLIGHT)" >$@
curve25519/edwards25519_scalarmuldouble_alt.correct: curve25519/bignum_inv_p25519.o proofs/edwards25519_scalarmuldouble_alt.ml curve25519/edwards25519_scalarmuldouble_alt.o ; ../tools/run-proof.sh arm edwards25519_scalarmuldouble_alt "$(HOLLIGHT)" >$@
generic/bignum_modexp.correct: generic/bignum_amontifier.correct generic/bignum_amontmul.correct generic/bignum_demont.correct generic/bignum_mux.correct proofs/bignum_modexp.ml generic/bignum_modexp.o ; ../tools/run-proof.sh arm bignum_modexp "$(HOLLIGHT)" >$@

# All other other instances are standalone

curve25519/%.correct: proofs/%.ml curve25519/%.o ; (cd ..; (echo 'loadt "arm/proofs/base.ml";;'; echo 'loadt "arm/proofs/$*.ml";;') | $(HOLLIGHT) 2>&1) >$@
fastmul/%.correct: proofs/%.ml fastmul/%.o ; (cd ..; (echo 'loadt "arm/proofs/base.ml";;'; echo 'loadt "arm/proofs/$*.ml";;') | $(HOLLIGHT) 2>&1) >$@
generic/%.correct: proofs/%.ml generic/%.o ; (cd ..; (echo 'loadt "arm/proofs/base.ml";;'; echo 'loadt "arm/proofs/$*.ml";;') | $(HOLLIGHT) 2>&1) >$@
p256/%.correct: proofs/%.ml p256/%.o ; (cd ..; (echo 'loadt "arm/proofs/base.ml";;'; echo 'loadt "arm/proofs/$*.ml";;') | $(HOLLIGHT) 2>&1) >$@
p384/%.correct: proofs/%.ml p384/%.o ; (cd ..; (echo 'loadt "arm/proofs/base.ml";;'; echo 'loadt "arm/proofs/$*.ml";;') | $(HOLLIGHT) 2>&1) >$@
p521/%.correct: proofs/%.ml p521/%.o ; (cd ..; (echo 'loadt "arm/proofs/base.ml";;'; echo 'loadt "arm/proofs/$*.ml";;') | $(HOLLIGHT) 2>&1) >$@
secp256k1/%.correct: proofs/%.ml secp256k1/%.o ; (cd ..; (echo 'loadt "arm/proofs/base.ml";;'; echo 'loadt "arm/proofs/$*.ml";;') | $(HOLLIGHT) 2>&1) >$@
sm2/%.correct: proofs/%.ml sm2/%.o ; (cd ..; (echo 'loadt "arm/proofs/base.ml";;'; echo 'loadt "arm/proofs/$*.ml";;') | $(HOLLIGHT) 2>&1) >$@
curve25519/%.correct: proofs/%.ml curve25519/%.o ; ../tools/run-proof.sh arm "$*" "$(HOLLIGHT)" >$@
fastmul/%.correct: proofs/%.ml fastmul/%.o ; ../tools/run-proof.sh arm "$*" "$(HOLLIGHT)" >$@
generic/%.correct: proofs/%.ml generic/%.o ; ../tools/run-proof.sh arm "$*" "$(HOLLIGHT)" >$@
p256/%.correct: proofs/%.ml p256/%.o ; ../tools/run-proof.sh arm "$*" "$(HOLLIGHT)" >$@
p384/%.correct: proofs/%.ml p384/%.o ; ../tools/run-proof.sh arm "$*" "$(HOLLIGHT)" >$@
p521/%.correct: proofs/%.ml p521/%.o ; ../tools/run-proof.sh arm "$*" "$(HOLLIGHT)" >$@
secp256k1/%.correct: proofs/%.ml secp256k1/%.o ; ../tools/run-proof.sh arm "$*" "$(HOLLIGHT)" >$@
sm2/%.correct: proofs/%.ml sm2/%.o ; ../tools/run-proof.sh arm "$*" "$(HOLLIGHT)" >$@

run_proofs: $(PROOFS);

Expand Down
1 change: 1 addition & 0 deletions codebuild/proofs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ phases:
- cd ${CODEBUILD_SRC_DIR}/${S2N_BIGNUM_ARCH}
- export HOLDIR=${CODEBUILD_SRC_DIR_hol_light}
- make -j ${CORE_COUNT} proofs
- ../tools/collect-times.sh ${S2N_BIGNUM_ARCH}
1 change: 1 addition & 0 deletions tools/check-proofs.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/bash
if [ "$#" -ne 1 ]; then
echo "check-proofs.sh <dir (e.g., arm)>"
echo "This script inspects .correct files that are generated by 'make proofs'"
Expand Down
18 changes: 18 additions & 0 deletions tools/collect-times.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
if [ "$#" -ne 1 ]; then
echo "collect-times.sh <dir (e.g., arm)>"
echo "This script inspects .correct files that are generated by 'make proofs'"
echo "in the given architecture directory and collects all timing informations."
exit 1
fi

s2n_bignum_arch=$1
cd $s2n_bignum_arch

num_correct_files=`find . -name "*.correct" | wc -l`
if [ $num_correct_files -eq 0 ]; then
echo "No .correct file exists. Did you run 'make proofs'?"
exit 1
fi
# grep must not detect anything including 'error' (case insensitive, '-i').
grep -r -i "Running time: " --include "*.correct"
23 changes: 23 additions & 0 deletions tools/run-proof.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
if [ "$#" -ne 3 ]; then
echo "../tools/run-proof.sh <dir (arm/x86)> <asm filename without .S (e.g., bignum_copy)> <HOL Light command>"
echo "This script runs HOL Light proof at '<dir>/proofs/<asm filename>.ml'".
exit 1
fi

# Return the exit code if any statement fails
set -e

cd ..

s2n_bignum_arch=$1
asm_filename=$2
hol_light_cmd=$3

(echo 'Topdirs.dir_directory "+unix";;'; \
echo 'Topdirs.dir_load Format.std_formatter "unix.cma";;'; \
echo 'let start_time = Unix.time();;'; \
echo "loadt \"${s2n_bignum_arch}/proofs/base.ml\";;"; \
echo "loadt \"${s2n_bignum_arch}/proofs/${asm_filename}.ml\";;"; \
echo 'let end_time = Unix.time();;'; \
echo 'Printf.printf "Running time: %f sec, Start unixtime: %f, End unixtime: %f\n" (end_time -. start_time) start_time end_time;;') | eval "$hol_light_cmd" 2>&1
Loading

0 comments on commit e21b2e7

Please sign in to comment.