Skip to content

Commit 85e1c57

Browse files
CBMC: Add proofs on top of native functions
(polymat_permute_bitrev_to_custom_native) - Unlike previous commit: 52df632, this commit want to remove the temporary workaround, directly prove polymat_permute_bitrev_custom on top of native API. Co-authored-by: Matthias J. Kannwischer <[email protected]> Signed-off-by: willieyz <[email protected]>
1 parent 52df632 commit 85e1c57

File tree

7 files changed

+30
-117
lines changed

7 files changed

+30
-117
lines changed

mldsa/src/native/api.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ __contract__(
131131
requires(memory_no_alias(p, sizeof(int32_t) * MLDSA_N))
132132
requires(array_bound(p, 0, MLDSA_N, 0, MLDSA_Q))
133133
assigns(memory_slice(p, sizeof(int32_t) * MLDSA_N))
134-
ensures(array_bound(p, 0, MLDSA_N, 0, MLDSA_Q)));
134+
ensures(array_bound(p, 0, MLDSA_N, 0, MLDSA_Q))
135+
);
135136
#endif /* MLD_USE_NATIVE_NTT_CUSTOM_ORDER */
136137

137138

mldsa/src/polyvec.c

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
* with native backends, which are currently not yet namespaced. */
2626
#define mld_polymat_permute_bitrev_to_custom \
2727
MLD_ADD_PARAM_SET(mld_polymat_permute_bitrev_to_custom)
28-
#define mld_polyvecl_permute_bitrev_to_custom \
29-
MLD_ADD_PARAM_SET(mld_polyvecl_permute_bitrev_to_custom)
3028
#define mld_polyvecl_pointwise_acc_montgomery_c \
3129
MLD_ADD_PARAM_SET(mld_polyvecl_pointwise_acc_montgomery_c)
3230

@@ -37,36 +35,6 @@
3735
* No-op unless a native backend with a custom ordering is used.
3836
*/
3937

40-
static void mld_polyvecl_permute_bitrev_to_custom(mld_polyvecl *v)
41-
__contract__(
42-
/* We don't specify that this should be a permutation, but only
43-
* that it does not change the bound established at the end of
44-
* mld_polyvec_matrix_expand.
45-
*/
46-
requires(memory_no_alias(v, sizeof(mld_polyvecl)))
47-
requires(forall(x, 0, MLDSA_L,
48-
array_bound(v->vec[x].coeffs, 0, MLDSA_N, 0, MLDSA_Q)))
49-
assigns(memory_slice(v, sizeof(mld_polyvecl)))
50-
ensures(forall(x, 0, MLDSA_L,
51-
array_bound(v->vec[x].coeffs, 0, MLDSA_N, 0, MLDSA_Q))))
52-
{
53-
#if defined(MLD_USE_NATIVE_NTT_CUSTOM_ORDER)
54-
unsigned i;
55-
for (i = 0; i < MLDSA_L; i++)
56-
__loop__(
57-
assigns(i, memory_slice(v, sizeof(mld_polyvecl)))
58-
invariant(i <= MLDSA_L)
59-
invariant(forall(x, 0, MLDSA_L,
60-
array_bound(v->vec[x].coeffs, 0, MLDSA_N, 0, MLDSA_Q))))
61-
{
62-
mld_poly_permute_bitrev_to_custom(v->vec[i].coeffs);
63-
}
64-
#else /* MLD_USE_NATIVE_NTT_CUSTOM_ORDER */
65-
/* Nothing to do */
66-
(void)v;
67-
#endif /* !MLD_USE_NATIVE_NTT_CUSTOM_ORDER */
68-
}
69-
7038
static void mld_polymat_permute_bitrev_to_custom(mld_polymat *mat)
7139
__contract__(
7240
/* We don't specify that this should be a permutation, but only
@@ -81,16 +49,27 @@ __contract__(
8149
array_bound(mat->vec[k1].vec[l1].coeffs, 0, MLDSA_N, 0, MLDSA_Q))))
8250
)
8351
{
52+
#if defined(MLD_USE_NATIVE_NTT_CUSTOM_ORDER)
53+
/* TODO: proof */
8454
unsigned int i;
85-
for (i = 0; i < MLDSA_K; i++)
55+
for (i = 0; i < MLDSA_K * MLDSA_L; i++)
8656
__loop__(
8757
assigns(i, memory_slice(mat, sizeof(mld_polymat)))
88-
invariant(i <= MLDSA_K)
58+
invariant(i <= MLDSA_K * MLDSA_L)
8959
invariant(forall(k1, 0, MLDSA_K, forall(l1, 0, MLDSA_L,
90-
array_bound(mat->vec[k1].vec[l1].coeffs, 0, MLDSA_N, 0, MLDSA_Q)))))
60+
array_bound(mat->vec[k1].vec[l1].coeffs, 0, MLDSA_N, 0, MLDSA_Q))))
61+
)
9162
{
92-
mld_polyvecl_permute_bitrev_to_custom(&mat->vec[i]);
63+
mld_poly_permute_bitrev_to_custom(
64+
mat->vec[i / MLDSA_L].vec[i % MLDSA_L].coeffs);
9365
}
66+
67+
#else /* MLD_USE_NATIVE_NTT_CUSTOM_ORDER */
68+
69+
/* Nothing to do */
70+
((void)mat);
71+
72+
#endif /* !MLD_USE_NATIVE_NTT_CUSTOM_ORDER */
9473
}
9574
#endif /* !MLD_CONFIG_REDUCE_RAM */
9675

@@ -951,5 +930,4 @@ void mld_polyveck_unpack_t0(mld_polyveck *p,
951930
/* To facilitate single-compilation-unit (SCU) builds, undefine all macros.
952931
* Don't modify by hand -- this is auto-generated by scripts/autogen. */
953932
#undef mld_polymat_permute_bitrev_to_custom
954-
#undef mld_polyvecl_permute_bitrev_to_custom
955933
#undef mld_polyvecl_pointwise_acc_montgomery_c

proofs/cbmc/polymat_permute_bitrev_to_custom/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
2020
PROJECT_SOURCES += $(SRCDIR)/mldsa/src/polyvec.c
2121

2222
CHECK_FUNCTION_CONTRACTS=mld_polymat_permute_bitrev_to_custom
23-
USE_FUNCTION_CONTRACTS=mld_polyvecl_permute_bitrev_to_custom
23+
USE_FUNCTION_CONTRACTS=
2424
APPLY_LOOP_CONTRACTS=on
2525
USE_DYNAMIC_FRAMES=1
2626

proofs/cbmc/polyvecl_permute_bitrev_to_custom_native/Makefile renamed to proofs/cbmc/polymat_permute_bitrev_to_custom_native/Makefile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,43 @@
1-
# Copyright (c) The mlkem-native project authors
21
# Copyright (c) The mldsa-native project authors
32
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
43

54
include ../Makefile_params.common
65

76
HARNESS_ENTRY = harness
8-
HARNESS_FILE = polyvecl_permute_bitrev_to_custom_native_harness
7+
HARNESS_FILE = polymat_permute_bitrev_to_custom_native_harness
98

109
# This should be a unique identifier for this proof, and will appear on the
1110
# Litani dashboard. It can be human-readable and contain spaces if you wish.
12-
PROOF_UID = mld_polyvecl_permute_bitrev_to_custom_native
11+
PROOF_UID = polymat_permute_bitrev_to_custom_native
1312

1413
DEFINES += -DMLD_CONFIG_USE_NATIVE_BACKEND_ARITH -DMLD_CONFIG_ARITH_BACKEND_FILE="\"dummy_backend.h\""
1514
INCLUDES +=
16-
UNWINDSET +=
1715

1816
REMOVE_FUNCTION_BODY +=
17+
UNWINDSET +=
1918

2019
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
2120
PROJECT_SOURCES += $(SRCDIR)/mldsa/src/polyvec.c
2221

23-
CHECK_FUNCTION_CONTRACTS=mld_polyvecl_permute_bitrev_to_custom
24-
USE_FUNCTION_CONTRACTS= mld_poly_permute_bitrev_to_custom
22+
CHECK_FUNCTION_CONTRACTS=mld_polymat_permute_bitrev_to_custom
23+
USE_FUNCTION_CONTRACTS=mld_poly_permute_bitrev_to_custom
2524
APPLY_LOOP_CONTRACTS=on
2625
USE_DYNAMIC_FRAMES=1
2726

2827
# Disable any setting of EXTERNAL_SAT_SOLVER, and choose SMT backend instead
2928
EXTERNAL_SAT_SOLVER=
3029
CBMCFLAGS=--smt2 --slice-formula --no-array-field-sensitivity
3130

32-
FUNCTION_NAME = mld_polyvecl_permute_bitrev_to_custom_native
31+
FUNCTION_NAME = polymat_permute_bitrev_to_custom_native
3332

3433
# If this proof is found to consume huge amounts of RAM, you can set the
3534
# EXPENSIVE variable. With new enough versions of the proof tools, this will
3635
# restrict the number of EXPENSIVE CBMC jobs running at once. See the
3736
# documentation in Makefile.common under the "Job Pools" heading for details.
3837
# EXPENSIVE = true
39-
CBMC_OBJECT_BITS = 10
38+
39+
# This function is large enough to need...
40+
CBMC_OBJECT_BITS = 12
4041

4142
# If you require access to a file-local ("static") function or object to conduct
4243
# your proof, set the following (and do not include the original source file

proofs/cbmc/polyvecl_permute_bitrev_to_custom/polyvecl_permute_bitrev_to_custom_harness.c renamed to proofs/cbmc/polymat_permute_bitrev_to_custom_native/polymat_permute_bitrev_to_custom_native_harness.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
#include "polyvec.h"
55

6-
void mld_polyvecl_permute_bitrev_to_custom(mld_polyvecl *v);
6+
void mld_polymat_permute_bitrev_to_custom(mld_polymat *mat);
77

88
void harness(void)
99
{
10-
mld_polyvecl *v;
11-
mld_polyvecl_permute_bitrev_to_custom(v);
10+
mld_polymat *mat;
11+
mld_polymat_permute_bitrev_to_custom(mat);
1212
}

proofs/cbmc/polyvecl_permute_bitrev_to_custom/Makefile

Lines changed: 0 additions & 55 deletions
This file was deleted.

proofs/cbmc/polyvecl_permute_bitrev_to_custom_native/polyvecl_permute_bitrev_to_custom_native_harness.c

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)