Skip to content

Conversation

@willieyz
Copy link
Contributor

@willieyz willieyz commented Dec 4, 2025

CBMC Proof Native Functions
poly_ntt_native mld_ntt_native
poly_invntt_tomont_native mld_intt_native
Skip mld_poly_permute_bitrev_to_custom
rej_uniform_native mld_rej_uniform_native
rej_eta_native mld_rej_uniform_eta2_native
mld_rej_uniform_eta4_native
poly_decompose_native mld_poly_decompose_32_native
mld_poly_decompose_88_native
poly_caddq_native mld_poly_caddq_native
poly_use_hint_native mld_poly_use_hint_32_native
mld_poly_use_hint_88_native
poly_chknorm_native mld_poly_chknorm_native
polyz_unpack_native mld_polyz_unpack_17_native
mld_polyz_unpack_19_native
poly_pointwise_montgomery_native mld_poly_pointwise_montgomery_native
polyvecl_pointwise_acc_montgomery_native mld_polyvecl_pointwise_acc_montgomery_l4_native
mld_polyvecl_pointwise_acc_montgomery_l5_native
mld_polyvecl_pointwise_acc_montgomery_l7_native
keccakf1600_permute_native mld_keccak_f1600_x1_native
keccakf1600x4_permute_native mld_keccak_f1600_x4_native
  • This PR adds CBMC proofs for all native backend functions except one. We temporarily skip mld_poly_permute_bitrev_to_custom because its proof times out during CBMC ML-DSA-44 checking. Have already asked for help from @mkannwischer and @rod-chapman, and we will open a separate pull request: #770 , to address this issue.

  • Each proof reuses the harness and add contracts that reference from the corresponding C implementation, verifying that native backends satisfy the same specifications. Proofs use a corresponding mock backend (dummy_backend.h, dummy_backend_fips202_x1, dummy_backend_fips202_x4).

  • This PR made follwoing changes

    • Added proof harnesses and Makefiles in proofs/cbmc/ for all native functions
    • Introduced array_unchanged contract pattern in cbmc.h for fallback verification
    • Added MLD_NTT_BOUND and MLD_INTT_BOUND constant in api.h.
    • Refactored mld_polymat_permute_bitrev_to_custom from double to single loop for proof tractability
  • Test steps:

    • 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, for examples: tests cbmc -p poly_ntt will check poly_ntt, poly_ntt_c, poly_ntt_native with 3 security level.
| Status  | Count |
|---------|-------|
| Success | 3     |

| Proof           | Status  | Duration (in s) |
|-----------------|---------|-----------------|
| poly_ntt        | Success | 3               |
| poly_ntt_c      | Success | 2               |
| poly_ntt_native | Success | 3               |

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 for this PR.

Since the CBMC proof for polymat_permute_bitrev_to_custom_native is blowing up for ML-DSA-44, could you move just that to a new PR so we can investigate there?
Then we can already review+merge all the other commits.

@willieyz willieyz marked this pull request as ready for review December 5, 2025 06:13
@willieyz willieyz requested a review from a team as a code owner December 5, 2025 06: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. Looking fairly good. Here are some comments what still needs to be adjusted. The decompose contracts are wrong and are a serious soundness issue - the other comments are minor.

The contract for mld_poly_chknorm_native is rather ugly - we should consider simplifying that vastly, but that can be a follow up.

Please remove the TODOs also for mld_poly_use_hint_88_native and mld_poly_use_hint_32_native.

@willieyz willieyz force-pushed the cbmc-native branch 2 times, most recently from 1c2f04d to 5a99425 Compare December 5, 2025 10:57
@willieyz
Copy link
Contributor Author

willieyz commented Dec 5, 2025

Thanks @willieyz. Looking fairly good. Here are some comments what still needs to be adjusted. The decompose contracts are wrong and are a serious soundness issue - the other comments are minor.

The contract for mld_poly_chknorm_native is rather ugly - we should consider simplifying that vastly, but that can be a follow up.

Please remove the TODOs also for mld_poly_use_hint_88_native and mld_poly_use_hint_32_native.

Hello, @mkannwischer , thank you for your review!
I had fixed all issue according to your comment, also ,I will create a issue #773 following up the mld_poly_chknorm_native contract refactor problem,
Thank you for helping me improve this PR, thanks!

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 for the changes @willieyz - I just rechecked everything. LGTM now.

@hanno-becker, could you also take a look please?

@rod-chapman
Copy link
Contributor

News: CBMC team have proposed a fix for CBMC that helps with this issue. This is currently on a branch of the CBMC repo awaiting review.

For mldsa-native, I still have to re-structure the code of polymat_permite_bitrev_to_custom() to use a nested loop, so that the code structure matches the data structure.

With that change, AND the new CBMC, the proofs looks OK.

I have the code change - shall I commit and push it here?

@mkannwischer
Copy link
Contributor

News: CBMC team have proposed a fix for CBMC that helps with this issue. This is currently on a branch of the CBMC repo awaiting review.

For mldsa-native, I still have to re-structure the code of polymat_permite_bitrev_to_custom() to use a nested loop, so that the code structure matches the data structure.

With that change, AND the new CBMC, the proofs looks OK.

I have the code change - shall I commit and push it here?

Awesome news. Thanks @rod-chapman for following up.
Please experiment in #770. Once everything works fine we can pull it over here.

@rod-chapman
Copy link
Contributor

I have pushed the refactored polymat_permute_bitrev_to_custom() on the cbmc-native2 branch on PR#770. With the new wavefront of CBMC, proofs go through OK. I will push CBMC team to prioritize review and a new tagged release.

This commit adds CBMC proofs for the native function `mld_ntt_native`,
called `poly_ntt_native`

The following changes are included:
  - Add `dummy_backend.h` as a mock backend for `poly_ntt_native`.
  - Apply the same harness file and construct function contract
    reference from `poly_ntt`.
  - Use the following function contracts:
    - `mld_ntt_native`
    - `mld_poly_ntt_c`
  - Introduce a new CBMC contract pattern `array_unchanged` in `cbmc.h`,
    which is used to verify the fallback behavior inside `mld_ntt_native`.

Signed-off-by: willieyz <willie.zhao@chelpis.com>
- This commit adds CBMC proofs for the native function `mld_intt_native`,
  called `poly_invntt_tomont_native`

- This following changes are include:
  - Apply the same harness file and construct function contract,
    reference from `poly_invntt_tomnot`.
  - Use the following function contracts:
    - `mld_intt_native`
    - `mld_poly_invntt_tomont_c`
  - Add MLD_INTT_BOUND in api.h
  - Add `MLD_USE_NATIVE_INTT` in dummy_backend.h

Signed-off-by: willieyz <willie.zhao@chelpis.com>
- This commit adds CBMC proofs for the native function `mld_rej_uniform_native`,
  called `rej_uniform_native`

- This following changes are include:
  - Apply the same harness file and construct function contract reference
    from `rej_uniform`.

  - Use the following function contracts:
    - `mld_rej_uniform_native`
    - `mld_rej_uniform_c`
  - Add `MLD_USE_NATIVE_REJ_UNIFORM` in dummy_backend.h

Signed-off-by: willieyz <willie.zhao@chelpis.com>
- This commit adds CBMC proofs for following the native function:
  `mld_rej_uniform_eta2_native` and `mld_rej_uniform_eta4_native`,
  called `rej_eta_native`.

- This following changes are include:
  - Apply the same harness file and construct function contract reference
    from rej_eta.

  - Use the following function contracts:
    - mld_rej_eta_c
    - mld_rej_uniform_eta2_native
    - mld_rej_uniform_eta4_native

  - Add `MLD_USE_NATIVE_REJ_UNIFORM_ETA2`,
        `MLD_USE_NATIVE_REJ_UNIFORM_ETA4` in dummy_backend.h

Signed-off-by: willieyz <willie.zhao@chelpis.com>
- This commit adds CBMC proofs for following the native function:
  `mld_poly_decompose_32_native`, `mld_poly_decompose_88_native`.
  called `poly_decompose_native`.

- This following changes are include:

  - Apply the same harness file and construct function contract reference
    from `poly_decompose`.

  - Use the following function contracts:
    - mld_poly_decompose_c
    - mld_poly_decompose_32_native
    - mld_poly_decompose_88_native

  - Add `MLD_USE_NATIVE_POLY_DECOMPOSE_32`,
    `MLD_USE_NATIVE_POLY_DECOMPOSE_88` in dummy_backend.h

Signed-off-by: willieyz <willie.zhao@chelpis.com>
- This commit adds CBMC proofs for the native function
  `mld_poly_caddq_native`, called `poly_caddq_native`

- This following changes are include:
  - Apply the same harness file and construct function contract
    reference from `poly_caddq`.
  - Use the following function contracts:
    - `mld_poly_caddq_c`
    - `mld_poly_caddq_native`
  - Add `MLD_USE_NATIVE_POLY_CADDQ` in dummy_backend.h

Signed-off-by: willieyz <willie.zhao@chelpis.com>
- This commit adds CBMC proofs for following the native function:
 `mld_poly_use_hint_32_native`, `mld_poly_use_hint_88_native`.
 called `poly_use_hint_native`.

- This following changes are include:

 - Apply the same harness file and construct function contract reference
  from `poly_use_hint`.

 - Use the following function contracts:
  - mld_poly_use_hint_c
  - mld_poly_use_hint_32_native
  - mld_poly_use_hint_88_native

 - Add `MLD_USE_NATIVE_POLY_USE_HINT_32`,
  `MLD_USE_NATIVE_POLY_USE_HINT_88` in dummy_backend.h

Signed-off-by: willieyz <willie.zhao@chelpis.com>
- This commit adds CBMC proofs for following the native function:
 `mld_poly_chknorm_native`, called `poly_chknorm_native`.

- This following changes are include:

 - Apply the same harness file and construct function contract reference
  from `poly_chknorm_native`.

 - Use the following function contracts:
  - `mld_poly_chknorm_c`
  - `mld_poly_chknorm_native`

 - Add `MLD_USE_NATIVE_POLY_CHKNORM` in dummy_backend.h

Signed-off-by: willieyz <willie.zhao@chelpis.com>
- This commit adds CBMC proofs for following the native function:
 `mld_polyz_unpack_17_native` and `mld_polyz_unpack_19_native`.
 called `polyz_unpack_native`.

- This following changes are include:

 - Apply the same harness file and construct function contract reference
  from `polyz_unpack`.

 - Use the following function contracts:
   - `mld_polyz_unpack_c`
   - `mld_polyz_unpack_17_native`
   - `mld_polyz_unpack_17_native`

 - Add `MLD_USE_NATIVE_POLYZ_UNPACK_17`,
  `MLD_USE_NATIVE_POLYZ_UNPACK_19` in dummy_backend.h

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

- This commit adds CBMC proofs for the native function
  `mld_poly_pointwise_montgomery_native`,
  called `poly_pointwise_montgomery_native`

- This following changes are include:
  - Apply the same harness file and construct function contract,
    reference from `poly_pointwise_montgomery`.
  - Use the following function contracts:
    - `mld_poly_pointwise_montgomery_native`
    - `mld_poly_pointwise_montgomery_c`
  - Add `MLD_USE_NATIVE_POINTWISE_MONTGOMERY` in dummy_backend.h

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

- This commit adds CBMC proofs for following the native function:
  `mld_polyvecl_pointwise_acc_montgomery_l4_native`,
  `mld_polyvecl_pointwise_acc_montgomery_l5_native` and
  `mld_polyvecl_pointwise_acc_montgomery_l7_native`
  called `polyvecl_pointwise_acc_montgomery_native`.

- This following changes are include:
  - Apply the same harness file and construct function contract reference
    from `polyvecl_pointwise_acc_montgomery`.
  - Use the following function contracts:
    - `mld_polyvecl_pointwise_acc_montgomery_l4_native`
    - `mld_polyvecl_pointwise_acc_montgomery_l5_native`
    - `mld_polyvecl_pointwise_acc_montgomery_l7_native`

- Add `MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L4`,
      `MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L5`,
      `MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L7`
    in dummy_backend.h

Signed-off-by: willieyz <willie.zhao@chelpis.com>
- This commit adds CBMC proofs for following the native function:
 `mld_keccak_f1600_x1_native`, called `keccakf1600_permute_native`.

- This following changes are include:

 - Apply the same harness file and construct function contract reference
  from `keccakf1600_permute`.

 - Use the following function contracts:
  - `mld_keccak_f1600_x1_native`

 - Add `MLD_USE_FIPS202_X1_NATIVE` in dummy_backend_fips202_x1.h

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

- This commit adds CBMC proofs for following the native function:
 `mld_keccak_f1600_x4_native`, called `keccakf1600x4_permute_native`.

- This following changes are include:

 - Apply the same harness file and construct function contract reference
  from `keccakf1600x4_permute`.

 - Use the following function contracts:
  - `mld_keccak_f1600_x4_native`

 - Add `MLD_USE_FIPS202_X4_NATIVE` in dummy_backend_fips202_x4.h

Signed-off-by: willieyz <willie.zhao@chelpis.com>
@mkannwischer mkannwischer merged commit d702136 into main Dec 12, 2025
328 checks passed
@mkannwischer mkannwischer deleted the cbmc-native branch December 12, 2025 14:41
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