Skip to content
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

avx2/commitment: F* proofs #874

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open

avx2/commitment: F* proofs #874

wants to merge 23 commits into from

Conversation

W95Psp
Copy link
Contributor

@W95Psp W95Psp commented Mar 5, 2025

This PR adds proofs by normalization for one avx2 serialization function.

(previous text)
The main problem here is libcrux-intrinsics: the avx2 proofs in ML-KEM relies on very different models.
I'm not sure what to do here: maybe I should just add a avx2_extract_minicore.rs file and add a cfg to choose between either avx2_extract or avx2_extract_minicore?
And when we migrate the ML-KEM proofs, we can kill avx2_extract.

Any opinion on that?


Fixes #886.
We'll need to file a follow up for the proof of serialize_6.

What does this PR fixes:

  • enables proofs with the Rust minicore
  • bit-level proof of serialize_4

Missing:

  • bit-level proof of serialize_6
  • higher-level statements / proofs: proofs on integers, not bit vec

This following hax PRs were created while working on this libcrux PR:

Copy link
Member

@franziskuskiefer franziskuskiefer left a comment

Choose a reason for hiding this comment

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

no review, just a few quick high level comments

@@ -20,7 +20,8 @@ libcrux-sha3 = { version = "0.0.2-beta.3", path = "../libcrux-sha3" }
libcrux-intrinsics = { version = "0.0.2-beta.3", path = "../libcrux-intrinsics" }
libcrux-platform = { version = "0.0.2-beta.3", path = "../sys/platform" }
libcrux-macros = { version = "0.0.2-beta.3", path = "../macros" }
hax-lib = { version = "0.1.0", git = "https://github.com/hacspec/hax/"}
hax-lib = { version = "0.1.0", git = "https://github.com/hacspec/hax/", branch = "replace-body-temp"}
minicore = { path = "../fstar-helpers/minicore" }
Copy link
Member

Choose a reason for hiding this comment

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

So this requires releasing the minicore and actually making it releasable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally, I'd like to kill that Rust dependency. I have a plan for that but I need to experiment a little: that will require some more rewriting in F*.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So: this dependency is not needed in libcrux-intrsinsics, but I still need those in ml-dsa, but only on specs

Copy link
Member

Choose a reason for hiding this comment

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

Well, it's a dependency, so it needs to be released. path doesn't work for that.

@W95Psp W95Psp force-pushed the minicore-commitment-proof branch 2 times, most recently from 0dde429 to a3768df Compare March 12, 2025 16:09
@W95Psp W95Psp marked this pull request as ready for review March 12, 2025 16:20
@W95Psp W95Psp requested a review from a team as a code owner March 12, 2025 16:20
@W95Psp
Copy link
Contributor Author

W95Psp commented Mar 12, 2025

I have a regression in my proof somewhere, I need to fix that.
But otherwise this PR is ready for review!

@W95Psp
Copy link
Contributor Author

W95Psp commented Mar 17, 2025

I fixed my proof on ML-DSA, but the proof is pretty slow. Now it's going through. Debugging is a bit long, I have to wait for F* to normalize terms before seeing actual errors. I have some ideas to speed up the proof, but I need to investigate more.

Copy link
Member

Choose a reason for hiding this comment

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

Why does this need to be rewritten and what does it now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Quoting the commit that introduces this:

@W95Psp
hax: intro hax.sh
c3c24c3

This commit introduces a hax.sh script, that aims at replacing the python script.

The script does a little more: it is fixing up core names into minicore names.

The union of modules between our hax core model (proof-libs in hax) and minicore is not empty. This is a big issue for F*.
The script thus replace references to every core module provided by minicore into a reference to the corresponding minicore module.

@@ -20,7 +20,8 @@ libcrux-sha3 = { version = "0.0.2-beta.3", path = "../libcrux-sha3" }
libcrux-intrinsics = { version = "0.0.2-beta.3", path = "../libcrux-intrinsics" }
libcrux-platform = { version = "0.0.2-beta.3", path = "../sys/platform" }
libcrux-macros = { version = "0.0.2-beta.3", path = "../macros" }
hax-lib = { version = "0.1.0", git = "https://github.com/hacspec/hax/"}
hax-lib = { version = "0.1.0", git = "https://github.com/hacspec/hax/", branch = "replace-body-temp"}
minicore = { path = "../fstar-helpers/minicore" }
Copy link
Member

Choose a reason for hiding this comment

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

Well, it's a dependency, so it needs to be released. path doesn't work for that.

#[inline(always)]
fn serialize_4(simd_unit: &Vec256) -> Vec128 {
Copy link
Member

Choose a reason for hiding this comment

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

Did you check that this doesn't impact performance?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. I am taking a look now then

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ran cargo criterion before and after applying my diff to that one file commitment.rs.
I got the following very surprising results:
Capture d’écran 2025-04-01 à 15 00 00

Seems like the benchs are a bit flaky (as disucssed on gchat with Jonas).
Shall I inverstigate more? (if yes, how?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Running cargo bench --bench manual65:

(seems fine, right?)

Without commitment.rs patch

(libcrux) KeyGen 65 portable: 132 μs
(libcrux) Sign 65 portable: 395 μs
(libcrux) Verify 65 portable: 123 μs

(libcrux) KeyGen 65 simd256: 130 μs
(libcrux) Sign 65 simd256: 145 μs
(libcrux) Verify 65 simd256: 53 μs

(pqclean) KeyGen 65: 41 μs
(pqclean) Sign 65: 116 μs
(pqclean) Verify 65: 45 μs

With commitment.rs patch

(libcrux) KeyGen 65 portable: 133 μs
(libcrux) Sign 65 portable: 402 μs
(libcrux) Verify 65 portable: 124 μs

(libcrux) KeyGen 65 simd256: 130 μs
(libcrux) Sign 65 simd256: 144 μs
(libcrux) Verify 65 simd256: 54 μs

(pqclean) KeyGen 65: 42 μs
(pqclean) Sign 65: 116 μs
(pqclean) Verify 65: 46 μs

Second run:

(libcrux) KeyGen 65 portable: 136 μs
(libcrux) Sign 65 portable: 394 μs
(libcrux) Verify 65 portable: 123 μs

(libcrux) KeyGen 65 simd256: 130 μs
(libcrux) Sign 65 simd256: 145 μs
(libcrux) Verify 65 simd256: 53 μs

(pqclean) KeyGen 65: 41 μs
(pqclean) Sign 65: 114 μs
(pqclean) Verify 65: 45 μs

On main branch

(libcrux) KeyGen 65 portable: 133 μs
(libcrux) Sign 65 portable: 421 μs
(libcrux) Verify 65 portable: 122 μs

(libcrux) KeyGen 65 simd256: 128 μs
(libcrux) Sign 65 simd256: 143 μs
(libcrux) Verify 65 simd256: 53 μs

(pqclean) KeyGen 65: 41 μs
(pqclean) Sign 65: 115 μs
(pqclean) Verify 65: 45 μs

W95Psp added 18 commits April 1, 2025 12:36
This is required so that we can have a hax postcondition to `bits` stating it's a non-zero integer.
`core::arch` is actually `core::core_arch` in Rust's `core`.
This commit introduces a new abstraction: functional arrays.
This is an abstraction that provides finite maps: this is useful isntead of sequences, as fun arrays extract to `->^` restricted arrows in F*.
That's particularly handy for normalization in F*.
This commit introduces a `hax.sh` script, that aims at replacing the python script.

The script does a little more: it is fixing up core names into minicore names.

The union of modules between our hax `core` model (proof-libs in hax) and minicore is not empty. This is a big issue for F*.
The script thus replace references to every core module provided by minicore into a reference to the corresponding minicore module.
@W95Psp W95Psp force-pushed the minicore-commitment-proof branch from 8f106cd to af26ce9 Compare April 1, 2025 12:37
libcrux-intrinsics is extracted in two different ways, depending on
wether we are extracting ml-kem or ml-dsa. Thus having F* files checked
in the git repo will cause troubles.
@W95Psp W95Psp mentioned this pull request Apr 1, 2025
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.

Verifty ML-DSA: avx2/encoding/commitment: serialize_4
3 participants