Skip to content

Commit 4f1c175

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

File tree

5 files changed

+93
-4
lines changed

5 files changed

+93
-4
lines changed

mldsa/src/native/api.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,15 @@ __contract__(
423423
* Arguments: - int32_t *r: pointer to output polynomial
424424
* - const uint8_t *a: byte array with bit-packed polynomial
425425
**************************************************/
426-
static MLD_INLINE int mld_polyz_unpack_17_native(int32_t *r, const uint8_t *a);
426+
static MLD_INLINE int mld_polyz_unpack_17_native(int32_t *r, const uint8_t *a)
427+
__contract__(
428+
requires(memory_no_alias(r, sizeof(int32_t) * MLDSA_N))
429+
requires(memory_no_alias(a, MLDSA_POLYZ_PACKEDBYTES))
430+
assigns(memory_slice(r, sizeof(int32_t) * MLDSA_N))
431+
ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
432+
ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_bound(r, 0, MLDSA_N, -(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1 + 1))
433+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(r, MLDSA_N))
434+
);
427435
#endif /* MLD_USE_NATIVE_POLYZ_UNPACK_17 */
428436

429437
#if defined(MLD_USE_NATIVE_POLYZ_UNPACK_19)
@@ -437,7 +445,15 @@ static MLD_INLINE int mld_polyz_unpack_17_native(int32_t *r, const uint8_t *a);
437445
* Arguments: - int32_t *r: pointer to output polynomial
438446
* - const uint8_t *a: byte array with bit-packed polynomial
439447
**************************************************/
440-
static MLD_INLINE int mld_polyz_unpack_19_native(int32_t *r, const uint8_t *a);
448+
static MLD_INLINE int mld_polyz_unpack_19_native(int32_t *r, const uint8_t *a)
449+
__contract__(
450+
requires(memory_no_alias(r, sizeof(int32_t) * MLDSA_N))
451+
requires(memory_no_alias(a, MLDSA_POLYZ_PACKEDBYTES))
452+
assigns(memory_slice(r, sizeof(int32_t) * MLDSA_N))
453+
ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
454+
ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_bound(r, 0, MLDSA_N, -(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1 + 1))
455+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(r, MLDSA_N))
456+
);
441457
#endif /* MLD_USE_NATIVE_POLYZ_UNPACK_19 */
442458

443459
#if defined(MLD_USE_NATIVE_POINTWISE_MONTGOMERY)

mldsa/src/poly_kl.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,6 @@ MLD_INTERNAL_API
861861
void mld_polyz_unpack(mld_poly *r, const uint8_t a[MLDSA_POLYZ_PACKEDBYTES])
862862
{
863863
#if defined(MLD_USE_NATIVE_POLYZ_UNPACK_17) && MLD_CONFIG_PARAMETER_SET == 44
864-
/* TODO: proof */
865864
int ret;
866865
ret = mld_polyz_unpack_17_native(r->coeffs, a);
867866
if (ret == MLD_NATIVE_FUNC_SUCCESS)
@@ -871,7 +870,6 @@ void mld_polyz_unpack(mld_poly *r, const uint8_t a[MLDSA_POLYZ_PACKEDBYTES])
871870
}
872871
#elif defined(MLD_USE_NATIVE_POLYZ_UNPACK_19) && \
873872
(MLD_CONFIG_PARAMETER_SET == 65 || MLD_CONFIG_PARAMETER_SET == 87)
874-
/* TODO: proof */
875873
int ret;
876874
ret = mld_polyz_unpack_19_native(r->coeffs, a);
877875
if (ret == MLD_NATIVE_FUNC_SUCCESS)

proofs/cbmc/dummy_backend.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#define MLD_USE_NATIVE_POLY_USE_HINT_32
1919
#define MLD_USE_NATIVE_POLY_USE_HINT_88
2020
#define MLD_USE_NATIVE_POLY_CHKNORM
21+
#define MLD_USE_NATIVE_POLYZ_UNPACK_17
22+
#define MLD_USE_NATIVE_POLYZ_UNPACK_19
2123

2224
#include "../../mldsa/src/native/api.h"
2325

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

0 commit comments

Comments
 (0)