Skip to content

Commit 242eccb

Browse files
committed
CBMC: Prove AArch64 mlk_poly_reduce_native based on HOL-Light spec
Signed-off-by: Matthias J. Kannwischer <matthias@kannwischer.eu>
1 parent 0843f3f commit 242eccb

File tree

6 files changed

+99
-3
lines changed

6 files changed

+99
-3
lines changed

dev/aarch64_clean/src/arith_native_aarch64.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,14 @@ __contract__(
6262
);
6363

6464
#define mlk_poly_reduce_asm MLK_NAMESPACE(poly_reduce_asm)
65-
void mlk_poly_reduce_asm(int16_t *);
65+
void mlk_poly_reduce_asm(int16_t *p)
66+
/* This must be kept in sync with the HOL-Light specification
67+
* in proofs/hol_light/arm/proofs/mlkem_poly_reduce.ml */
68+
__contract__(
69+
requires(memory_no_alias(p, sizeof(int16_t) * MLKEM_N))
70+
assigns(memory_slice(p, sizeof(int16_t) * MLKEM_N))
71+
ensures(array_bound(p, 0, MLKEM_N, 0, MLKEM_Q))
72+
);
6673

6774
#define mlk_poly_tomont_asm MLK_NAMESPACE(poly_tomont_asm)
6875
void mlk_poly_tomont_asm(int16_t *p)

dev/aarch64_opt/src/arith_native_aarch64.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,14 @@ __contract__(
6262
);
6363

6464
#define mlk_poly_reduce_asm MLK_NAMESPACE(poly_reduce_asm)
65-
void mlk_poly_reduce_asm(int16_t *);
65+
void mlk_poly_reduce_asm(int16_t *p)
66+
/* This must be kept in sync with the HOL-Light specification
67+
* in proofs/hol_light/arm/proofs/mlkem_poly_reduce.ml */
68+
__contract__(
69+
requires(memory_no_alias(p, sizeof(int16_t) * MLKEM_N))
70+
assigns(memory_slice(p, sizeof(int16_t) * MLKEM_N))
71+
ensures(array_bound(p, 0, MLKEM_N, 0, MLKEM_Q))
72+
);
6673

6774
#define mlk_poly_tomont_asm MLK_NAMESPACE(poly_tomont_asm)
6875
void mlk_poly_tomont_asm(int16_t *p)

mlkem/native/aarch64/src/arith_native_aarch64.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,14 @@ __contract__(
6262
);
6363

6464
#define mlk_poly_reduce_asm MLK_NAMESPACE(poly_reduce_asm)
65-
void mlk_poly_reduce_asm(int16_t *);
65+
void mlk_poly_reduce_asm(int16_t *p)
66+
/* This must be kept in sync with the HOL-Light specification
67+
* in proofs/hol_light/arm/proofs/mlkem_poly_reduce.ml */
68+
__contract__(
69+
requires(memory_no_alias(p, sizeof(int16_t) * MLKEM_N))
70+
assigns(memory_slice(p, sizeof(int16_t) * MLKEM_N))
71+
ensures(array_bound(p, 0, MLKEM_N, 0, MLKEM_Q))
72+
);
6673

6774
#define mlk_poly_tomont_asm MLK_NAMESPACE(poly_tomont_asm)
6875
void mlk_poly_tomont_asm(int16_t *p)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright (c) The mlkem-native project authors
2+
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
3+
4+
include ../Makefile_params.common
5+
6+
HARNESS_ENTRY = harness
7+
HARNESS_FILE = poly_reduce_native_aarch64_harness
8+
9+
# This should be a unique identifier for this proof, and will appear on the
10+
# Litani dashboard. It can be human-readable and contain spaces if you wish.
11+
PROOF_UID = poly_reduce_native_aarch64
12+
13+
# We need to set MLK_CHECK_APIS as otherwise mlkem/native/api.h won't be
14+
# included, which contains the CBMC specifications.
15+
DEFINES += -DMLK_CONFIG_USE_NATIVE_BACKEND_ARITH -DMLK_CONFIG_ARITH_BACKEND_FILE="\"$(SRCDIR)/mlkem/native/aarch64/meta.h\"" -DMLK_CHECK_APIS
16+
INCLUDES +=
17+
18+
REMOVE_FUNCTION_BODY +=
19+
UNWINDSET +=
20+
21+
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
22+
PROJECT_SOURCES += $(SRCDIR)/mlkem/poly.c
23+
24+
CHECK_FUNCTION_CONTRACTS=mlk_poly_reduce_native
25+
USE_FUNCTION_CONTRACTS=mlk_poly_reduce_asm
26+
APPLY_LOOP_CONTRACTS=on
27+
USE_DYNAMIC_FRAMES=1
28+
29+
# Disable any setting of EXTERNAL_SAT_SOLVER, and choose SMT backend instead
30+
EXTERNAL_SAT_SOLVER=
31+
CBMCFLAGS=--smt2
32+
33+
FUNCTION_NAME = poly_reduce_native_aarch64
34+
35+
# If this proof is found to consume huge amounts of RAM, you can set the
36+
# EXPENSIVE variable. With new enough versions of the proof tools, this will
37+
# restrict the number of EXPENSIVE CBMC jobs running at once. See the
38+
# documentation in Makefile.common under the "Job Pools" heading for details.
39+
# EXPENSIVE = true
40+
41+
# This function is large enough to need...
42+
CBMC_OBJECT_BITS = 8
43+
44+
# If you require access to a file-local ("static") function or object to conduct
45+
# your proof, set the following (and do not include the original source file
46+
# ("mlkem/poly.c") in PROJECT_SOURCES).
47+
# REWRITTEN_SOURCES = $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i
48+
# include ../Makefile.common
49+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_SOURCE = $(SRCDIR)/mlkem/poly.c
50+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_FUNCTIONS = foo bar
51+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_OBJECTS = baz
52+
# Care is required with variables on the left-hand side: REWRITTEN_SOURCES must
53+
# be set before including Makefile.common, but any use of variables on the
54+
# left-hand side requires those variables to be defined. Hence, _SOURCE,
55+
# _FUNCTIONS, _OBJECTS is set after including Makefile.common.
56+
57+
include ../Makefile.common
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) The mlkem-native project authors
2+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
// SPDX-License-Identifier: MIT-0
4+
5+
#include <stdint.h>
6+
#include "cbmc.h"
7+
#include "params.h"
8+
9+
void mlk_poly_reduce_native(int16_t p[MLKEM_N]);
10+
11+
void harness(void)
12+
{
13+
int16_t *r;
14+
mlk_poly_reduce_native(r);
15+
}

proofs/hol_light/arm/proofs/mlkem_poly_reduce.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ let overall_lemma = prove
118118
REWRITE_TAC[MATCH_MP lemma_rem (CONGBOUND_RULE `barred x`)] THEN
119119
BITBLAST_TAC);;
120120

121+
(* NOTE: This must be kept in sync with the CBMC specification
122+
* in mlkem/native/aarch64/src/arith_native_aarch64.h *)
123+
121124
let MLKEM_POLY_REDUCE_CORRECT = prove
122125
(`!a x pc.
123126
nonoverlapping (word pc,0x124) (a,512)

0 commit comments

Comments
 (0)