Skip to content

Conversation

@willieyz
Copy link
Contributor

@willieyz willieyz commented Dec 29, 2025

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

  • Related: CBMC proofs for mld_poly_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
- This commit apply same workarounds for
  mld_polymat_permute_bitrev_to_custom, reference from mlkem-native,
  add following function and corresponding CBMC proof:
    - mld_polyvecl_permute_bitrev_to_custom
    - mld_polyvecl_permute_bitrev_to_custom_native
- and for the CBMC proof for above function:
    - mld_polyvecl_permute_bitrev_to_custom_native
  we add the contract and exception in check-contracts for
  for mld_poly_permute_bitrev_to_custom.

- Use tests cbmc -p polymat_permute_bitrev_to_custom contract in
  polymat_permute_bitrev_to_custom cbmc proof

Signed-off-by: willieyz <willie.zhao@chelpis.com>

add changes

Signed-off-by: willieyz <willie.zhao@chelpis.com>
@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
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