Skip to content

Commit 788bd93

Browse files
willieyzmkannwischer
authored andcommitted
CBMC: Add proofs on top of native functions (mld_poly_pointwise_montgomery_native)
- This commit adds CBMC proofs for the native function `mld_poly_pointwise_montgomery_native`, called `poly_pointwise_montgomery_native` - This following changes are include: - Apply the same harness file and construct function contract, reference from `poly_pointwise_montgomery`. - Use the following function contracts: - `mld_poly_pointwise_montgomery_native` - `mld_poly_pointwise_montgomery_c` - Add `MLD_USE_NATIVE_POINTWISE_MONTGOMERY` in dummy_backend.h Signed-off-by: willieyz <willie.zhao@chelpis.com>
1 parent 4f1c175 commit 788bd93

File tree

5 files changed

+80
-2
lines changed

5 files changed

+80
-2
lines changed

mldsa/src/native/api.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,20 @@ __contract__(
471471
* - const int32_t b[MLDSA_N]: second input polynomial
472472
**************************************************/
473473
static MLD_INLINE int mld_poly_pointwise_montgomery_native(
474-
int32_t c[MLDSA_N], const int32_t a[MLDSA_N], const int32_t b[MLDSA_N]);
474+
int32_t c[MLDSA_N], const int32_t a[MLDSA_N], const int32_t b[MLDSA_N])
475+
__contract__(
476+
requires(memory_no_alias(a, sizeof(int32_t) * MLDSA_N))
477+
requires(memory_no_alias(b, sizeof(int32_t) * MLDSA_N))
478+
requires(memory_no_alias(c, sizeof(int32_t) * MLDSA_N))
479+
requires(array_abs_bound(a, 0, MLDSA_N, MLD_NTT_BOUND))
480+
requires(array_abs_bound(b, 0, MLDSA_N, MLD_NTT_BOUND))
481+
assigns(memory_slice(c, sizeof(int32_t) * MLDSA_N))
482+
ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
483+
ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_abs_bound(c, 0, MLDSA_N, MLDSA_Q))
484+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_abs_bound(a, 0, MLDSA_N, MLD_NTT_BOUND))
485+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_abs_bound(b, 0, MLDSA_N, MLD_NTT_BOUND))
486+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(c, MLDSA_N))
487+
);
475488
#endif /* MLD_USE_NATIVE_POINTWISE_MONTGOMERY */
476489

477490
#if defined(MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L4)

mldsa/src/poly.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ void mld_poly_pointwise_montgomery(mld_poly *c, const mld_poly *a,
244244
const mld_poly *b)
245245
{
246246
#if defined(MLD_USE_NATIVE_POINTWISE_MONTGOMERY)
247-
/* TODO: proof */
248247
int ret;
249248
mld_assert_abs_bound(a->coeffs, MLDSA_N, MLD_NTT_BOUND);
250249
mld_assert_abs_bound(b->coeffs, MLDSA_N, MLD_NTT_BOUND);

proofs/cbmc/dummy_backend.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define MLD_USE_NATIVE_POLY_CHKNORM
2121
#define MLD_USE_NATIVE_POLYZ_UNPACK_17
2222
#define MLD_USE_NATIVE_POLYZ_UNPACK_19
23+
#define MLD_USE_NATIVE_POINTWISE_MONTGOMERY
2324

2425
#include "../../mldsa/src/native/api.h"
2526

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright (c) The mldsa-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_pointwise_montgomery_native_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_pointwise_montgomery_native
12+
13+
DEFINES += -DMLD_CONFIG_USE_NATIVE_BACKEND_ARITH -DMLD_CONFIG_ARITH_BACKEND_FILE="\"dummy_backend.h\""
14+
INCLUDES +=
15+
16+
REMOVE_FUNCTION_BODY +=
17+
UNWINDSET +=
18+
19+
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
20+
PROJECT_SOURCES += $(SRCDIR)/mldsa/src/poly.c
21+
22+
CHECK_FUNCTION_CONTRACTS=$(MLD_NAMESPACE)poly_pointwise_montgomery
23+
USE_FUNCTION_CONTRACTS=mld_poly_pointwise_montgomery_native mld_poly_pointwise_montgomery_c
24+
APPLY_LOOP_CONTRACTS=on
25+
USE_DYNAMIC_FRAMES=1
26+
27+
# Disable any setting of EXTERNAL_SAT_SOLVER, and choose SMT backend instead
28+
EXTERNAL_SAT_SOLVER=
29+
CBMCFLAGS=--smt2
30+
31+
FUNCTION_NAME = poly_pointwise_montgomery_native
32+
33+
# If this proof is found to consume huge amounts of RAM, you can set the
34+
# EXPENSIVE variable. With new enough versions of the proof tools, this will
35+
# restrict the number of EXPENSIVE CBMC jobs running at once. See the
36+
# documentation in Makefile.common under the "Job Pools" heading for details.
37+
# EXPENSIVE = true
38+
39+
# This function is large enough to need...
40+
CBMC_OBJECT_BITS = 10
41+
42+
# If you require access to a file-local ("static") function or object to conduct
43+
# your proof, set the following (and do not include the original source file
44+
# ("mldsa/poly.c") in PROJECT_SOURCES).
45+
# REWRITTEN_SOURCES = $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i
46+
# include ../Makefile.common
47+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_SOURCE = $(SRCDIR)/mldsa/src/poly.c
48+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_FUNCTIONS = foo bar
49+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_OBJECTS = baz
50+
# Care is required with variables on the left-hand side: REWRITTEN_SOURCES must
51+
# be set before including Makefile.common, but any use of variables on the
52+
# left-hand side requires those variables to be defined. Hence, _SOURCE,
53+
# _FUNCTIONS, _OBJECTS is set after including Makefile.common.
54+
55+
include ../Makefile.common
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright (c) The mldsa-native project authors
2+
// SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
3+
4+
#include "poly.h"
5+
6+
void harness(void)
7+
{
8+
mld_poly *a, *b, *c;
9+
mld_poly_pointwise_montgomery(c, a, b);
10+
}

0 commit comments

Comments
 (0)