Skip to content

[WIP] Mutable Style for ML-KEM #954

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

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft

Conversation

karthikbhargavan
Copy link
Contributor

WIP: tranforming ML-KEM to use &muts everywhere.

@karthikbhargavan karthikbhargavan changed the title Franziskus/mlkem mut [WIP] Mutable Style for ML-KEM May 9, 2025
@karthikbhargavan
Copy link
Contributor Author

karthikbhargavan commented May 11, 2025

@franziskuskiefer @jschneider-bensch

This branch needs some fixes in order to extract F*, and then lax and typecheck it.
To test the current status run hax.py_extract &> res and inspect the errors in res.
We will be handling these errors incrementally.

In commit 29899aa
I fixed hash_functions.rs to lax-check as an example, so now the first error you will see is in ind_cpa.rs.

The general rules for the transformation are as follows.
For each function in a module:

  • if an argument has been turned from an array (e.g. [u8; LEN]) to a slice (&[u8] or &mut [u8]), then we need a pre-condition stating what its length is: #[hax_lib::requires(input.len() == LEN)]
  • if an output (e.g. [u8; LEN]) has been turned into a mutable slice input (out:&mut [u8]), then we need both a pre-condition as described above and a post-condition saying that the length did not change (unfortunate to have to do this, but needed for now): #[hax_lib::ensures(|_| fstar!("Seq.length ${out}_future == Seq.length ${out}"))]
  • if an output has been turned into a mutable input, and if the function already has a post-condition stated in term of the result (e.g. ensures(| result | fstar!("... result ...."))) then we need to change each reference to result to refer to the future version of the output: ensures(| _ | fstar!("... ${output}_future ...."))

You can see some of these patterns in hash_functions.rs already.
Once you fix these, then hax.py_extract will no longer show errors for your module (even if there are errors in other modules). You can then open the extracted file in proofs/fstar/extraction and try to lax-check it.

Sometimes, the specs will have to be changed more substantially, in which case, comment them out, leave a note for the proofs team, and just try to make sure that the extraction works, and if possible that the output lax-checks.

@karthikbhargavan
Copy link
Contributor Author

In a follow-up commit fa5d435 I fixed the spec for Spec.Utils.fsti to match the new signature of these functions.

Now all the post-conditions of hash-functions are also fixed for the new style.

Copy link

This PR has been marked as stale due to a lack of activity for 60 days. If you believe this pull request is still relevant, please provide an update or comment to keep it open. Otherwise, it will be closed in 7 days.

@jschneider-bensch
Copy link
Collaborator

Still relevant, proofs still need to be adapted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants