Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve speed of proof of matvec_mul() #408

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 3 additions & 4 deletions cbmc/proofs/matvec_mul/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@ DEFINES +=
INCLUDES +=

REMOVE_FUNCTION_BODY +=
UNWINDSET += matvec_mul.0:4 # Maximum value of MLKEM_K

PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
PROJECT_SOURCES += $(SRCDIR)/mlkem/indcpa.c

CHECK_FUNCTION_CONTRACTS=matvec_mul
USE_FUNCTION_CONTRACTS=$(MLKEM_NAMESPACE)polyvec_mulcache_compute $(MLKEM_NAMESPACE)polyvec_basemul_acc_montgomery_cached
USE_FUNCTION_CONTRACTS=$(MLKEM_NAMESPACE)polyvec_basemul_acc_montgomery_cached
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
CBMCFLAGS=--smt2 --no-array-field-sensitivity --arrays-uf-always --slice-formula

FUNCTION_NAME = $(MLKEM_NAMESPACE)matvec_mul

Expand All @@ -36,7 +35,7 @@ FUNCTION_NAME = $(MLKEM_NAMESPACE)matvec_mul
# EXPENSIVE = true

# This function is large enough to need...
CBMC_OBJECT_BITS = 10
CBMC_OBJECT_BITS = 8

# 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
Expand Down
11 changes: 7 additions & 4 deletions mlkem/indcpa.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void gen_matrix_entry(poly *entry,
while (ctr < MLKEM_N) // clang-format off
ASSIGNS(ctr, state, OBJECT_UPTO(entry, sizeof(poly)), OBJECT_WHOLE(buf))
INVARIANT(0 <= ctr && ctr <= MLKEM_N)
INVARIANT(ctr > 0 ==> ARRAY_BOUND(entry->coeffs, 0, ctr - 1,
INVARIANT(ctr > 0 ==> ARRAY_BOUND(entry->coeffs, 0, ctr - 1,
0, (MLKEM_Q - 1))) // clang-format on
{
shake128_squeezeblocks(buf, 1, &state);
Expand Down Expand Up @@ -342,9 +342,12 @@ void matvec_mul(polyvec *out, const polyvec a[MLKEM_K], const polyvec *v,
ASSIGNS(OBJECT_WHOLE(out))
// clang-format on
{
for (int i = 0; i < MLKEM_K; i++) {
polyvec_basemul_acc_montgomery_cached(&out->vec[i], &a[i], v, vc);
}
for (int i = 0; i < MLKEM_K; i++) // clang-format off
ASSIGNS(i, OBJECT_WHOLE(out))
INVARIANT(i >= 0 && i <= MLKEM_K) // clang-format on
{
polyvec_basemul_acc_montgomery_cached(&out->vec[i], &a[i], v, vc);
}
}

/*************************************************
Expand Down