Skip to content

Commit cc0d751

Browse files
committed
Simplify polymat_permite_bitrev_to_customer() (native version)
The code structure now mimics the data structure to make proof tractable. Also updates Makefile for this proof in line with the similar function in mldsa-native. Signed-off-by: Rod Chapman <rodchap@amazon.com>
1 parent 7917874 commit cc0d751

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

mlkem/src/indcpa.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,21 +188,30 @@ __contract__(
188188
requires(memory_no_alias(a, sizeof(mlk_polymat)))
189189
requires(forall(x, 0, MLKEM_K, forall(y, 0, MLKEM_K,
190190
array_bound(a->vec[x].vec[y].coeffs, 0, MLKEM_N, 0, MLKEM_Q))))
191-
assigns(object_whole(a))
191+
assigns(memory_slice(a, sizeof(mlk_polymat)))
192192
ensures(forall(x, 0, MLKEM_K, forall(y, 0, MLKEM_K,
193193
array_bound(a->vec[x].vec[y].coeffs, 0, MLKEM_N, 0, MLKEM_Q)))))
194194
{
195195
#if defined(MLK_USE_NATIVE_NTT_CUSTOM_ORDER)
196-
unsigned i;
197-
for (i = 0; i < MLKEM_K * MLKEM_K; i++)
196+
unsigned i, j;
197+
for (i = 0; i < MLKEM_K; i++)
198198
__loop__(
199-
assigns(i, object_whole(a))
200-
invariant(i <= MLKEM_K * MLKEM_K)
201-
invariant(forall(x, 0, MLKEM_K, forall(y, 0, MLKEM_K,
202-
array_bound(a->vec[x].vec[y].coeffs, 0, MLKEM_N, 0, MLKEM_Q)))))
199+
assigns(i, j, memory_slice(a, sizeof(mlk_polymat)))
200+
invariant(i <= MLKEM_K)
201+
invariant(forall(x2, 0, MLKEM_K, forall(y2, 0, MLKEM_K,
202+
array_bound(a->vec[x2].vec[y2].coeffs, 0, MLKEM_N, 0, MLKEM_Q)))))
203203
{
204-
mlk_poly_permute_bitrev_to_custom(
205-
a->vec[i / MLKEM_K].vec[i % MLKEM_K].coeffs);
204+
for (j = 0; j < MLKEM_K; j++)
205+
__loop__(
206+
assigns(j, memory_slice(a, sizeof(mlk_polymat)))
207+
invariant(i <= MLKEM_K)
208+
invariant(j <= MLKEM_K)
209+
invariant(forall(x3, 0, MLKEM_K, forall(y3, 0, MLKEM_K,
210+
array_bound(a->vec[x3].vec[y3].coeffs, 0, MLKEM_N, 0, MLKEM_Q))))
211+
)
212+
{
213+
mlk_poly_permute_bitrev_to_custom(a->vec[i].vec[j].coeffs);
214+
}
206215
}
207216
#else /* MLK_USE_NATIVE_NTT_CUSTOM_ORDER */
208217
/* Nothing to do */

proofs/cbmc/polymat_permute_bitrev_to_custom_native/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ USE_DYNAMIC_FRAMES=1
2626

2727
# Disable any setting of EXTERNAL_SAT_SOLVER, and choose SMT backend instead
2828
EXTERNAL_SAT_SOLVER=
29-
CBMCFLAGS=--smt2
29+
CBMCFLAGS=--smt2 --slice-formula --no-array-field-sensitivity
3030

3131
FUNCTION_NAME = mlk_polymat_permute_bitrev_to_custom_native
3232

@@ -35,7 +35,7 @@ FUNCTION_NAME = mlk_polymat_permute_bitrev_to_custom_native
3535
# restrict the number of EXPENSIVE CBMC jobs running at once. See the
3636
# documentation in Makefile.common under the "Job Pools" heading for details.
3737
# EXPENSIVE = true
38-
CBMC_OBJECT_BITS = 10
38+
CBMC_OBJECT_BITS = 12
3939

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

0 commit comments

Comments
 (0)