Skip to content

Conversation

@willieyz
Copy link
Contributor

@willieyz willieyz commented Dec 29, 2025

  • Resolve: CBMC: Add proofs atop of native functions #350

  • Related: Refactor mld_polymat_permute_bitrev_to_custom #770

  • This PR refactor the polynomial matrix permutation logic by extracting a reusable mld_polyvecl_permute_bitrev_to_custom function and adds comprehensive CBMC verification for both C and native implementations.

  • This is a temporary workaround until diffblue/cbmc#8796 is resolved.

  • This PR made follwoing changes:

    • Extract mld_polyvecl_permute_bitrev_to_custom from mld_polymat_permute_bitrev_to_custom, and use polyvecl_permute_bitrev_to_custom's function contract in polymat_permute_bitrev_to_custom
    • Add CBMC contracts to mld_poly_permute_bitrev_to_custom in API header
    • Add CBMC proof for mld_polyvecl_permute_bitrev_to_custom (C implementation)
    • Add CBMC proof for mld_polyvecl_permute_bitrev_to_custom_native (native backend)
  • Testing

    • make clean & MLD_CONFIG_PARAMETER_SET=44/65/87 make result checking the contract itself.
    • tests cbmc -p "parrent_proof", this will check the parrent proof

@willieyz willieyz force-pushed the cbmc-bitrev-to-custom-workarounds branch 2 times, most recently from 3246468 to ae1ed8d Compare December 30, 2025 02:49
@willieyz willieyz marked this pull request as ready for review December 31, 2025 03:46
@willieyz willieyz requested a review from a team as a code owner December 31, 2025 03:46
@willieyz willieyz changed the title CBMC: apply same workarounds for mld_polymat_permute_bitrev_to_custom CBMC: Prove mld_polymat_permute_bitrev_to_custom on top of native API Dec 31, 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.

The mld_polymat_permute_bitrev_to_custom needs to call the mld_polyvecl_permute_bitrev_to_custom function by contract, otherwise you are introducing a proof gap that the mld_polymat_permute_bitrev_to_custom isn't actually proven to be safe on top of the native backend.
The same problem exists in mlkem-native and should have been reported there rather than copied to mldsa-native. I opened a PR to fix that: pq-code-package/mlkem-native#1445.

@mkannwischer mkannwischer self-assigned this Jan 1, 2026
@willieyz willieyz force-pushed the cbmc-bitrev-to-custom-workarounds branch from ae1ed8d to 6fef01b Compare January 2, 2026 06:31
@willieyz willieyz requested a review from mkannwischer January 2, 2026 08:44
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.

The code changes look good to me now.

Please clean up the commit message:
(1) The add changes seems to be an artifact of a squashed commit. You may want to use fixup rather than squash in such cases.
(2) From your current commit message no one can understand what you are trying to do. What you are doing is proving mld_polymat_permute_bitrev_to_custom on top of the native API. It should become clear why the refactoring is needed (pointing to the CBMC issue). It's often more important to describe why you are doing something in addition to what you are doing.
(3) The commit message is full of grammatical mistakes making it hard to follow. Please be more careful and consider spell-checking your commit messages.

@willieyz willieyz force-pushed the cbmc-bitrev-to-custom-workarounds branch 2 times, most recently from b959870 to 55a9791 Compare January 5, 2026 02:22
@willieyz
Copy link
Contributor Author

willieyz commented Jan 5, 2026

The code changes look good to me now.

Please clean up the commit message: (1) The add changes seems to be an artifact of a squashed commit. You may want to use fixup rather than squash in such cases. (2) From your current commit message no one can understand what you are trying to do. What you are doing is proving mld_polymat_permute_bitrev_to_custom on top of the native API. It should become clear why the refactoring is needed (pointing to the CBMC issue). It's often more important to describe why you are doing something in addition to what you are doing. (3) The commit message is full of grammatical mistakes making it hard to follow. Please be more careful and consider spell-checking your commit messages.

Hello, Matthias,
The changes have been updated. I have carefully cleaned up the commit history and revised the commit message to more clearly explain the goal, motivation, and reference the relevant CBMC issue.

Really appreciate your guidance and patience in reviewing this. Thank you very much.

@willieyz willieyz requested a review from mkannwischer January 5, 2026 03:13
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 @willieyz! LGTM.

Refactor the polynomial matrix permutation to enable CBMC verification
when using native backend implementations. The current implementation
causes CBMC proof timeouts due to nested loops over two-dimensional
polynomial matrices, similar to the issue described in
(diffblue/cbmc#8796).

This refactoring decomposes the matrix-level operation into vector-level
components with explicit contracts. As a result, CBMC can verify each
component independently, avoiding the nested-loop state explosion while
preserving safety verification for the native backend.

Signed-off-by: willieyz <[email protected]>
@mkannwischer mkannwischer force-pushed the cbmc-bitrev-to-custom-workarounds branch from 55a9791 to 52df632 Compare January 6, 2026 02:46
@mkannwischer mkannwischer merged commit 9551965 into main Jan 6, 2026
333 checks passed
@mkannwischer mkannwischer deleted the cbmc-bitrev-to-custom-workarounds branch January 6, 2026 03:45
mkannwischer added a commit that referenced this pull request Jan 6, 2026
…ry_c

#820 introduced a massive
performance regression to the CBMC proofs caused by the
polyvecl_pointwise_acc_montgomery_c.

This commit increases the OBJECT_BITS for that proof fixing the problem.

Signed-off-by: Matthias J. Kannwischer <[email protected]>
mkannwischer added a commit that referenced this pull request Jan 6, 2026
…ry_c

#820 introduced a massive
performance regression to the CBMC proofs caused by the
polyvecl_pointwise_acc_montgomery_c.

This commit increases the OBJECT_BITS for that proof fixing the problem.

Signed-off-by: Matthias J. Kannwischer <[email protected]>
mkannwischer added a commit that referenced this pull request Jan 6, 2026
#820 introduced a massive
performance regression to the CBMC proofs caused by the
polyvecl_pointwise_acc_montgomery_c.

This commit increases the OBJECT_BITS for that proof fixing the problem.

Signed-off-by: Matthias J. Kannwischer <[email protected]>
hanno-becker pushed a commit that referenced this pull request Jan 6, 2026
#820 introduced a massive
performance regression to the CBMC proofs caused by the
polyvecl_pointwise_acc_montgomery_c.

This commit increases the OBJECT_BITS for that proof fixing the problem.

Signed-off-by: Matthias J. Kannwischer <[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.

CBMC: Add proofs atop of native functions

3 participants