Skip to content

Conversation

mkannwischer
Copy link
Contributor

cassert turns into a CBMC proof assertion inside of CBMC proofs, but it turns into a no-op otherwise.
mld_assert behaves the save inside of CBMC proofs, but also turns into a run-time assertion in debug builds.

@rod-chapman
Copy link
Contributor

What happens when an mld_assert() contains a forall quantifier or something else that isn't executable?

@hanno-becker
Copy link
Contributor

@rod-chapman We have so far managed to avoid that.

@mkannwischer mkannwischer marked this pull request as ready for review July 16, 2025 01:37
@mkannwischer mkannwischer requested a review from a team as a code owner July 16, 2025 01:37
@mkannwischer
Copy link
Contributor Author

What happens when an mld_assert() contains a forall quantifier or something else that isn't executable?

You can make use of mld_assert_bound / mld_assert_abs_bound. If that is insufficient, one can consider adding additional mld_assert_ functions.

@mkannwischer mkannwischer force-pushed the mld_assert branch 2 times, most recently from 1649e77 to b4ac310 Compare July 19, 2025 13:02
mldsa/polyvec.c Outdated
cassert(j == MLDSA_L);
cassert(t >= -(int64_t)MLDSA_L * (MLDSA_Q - 1) * (MLD_NTT_BOUND - 1));
cassert(t <= (int64_t)MLDSA_L * (MLDSA_Q - 1) * (MLD_NTT_BOUND - 1));
mld_assert(j == MLDSA_L);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkannwischer Can we use this opportunity to check if we actually need those asserts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While assertions like these might not be strictly needed for Z3 to prove everything, they sometimes serve as documentation for a new human reader. Imagine someone from (say) TrailOfBits looking at this code for the first time ... such assertions are a chance for the developer to say "Dear reader, here's something important that has to True at this point in the program that might not be obvious..."

Please consider the human reader in evaluating the merits of these cases.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree in principle, but here were merely restate the loop invariant which is just a few lines above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed in this case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing all casserts to check if the CI is still happy.

@@ -17,20 +18,20 @@ void mld_decompose(int32_t *a0, int32_t *a1, int32_t a)
{
*a1 = (a + 127) >> 7;
/* We know a >= 0 and a < MLDSA_Q, so... */
cassert(*a1 >= 0 && *a1 <= 65472);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@mkannwischer
Copy link
Contributor Author

Note that updates in main have introduced additional casserts. Those should be changed to mld_assert (or removed as well).

@hanno-becker hanno-becker force-pushed the mld_assert branch 3 times, most recently from 5a3689b to 5c43700 Compare July 23, 2025 14:15
mkannwischer and others added 2 commits July 23, 2025 16:02
cassert turns into a CBMC proof assertion inside of CBMC proofs, but it
turns into a no-op otherwise.
mld_assert behaves the save inside of CBMC proofs, but also turns into a
run-time assertion in debug builds.

Signed-off-by: Matthias J. Kannwischer <[email protected]>
Signed-off-by: Hanno Becker <[email protected]>
mld_montgomery_reduce() so far had two CBMC specs with varying
input/output bounds. However, it appears that the weak version
is not necessary and can be removed.

Signed-off-by: Hanno Becker <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants