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

New Challenge 14 - High-Assurance SIMD Intrinsics for Rust #174

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

Conversation

karthikbhargavan
Copy link

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

@rahulku
Copy link

rahulku commented Nov 20, 2024

@tautschnig

Copy link
Member

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

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

I am quite confused as to whether this is a challenge or a tool proposal.

doc/src/challenges/0014-intrinsics-simd.md Outdated Show resolved Hide resolved
doc/src/challenges/0014-intrinsics-simd.md Outdated Show resolved Hide resolved
doc/src/challenges/0014-intrinsics-simd.md Outdated Show resolved Hide resolved
doc/src/challenges/0014-intrinsics-simd.md Outdated Show resolved Hide resolved
Copy link
Member

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

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

Let’s please disentangle producing the specifications from any particular tool. See detailed comments.

these contracts hold when the intrinsics are executed in Rust.
A secondary goal is to use these contracts as formal specifications
of the intrinsics API when doing proofs of Rust programs in proof
assistants like F* and Coq.
Copy link
Member

Choose a reason for hiding this comment

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

Why do specific tools matter when you are providing contracts?

Copy link
Author

Choose a reason for hiding this comment

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

I reduced references to specific tools, but I usually find it better to be concrete.

doc/src/challenges/0014-intrinsics-simd.md Outdated Show resolved Hide resolved

Separately, when formally verifying cryptographic libraries, each
project needs to define its own semantics for SIMD instructions in
EasyCrypt, F*, or Coq. This work is both time-consuming and
Copy link
Member

Choose a reason for hiding this comment

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

Is this necessarily a complete list of tools?

Copy link
Author

Choose a reason for hiding this comment

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

Rewrote.


Consequently, we believe there is a strong need for a consistent,
formal, testable specification of the SIMD intrinsics that can aid
Rust crypto developers. Furthermore, we believe that this
Copy link
Member

Choose a reason for hiding this comment

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

Why just crypto?

Copy link
Author

Choose a reason for hiding this comment

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

The motivation comes from crypto, but I rewrote to expand the potential application domain.

formal, testable specification of the SIMD intrinsics that can aid
Rust crypto developers. Furthermore, we believe that this
specification is written in a way that can be used to aid formal
verification of cryptography in various backend tools, including F*,
Copy link
Member

Choose a reason for hiding this comment

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

Is it a necessity that specifications are tailored towards crypto? We seek to do verification for all use cases.

Copy link
Author

Choose a reason for hiding this comment

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

The specifications are not tailored towards crypto, they are tailored towards verification. Rewrote.

```

This contract is then used to automatically generate randomized tests
for the intrinsic, which can be put on CI.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
for the intrinsic, which can be put on CI.
for the intrinsic, which can be put in CI.

Copy link
Author

Choose a reason for hiding this comment

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

fixed.

```

We then prove that this contract is consistent with the model of the
SIMD intrinsic in F* (i.e. our F* implementation of `mm_blen_epi16`)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
SIMD intrinsic in F* (i.e. our F* implementation of `mm_blen_epi16`)
SIMD intrinsic in F* (i.e. our F* implementation of `mm_blend_epi16`)

Copy link
Author

Choose a reason for hiding this comment

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

fixed.


### Assumptions

Users must trust the semantics of Rust encoded within the `hax`
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure that growing the TCB is a good idea, especially in a direction that will be somewhat foreign and inscrutable to Rust developers.

Copy link
Author

Choose a reason for hiding this comment

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

Rewrote to clarify. Of course, every Rust verification tool has its own TCB.


The goal is to annotate >= 100 intrinsics in `core::arch::x86_64` and
`core::arch::aarch64` with contracts, and all these contracts will be
tested both in Rust and in F*. These functions will include all the
Copy link
Member

Choose a reason for hiding this comment

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

I believe the F* part should be a tool proposal and not be intertwined with the challenge. Combining these both limits who can take on the challenge and also restricts us in getting any of this adopted upstream.

Copy link
Author

Choose a reason for hiding this comment

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

There will be a separate tool proposal for integrating hax (with F*, Coq, and possibly other provers as proof backends). We can remove the F* validation completely from here or offer it as an add-on to the solution.

@tautschnig tautschnig self-assigned this Nov 27, 2024
Copy link

@feliperodri feliperodri left a comment

Choose a reason for hiding this comment

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

After a first pass, my major comment is just to add more clarification on how to pick verification targets, avoid targeting tools to solve the challenge and do not attach the success criteria to any third-party libraries.

We can later send a tool proposal to be integrated into the repository and you can add more discussions on how to solve the challenge, even mentioning specific tools, in the GitHub issue corresponding to the challenge. However, this description should focus on what targets and properties are relevant and why.

  • note: I do encourage to use the application of this work in crypto to help prioritize the verification targets.

doc/src/challenges/0014-intrinsics-simd.md Outdated Show resolved Hide resolved
doc/src/challenges/0014-intrinsics-simd.md Outdated Show resolved Hide resolved
doc/src/challenges/0014-intrinsics-simd.md Outdated Show resolved Hide resolved
doc/src/challenges/0014-intrinsics-simd.md Outdated Show resolved Hide resolved
doc/src/challenges/0014-intrinsics-simd.md Outdated Show resolved Hide resolved
doc/src/challenges/0014-intrinsics-simd.md Outdated Show resolved Hide resolved
doc/src/challenges/0014-intrinsics-simd.md Outdated Show resolved Hide resolved
doc/src/challenges/0014-intrinsics-simd.md Show resolved Hide resolved
doc/src/challenges/0014-intrinsics-simd.md Outdated Show resolved Hide resolved
doc/src/challenges/0014-intrinsics-simd.md Outdated Show resolved Hide resolved

- **Status:** Open
- **Solution:**
- **Tracking Issue:** https://github.com/model-checking/verify-rust-std/issues/173

Choose a reason for hiding this comment

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

Missing reward: n/a.

Comment on lines +103 to +104
This contract is then used to automatically generate randomized tests
for the intrinsic, which can be put in CI.

Choose a reason for hiding this comment

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

?

Comment on lines +106 to +129
We can also use the [hax](https://github.com/hacspec/hax) toolchain to
compile this contract to F* where it can act as an interface to a model
of the intrinsics library.

```
val _mm_blend_epi16: __m128i -> __m128i -> i32 ->
Pure __m128i
(requires (v IMM8 >= 0 && v IMM8 <= 255))\
(ensures(fun result ->
forall j. j >= 0 && j < 8 ==>
if get_bit(IMM8,j) then
get_lane(result, j) == get_lane(b,j)
else
get_lane(result, j) == get_lane(a,j)))
```

We then prove that this contract is consistent with the model of the
SIMD intrinsic in F* (i.e. our F* implementation of `mm_blend_epi16`)
and also run the same tests we ran in Rust against this model in F* to
gain more confidence in our translation from Rust.

Finally, we will show how to use this contract in F* in proofs like
the libcrux proof for the ML-KEM post-quantum cryptographic
contruction.

Choose a reason for hiding this comment

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

?

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