Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion mldsa/src/native/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,17 @@ set if there are native implementations for NTT and INTT."
* Arguments: - int32_t p[MLDSA_N]: pointer to in/output polynomial
*
**************************************************/
static MLD_INLINE void mld_poly_permute_bitrev_to_custom(int32_t p[MLDSA_N]);
static MLD_INLINE void mld_poly_permute_bitrev_to_custom(int32_t p[MLDSA_N])
__contract__(
/* We don't specify that this should be a permutation, but only
* that it does not change the bound established at the end of
* mld_polyvec_matrix_expand.
*/
requires(memory_no_alias(p, sizeof(int32_t) * MLDSA_N))
requires(array_bound(p, 0, MLDSA_N, 0, MLDSA_Q))
assigns(memory_slice(p, sizeof(int32_t) * MLDSA_N))
ensures(array_bound(p, 0, MLDSA_N, 0, MLDSA_Q))
);
#endif /* MLD_USE_NATIVE_NTT_CUSTOM_ORDER */


Expand Down
15 changes: 14 additions & 1 deletion mldsa/src/polyvec.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,24 @@ __contract__(
)
{
#if defined(MLD_USE_NATIVE_NTT_CUSTOM_ORDER)
/* TODO: proof */

unsigned int i, j;
for (i = 0; i < MLDSA_K; i++)
__loop__(
assigns(i, j, memory_slice(mat, sizeof(mld_polymat)))
invariant(i <= MLDSA_K)
invariant(forall(k1, 0, MLDSA_K, forall(l1, 0, MLDSA_L,
array_bound(mat->vec[k1].vec[l1].coeffs, 0, MLDSA_N, 0, MLDSA_Q))))
)
{
for (j = 0; j < MLDSA_L; j++)
__loop__(
assigns(j, memory_slice(mat, sizeof(mld_polymat)))
invariant(i <= MLDSA_K)
invariant(j <= MLDSA_L)
invariant(forall(k2, 0, MLDSA_K, forall(l2, 0, MLDSA_L,
array_bound(mat->vec[k2].vec[l2].coeffs, 0, MLDSA_N, 0, MLDSA_Q))))
)
{
mld_poly_permute_bitrev_to_custom(mat->vec[i].vec[j].coeffs);
}
Expand Down
6 changes: 3 additions & 3 deletions nix/cbmc/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ buildEnv {
cbmc = cbmc.overrideAttrs (old: rec {
version = "6.8.0";
src = fetchFromGitHub {
owner = "diffblue";
owner = "tautschnig";
repo = "cbmc";
hash = "sha256-PT6AYiwkplCeyMREZnGZA0BKl4ZESRC02/9ibKg7mYU=";
tag = "cbmc-6.8.0";
hash = "sha256-ng1zjICpmoHUWkG1PuLRmLtaUBmEALpRgNEpbsrnMV8=";
rev = "4f514dbd70c89e3bae03a59f1dc9837acf25885c";
};
});
litani = callPackage ./litani.nix { }; # 1.29.0
Expand Down
55 changes: 55 additions & 0 deletions proofs/cbmc/polymat_permute_bitrev_to_custom_native/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright (c) The mldsa-native project authors
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT

include ../Makefile_params.common

HARNESS_ENTRY = harness
HARNESS_FILE = polymat_permute_bitrev_to_custom_native_harness

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

DEFINES += -DMLD_CONFIG_USE_NATIVE_BACKEND_ARITH -DMLD_CONFIG_ARITH_BACKEND_FILE="\"dummy_backend.h\""
INCLUDES +=

REMOVE_FUNCTION_BODY +=
UNWINDSET +=

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

CHECK_FUNCTION_CONTRACTS=mld_polymat_permute_bitrev_to_custom
USE_FUNCTION_CONTRACTS=mld_poly_permute_bitrev_to_custom
APPLY_LOOP_CONTRACTS=on
USE_DYNAMIC_FRAMES=1

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

FUNCTION_NAME = polymat_permute_bitrev_to_custom_native

# If this proof is found to consume huge amounts of RAM, you can set the
# EXPENSIVE variable. With new enough versions of the proof tools, this will
# restrict the number of EXPENSIVE CBMC jobs running at once. See the
# documentation in Makefile.common under the "Job Pools" heading for details.
# EXPENSIVE = true

# This function is large enough to need...
CBMC_OBJECT_BITS = 12

# If you require access to a file-local ("static") function or object to conduct
# your proof, set the following (and do not include the original source file
# ("mldsa/poly.c") in PROJECT_SOURCES).
# REWRITTEN_SOURCES = $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i
# include ../Makefile.common
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_SOURCE = $(SRCDIR)/mldsa/poly.c
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_FUNCTIONS = foo bar
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_OBJECTS = baz
# Care is required with variables on the left-hand side: REWRITTEN_SOURCES must
# be set before including Makefile.common, but any use of variables on the
# left-hand side requires those variables to be defined. Hence, _SOURCE,
# _FUNCTIONS, _OBJECTS is set after including Makefile.common.

include ../Makefile.common
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) The mldsa-native project authors
// SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT

#include "polyvec.h"

void mld_polymat_permute_bitrev_to_custom(mld_polymat *mat);

void harness(void)
{
mld_polymat *mat;
mld_polymat_permute_bitrev_to_custom(mat);
}
3 changes: 3 additions & 0 deletions scripts/check-contracts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def gen_contracts():
def is_exception(funcname):
# The functions passing this filter are known not to have a proof

if funcname == 'poly_permute_bitrev_to_custom':
return True

if funcname.endswith("_native") or funcname.endswith("_asm"):
# CBMC proofs are axiomatized against contracts of the backends
return True
Expand Down
Loading