Skip to content

CBMC: Don't declare structures in harnesses #1039

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

Merged
merged 1 commit into from
May 21, 2025
Merged

Conversation

hanno-becker
Copy link
Contributor

When CBMC checks a function contract, it seems that the preconditions set out in the contract are overlayed by the context set out in the harness. For example, if a function takes a pointer to foo, and the harness passes &f for foo f, then the function would never be evaluated for the possibility of an invalid pointer being passed. For that reason, harnesses must be as minimal as possible, merely declaring uninitialized variables of the expected type and calling the function under proof.

This commit fixes a few instances in mlkem-native where this was not yet the case.

@hanno-becker hanno-becker requested a review from a team as a code owner May 21, 2025 03:59
@hanno-becker hanno-becker added bug Something isn't working CBMC labels May 21, 2025
@hanno-becker hanno-becker requested a review from mkannwischer May 21, 2025 03:59
@hanno-becker hanno-becker added this to the v1 milestone May 21, 2025
@hanno-becker hanno-becker changed the title CBMC: Don't declare arrays in harnesses CBMC: Don't declare structures in harnesses May 21, 2025
Copy link
Contributor

@mkannwischer mkannwischer left a comment

Choose a reason for hiding this comment

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

Thanks @hanno-becker for fixing this.
Note that this was uncovered during proof development in mldsa-native: pq-code-package/mldsa-native#254

When CBMC checks a function contract, it seems that the preconditions
set out in the contract are overlayed by the context set out in the
harness. For example, if a function takes a pointer to `foo`, and the
harness passes `&f` for `foo f`, then the function would never be
evaluated for the possibility of an invalid pointer being passed.
For that reason, harnesses must be as minimal as possible, merely
declaring uninitialized variables of the expected type and calling
the function under proof.

This commit fixes a few instances in mlkem-native where this was
not yet the case.

Signed-off-by: Hanno Becker <[email protected]>
@hanno-becker hanno-becker merged commit 97bfbfa into main May 21, 2025
269 checks passed
@hanno-becker hanno-becker deleted the cbmc_harness_fix branch May 21, 2025 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working CBMC
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants