Skip to content

Commit 944cb66

Browse files
committed
HOL-Light: Simplify proof of poly_tobytes
The precondition in the HOL-Light proof for mlkem_poly_tobytes abstracts the memory contents at the source pointer as a list of 16-bit words. However, it is only in the post-condition that the length of this list is constrained to be 256. This does not seem to increase the expressivity of the spec but complicates the proof; in particular, it adds the need for another tactic currently fed the total number of instructions in the function, and which is not readily amenable to wrapping by the recently introduced MAP_UNTIL_TARGET_PC function. This commit moves the length constraints on the abstract list of 16-bit values to the precondition, simplifying the proof and thereby making it agnostic to the total number of instructions. Note that in general there can be value to pushing preconditions into premises of the post-condition: For example, in the NTT or invNTT, one can shove the constraint that the provided twiddle table should contain the right twiddles into a premise of the post-condition. This strictly increases expressivity, because even for wrong twiddle tables, one still gets safety properties from the proof. However, in the case of poly_tobytes, there does not seem to be such gain from moving the length constraint into the post-condition. Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
1 parent adb7160 commit 944cb66

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

proofs/hol_light/arm/proofs/mlkem_poly_tobytes.ml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,11 @@ let MLKEM_POLY_TOBYTES_CORRECT = prove
203203
(\s. aligned_bytes_loaded s (word pc) mlkem_poly_tobytes_mc /\
204204
read PC s = word (pc + MLKEM_POLY_TOBYTES_CORE_START) /\
205205
C_ARGUMENTS [r;a] s /\
206+
LENGTH l = 256 /\
206207
read (memory :> bytes(a,512)) s = num_of_wordlist l)
207208
(\s. read PC s = word(pc + MLKEM_POLY_TOBYTES_CORE_END) /\
208-
(LENGTH l = 256
209-
==> read(memory :> bytes(r,384)) s =
210-
num_of_wordlist (MAP word_zx l:(12 word)list)))
209+
read(memory :> bytes(r,384)) s =
210+
num_of_wordlist (MAP word_zx l:(12 word)list))
211211
(MAYCHANGE_REGS_AND_FLAGS_PERMITTED_BY_ABI ,,
212212
MAYCHANGE [memory :> bytes(r,384)])`,
213213
CONV_TAC LENGTH_SIMPLIFY_CONV THEN
@@ -216,12 +216,7 @@ let MLKEM_POLY_TOBYTES_CORRECT = prove
216216
NONOVERLAPPING_CLAUSES; ALL] THEN
217217
DISCH_THEN(REPEAT_TCL CONJUNCTS_THEN ASSUME_TAC) THEN
218218

219-
(*** Globalize the LENGTH l = 256 hypothesis ***)
220-
221-
ASM_CASES_TAC `LENGTH(l:int16 list) = 256` THENL
222-
[ASM_REWRITE_TAC[] THEN ENSURES_INIT_TAC "s0";
223-
ARM_QUICKSIM_TAC MLKEM_POLY_TOBYTES_EXEC
224-
[`read X0 s = a`; `read X1 s = z`; `read X2 s = i`] (1--169)] THEN
219+
ASM_REWRITE_TAC[] THEN ENSURES_INIT_TAC "s0" THEN
225220

226221
(*** Digitize and tweak the input digits to match 128-bit load size ****)
227222

@@ -283,11 +278,11 @@ let MLKEM_POLY_TOBYTES_SUBROUTINE_CORRECT = prove
283278
read PC s = word pc /\
284279
read X30 s = returnaddress /\
285280
C_ARGUMENTS [r;a] s /\
281+
LENGTH l = 256 /\
286282
read (memory :> bytes(a,512)) s = num_of_wordlist l)
287283
(\s. read PC s = returnaddress /\
288-
(LENGTH l = 256
289-
==> read(memory :> bytes(r,384)) s =
290-
num_of_wordlist (MAP word_zx l:(12 word)list)))
284+
read(memory :> bytes(r,384)) s =
285+
num_of_wordlist (MAP word_zx l:(12 word)list))
291286
(MAYCHANGE_REGS_AND_FLAGS_PERMITTED_BY_ABI ,,
292287
MAYCHANGE [memory :> bytes(r,384)])`,
293288
CONV_TAC LENGTH_SIMPLIFY_CONV THEN

0 commit comments

Comments
 (0)