Skip to content

Commit 015e66d

Browse files
willieyzmkannwischer
authored andcommitted
CBMC: Add proofs on top of native functions (poly_use_hint_native)
- This commit adds CBMC proofs for following the native function: `mld_poly_use_hint_32_native`, `mld_poly_use_hint_88_native`. called `poly_use_hint_native`. - This following changes are include: - Apply the same harness file and construct function contract reference from `poly_use_hint`. - Use the following function contracts: - mld_poly_use_hint_c - mld_poly_use_hint_32_native - mld_poly_use_hint_88_native - Add `MLD_USE_NATIVE_POLY_USE_HINT_32`, `MLD_USE_NATIVE_POLY_USE_HINT_88` in dummy_backend.h Signed-off-by: willieyz <willie.zhao@chelpis.com>
1 parent 95f5b95 commit 015e66d

File tree

5 files changed

+99
-4
lines changed

5 files changed

+99
-4
lines changed

mldsa/src/native/api.h

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,18 @@ __contract__(
342342
* - const int32_t *h: pointer to input hint polynomial
343343
**************************************************/
344344
static MLD_INLINE int mld_poly_use_hint_32_native(int32_t *b, const int32_t *a,
345-
const int32_t *h);
345+
const int32_t *h)
346+
__contract__(
347+
requires(memory_no_alias(a, sizeof(int32_t) * MLDSA_N))
348+
requires(memory_no_alias(b, sizeof(int32_t) * MLDSA_N))
349+
requires(memory_no_alias(h, sizeof(int32_t) * MLDSA_N))
350+
requires(array_bound(a, 0, MLDSA_N, 0, MLDSA_Q))
351+
requires(array_bound(h, 0, MLDSA_N, 0, 2))
352+
assigns(memory_slice(b, sizeof(int32_t) * MLDSA_N))
353+
ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
354+
ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_bound(b, 0, MLDSA_N, 0, (MLDSA_Q-1)/(2*MLDSA_GAMMA2)))
355+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(b, MLDSA_N))
356+
);
346357
#endif /* MLD_USE_NATIVE_POLY_USE_HINT_32 */
347358

348359
#if defined(MLD_USE_NATIVE_POLY_USE_HINT_88)
@@ -358,7 +369,18 @@ static MLD_INLINE int mld_poly_use_hint_32_native(int32_t *b, const int32_t *a,
358369
* - const int32_t *h: pointer to input hint polynomial
359370
**************************************************/
360371
static MLD_INLINE int mld_poly_use_hint_88_native(int32_t *b, const int32_t *a,
361-
const int32_t *h);
372+
const int32_t *h)
373+
__contract__(
374+
requires(memory_no_alias(a, sizeof(int32_t) * MLDSA_N))
375+
requires(memory_no_alias(b, sizeof(int32_t) * MLDSA_N))
376+
requires(memory_no_alias(h, sizeof(int32_t) * MLDSA_N))
377+
requires(array_bound(a, 0, MLDSA_N, 0, MLDSA_Q))
378+
requires(array_bound(h, 0, MLDSA_N, 0, 2))
379+
assigns(memory_slice(b, sizeof(int32_t) * MLDSA_N))
380+
ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
381+
ensures((return_value == MLD_NATIVE_FUNC_SUCCESS) ==> array_bound(b, 0, MLDSA_N, 0, (MLDSA_Q-1)/(2*MLDSA_GAMMA2)))
382+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged(b, MLDSA_N))
383+
);
362384
#endif /* MLD_USE_NATIVE_POLY_USE_HINT_88 */
363385

364386
#if defined(MLD_USE_NATIVE_POLY_CHKNORM)

mldsa/src/poly_kl.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ void mld_poly_use_hint(mld_poly *b, const mld_poly *a, const mld_poly *h)
158158
int ret;
159159
mld_assert_bound(a->coeffs, MLDSA_N, 0, MLDSA_Q);
160160
mld_assert_bound(h->coeffs, MLDSA_N, 0, 2);
161-
/* TODO: proof */
162161
ret = mld_poly_use_hint_88_native(b->coeffs, a->coeffs, h->coeffs);
163162
if (ret == MLD_NATIVE_FUNC_SUCCESS)
164163
{
@@ -170,7 +169,6 @@ void mld_poly_use_hint(mld_poly *b, const mld_poly *a, const mld_poly *h)
170169
int ret;
171170
mld_assert_bound(a->coeffs, MLDSA_N, 0, MLDSA_Q);
172171
mld_assert_bound(h->coeffs, MLDSA_N, 0, 2);
173-
/* TODO: proof */
174172
ret = mld_poly_use_hint_32_native(b->coeffs, a->coeffs, h->coeffs);
175173
if (ret == MLD_NATIVE_FUNC_SUCCESS)
176174
{

proofs/cbmc/dummy_backend.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#define MLD_USE_NATIVE_POLY_DECOMPOSE_32
1616
#define MLD_USE_NATIVE_POLY_DECOMPOSE_88
1717
#define MLD_USE_NATIVE_POLY_CADDQ
18+
#define MLD_USE_NATIVE_POLY_USE_HINT_32
19+
#define MLD_USE_NATIVE_POLY_USE_HINT_88
1820

1921
#include "../../mldsa/src/native/api.h"
2022

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 = poly_use_hint_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_use_hint_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)poly_use_hint
23+
USE_FUNCTION_CONTRACTS=mld_poly_use_hint_c
24+
ifeq ($(MLD_CONFIG_PARAMETER_SET),44)
25+
USE_FUNCTION_CONTRACTS+=mld_poly_use_hint_88_native
26+
else ifeq ($(MLD_CONFIG_PARAMETER_SET),65)
27+
USE_FUNCTION_CONTRACTS+=mld_poly_use_hint_32_native
28+
else ifeq ($(MLD_CONFIG_PARAMETER_SET),87)
29+
USE_FUNCTION_CONTRACTS+=mld_poly_use_hint_32_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 = poly_use_hint_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+
7+
void harness(void)
8+
{
9+
mld_poly *a, *b, *h;
10+
mld_poly_use_hint(b, a, h);
11+
}

0 commit comments

Comments
 (0)