<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>pereq - Blog</title>
    <subtitle>We build software, and the tools that others use to build software.</subtitle>
    <link rel="self" type="application/atom+xml" href="https://pereq-website.pages.dev/blog/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://pereq-website.pages.dev/blog/"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2026-10-01T00:00:00+00:00</updated>
    <id>https://pereq-website.pages.dev/blog/atom.xml</id>
    <entry xml:lang="en">
        <title>Hax 0.4!</title>
        <published>2026-10-01T00:00:00+00:00</published>
        <updated>2026-10-01T00:00:00+00:00</updated>
        
        <author>
          <name>Unknown</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://pereq-website.pages.dev/blog/hax_0_4_release/"/>
        <id>https://pereq-website.pages.dev/blog/hax_0_4_release/</id>
        
        <content type="html" xml:base="https://pereq-website.pages.dev/blog/hax_0_4_release/">&lt;p&gt;The world of mathematics has been shaken by an earthquake: LLMs can now generate
large Lean developments autonomously: &lt;a rel=&quot;external&quot; href=&quot;https://openai.com/index/navier-stokes-solution/&quot;&gt;Navier-Stokes
solution&lt;/a&gt;, &lt;a rel=&quot;external&quot; href=&quot;https://www.anthropic.com/research/formalizing-fermats-last-theorem&quot;&gt;FLT
proof&lt;/a&gt;, and
many more. The narrow stream of proof-work has the potential to open into a
free-flowing river.&lt;/p&gt;
&lt;p&gt;This offers a promise for software verification: what used to require
&lt;a rel=&quot;external&quot; href=&quot;https://project-everest.github.io/&quot;&gt;multi-year effort by skilled teams&lt;/a&gt; might
become more broadly available, provided that the flow can be tamed into useful
ways, that is, that formal verification toolchains adapt and improve.&lt;/p&gt;
&lt;p&gt;We’ve been updating and improving hax, our Rust verification framework, to
leverage this newfound potential. With Rust being a popular choice for
AI-written code, and with Lean seeing rapid adoption and tooling investment, we
believe our Rust-to-Lean pipeline could play a key role in improving confidence
in many critical codebases.&lt;/p&gt;
&lt;p&gt;We’re proud to announce the &lt;a rel=&quot;external&quot; href=&quot;https://github.com/cryspen/hax/releases&quot;&gt;0.4 release of
hax&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;TLDR&lt;/strong&gt;: We improved &lt;a rel=&quot;external&quot; href=&quot;https://github.com/cryspen/hax&quot;&gt;hax&lt;/a&gt; to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;have a &lt;strong&gt;greater reach&lt;/strong&gt; by expanding its support for the Rust language&lt;/li&gt;
&lt;li&gt;be more broadly &lt;strong&gt;accessible&lt;/strong&gt; to users&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This new release achieves that through:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the collaboration with &lt;a rel=&quot;external&quot; href=&quot;https://github.com/AeneasVerif/aeneas&quot;&gt;Aeneas&lt;/a&gt; as our
&lt;strong&gt;new engine for the Rust→Lean&lt;/strong&gt; pipeline&lt;/li&gt;
&lt;li&gt;a new &lt;strong&gt;streamlined&lt;/strong&gt; installation and &lt;strong&gt;setup&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For more technical details on the release, see the &lt;a rel=&quot;external&quot; href=&quot;https://hax.cryspen.com/blog/2026/09/29/hax-04-easier-to-install-and-configure-and-a-new-lean-backend/&quot;&gt;companion
post&lt;/a&gt;
on the hax blog. You can also &lt;a rel=&quot;external&quot; href=&quot;https://hax-playground.cryspen.com/&quot;&gt;try hax
online&lt;/a&gt;!&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;adopting-aeneas-for-the-lean-backend&quot;&gt;Adopting Aeneas for the Lean backend&lt;/h2&gt;
&lt;p&gt;Hax was from the beginning thought of as a multi-backend tool, i.e. targeting
several proof assistants, even though historically,
&lt;a rel=&quot;external&quot; href=&quot;https://fstar-lang.org/&quot;&gt;F*&lt;/a&gt; was our preferred option. We added a new Lean
backend over the course of 2025, which gave us interesting insights and
promising results.&lt;/p&gt;
&lt;p&gt;While the collaboration with the Aeneas team, which started at Inria, was still
ongoing on the frontend side of hax and
&lt;a rel=&quot;external&quot; href=&quot;https://github.com/AeneasVerif/charon&quot;&gt;Charon&lt;/a&gt;, we decided in early 2026 to
pivot and directly use the Charon+Aeneas pipeline as the translation engine for
our Lean backend. Since then, we’ve been increasing our collaboration,
contributing bug fixes and improvements.&lt;/p&gt;
&lt;p&gt;While the Charon+Aeneas pipeline was made available in 0.3.7, the 0.4
release makes it officially our main Lean backend. This increases support for
Rust, notably &lt;em&gt;functions returning mutable borrows&lt;/em&gt;. Here is an example from the
&lt;a rel=&quot;external&quot; href=&quot;https://github.com/openmls/openmls/blob/ff94cdc2b036fa91e676a5a9252b5150534d66df/openmls/src/treesync/treesync_node.rs#L133&quot;&gt;OpenMLS
codebase&lt;/a&gt;,
one of our ongoing proof efforts, that was previously rejected by our engine:&lt;/p&gt;
&lt;pre&gt;&lt;code data-lang=&quot;rust&quot;&gt;pub fn node_mut(&amp;amp;mut self) -&amp;gt; &amp;amp;mut Option&amp;lt;ParentNode&amp;gt; { ... }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Functionalizing calls to such a function, say &lt;code&gt;let x = n.node_mut()&lt;/code&gt;, is
non-trivial: it requires inserting “&lt;em&gt;backward functions&lt;/em&gt;” at the end of the
lifetime of &lt;code&gt;x&lt;/code&gt; to “update” the value of &lt;code&gt;n&lt;/code&gt;. Those backward functions must be
computed from the code and inserted at the right locations. This is the role of
the &lt;a rel=&quot;external&quot; href=&quot;https://dl.acm.org/doi/10.1145/3547647&quot;&gt;Aeneas translation&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;the-hax-workflow&quot;&gt;The hax workflow&lt;/h2&gt;
&lt;p&gt;Proving properties of Rust code is not only about translation. This release also
packages various extensions to Aeneas, to support the key design choices and
workflows of the &lt;em&gt;hax way&lt;/em&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a strong library of &lt;strong&gt;Rust-written models for core/std/alloc&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;a set of macros for &lt;strong&gt;writing specs directly in the code&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;and use of Lean’s built-in &lt;code&gt;mvcgen&lt;/code&gt; tactic as our main &lt;strong&gt;proof framework&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;All tools verifying Rust code have to handle its dependencies: compiler
intrinsics, core/std/alloc libraries. Often, it is done by providing a
hand-written model directly in the prover, say Lean for instance. This is
usually error-prone, hard to audit, hard to extend and backend-specific. To
solve those issues, we’ve been developing a &lt;strong&gt;Rust-written library&lt;/strong&gt; of &lt;strong&gt;models
for core&lt;/strong&gt;. They are easily &lt;strong&gt;extensible, backend-agnostic&lt;/strong&gt;, and heavily
&lt;strong&gt;tested&lt;/strong&gt; against their real core counterparts. Those models rely on a
small, &lt;a rel=&quot;external&quot; href=&quot;https://github.com/cryspen/hax/tree/main/hax-lib/core-models/rust_primitives&quot;&gt;well-defined set of
primitives&lt;/a&gt;
that have to be modeled in the library of each backend. We’re very excited about
the progress there; we’ll cover it in more detail in an upcoming post.&lt;/p&gt;
&lt;p&gt;A key part of the hax methodology is the collocation of code and specs: we
encourage writing the &lt;strong&gt;specs alongside the code&lt;/strong&gt;, directly in Rust (when
applicable). We extended Aeneas with preliminary support for those (restricted
to pre/post on standalone items for now). This eases review and sync of code and
proofs.&lt;/p&gt;
&lt;p&gt;Finally, we decided to adopt the &lt;a rel=&quot;external&quot; href=&quot;https://lean-lang.org/doc/reference/latest/The--mvcgen--tactic/&quot;&gt;&lt;code&gt;mvcgen&lt;/code&gt;
tactic&lt;/a&gt; as our
entry point for actual proofs. We believe in using standard, community-backed
tools as much as possible. The development speed of &lt;code&gt;mvcgen&lt;/code&gt; is astonishing, and
we’ve already used it in large-scale proofs with great success.&lt;/p&gt;
&lt;h2 id=&quot;a-streamlined-installation-and-setup&quot;&gt;A streamlined installation and setup&lt;/h2&gt;
&lt;p&gt;A key friction point for formal verification tools is usually installation,
setup, and maintenance. With this release, hax 0.4 is available directly with
&lt;code&gt;cargo install cargo-hax&lt;/code&gt; (or via a binary installation). Once installed, hax
handles the other dependencies (Charon+Aeneas) seamlessly for the user, via the
versatile command &lt;code&gt;cargo hax tools&lt;/code&gt; (fetching the binaries, managing versions,
etc.). See the &lt;a rel=&quot;external&quot; href=&quot;https://hax.cryspen.com/manual/tools/&quot;&gt;manual&lt;/a&gt; for more details.&lt;/p&gt;
&lt;p&gt;All the relevant settings for verification can now be stored in a single,
version-controlled, crate-level file &lt;code&gt;hax.toml&lt;/code&gt;. In that file, the user can
define &lt;em&gt;proof scenarios&lt;/em&gt;, with a specific backend, that target a subset of the
crate. This is key to enabling &lt;strong&gt;extensible verification&lt;/strong&gt;, or to target different
properties with different backends.&lt;/p&gt;
&lt;h2 id=&quot;trust-assumptions&quot;&gt;Trust &amp;amp; assumptions&lt;/h2&gt;
&lt;p&gt;Hax makes assumptions, and there are certainly bugs in the hax codebase or in
dependencies. We aim to document our trusted computing base, publish in
open-source and test our toolchain comprehensively. Notably:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Hax depends on open-source tools (Cargo, rustc, Lean, F*, Aeneas) that are
backed and scrutinized by a community. Hax 0.4 targets Lean v4.31.0, which has
some &lt;a rel=&quot;external&quot; href=&quot;https://leodemoura.github.io/blog/2026-8-1-postmortem-for-kernel-soundness-bug-14576/&quot;&gt;known soundness
bugs&lt;/a&gt;.
Upgrading the Lean version is planned for the next release.&lt;/li&gt;
&lt;li&gt;We rely on our modeling of Rust primitives and our core models being faithful
to the rustc implementation. We mitigate the risk of mismatch by heavily
testing them.&lt;/li&gt;
&lt;li&gt;Issues can hide in the overall workflow: flawed specs, excluded code, ignored
theorems, etc. We are building tools to surface the TCB for every hax project.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We welcome feedback and findings to continuously improve the trustworthiness of
the toolchain.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Hax 0.4 is a pivotal moment for Cryspen, leveling up to the challenges
ahead. The next release will contain a new
&lt;a rel=&quot;external&quot; href=&quot;https://bblanche.gitlabpages.inria.fr/proverif/&quot;&gt;ProVerif&lt;/a&gt; backend, increase
overall robustness and improve proof engineering.&lt;/p&gt;
&lt;p&gt;For more details on hax 0.4, look at the &lt;a rel=&quot;external&quot; href=&quot;https://hax.cryspen.com/blog/2026/09/29/hax-04-easier-to-install-and-configure-and-a-new-lean-backend/&quot;&gt;companion blog
post&lt;/a&gt;
on the hax blog, the docs, or the &lt;a rel=&quot;external&quot; href=&quot;https://github.com/cryspen/hax&quot;&gt;hax repo&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Stay tuned for hax 0.5!&lt;/p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>EIC Transition: Spectrum</title>
        <published>2026-06-25T00:00:00+00:00</published>
        <updated>2026-06-25T00:00:00+00:00</updated>
        
        <author>
          <name>Unknown</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://pereq-website.pages.dev/blog/eic-transition-spectrum/"/>
        <id>https://pereq-website.pages.dev/blog/eic-transition-spectrum/</id>
        
        <content type="html" xml:base="https://pereq-website.pages.dev/blog/eic-transition-spectrum/">&lt;p&gt;We are excited to have been awarded a Transition Grant from the European Innovation Council to build a specification and verification toolkit that developers can use to build and deploy provably-secure software. The project is called &lt;a href=&quot;https://pereq-website.pages.dev/spectrum/&quot;&gt;Spectrum&lt;/a&gt; and it builds on our &lt;a rel=&quot;external&quot; href=&quot;https://hax.cryspen.com&quot;&gt;hax&lt;/a&gt; open-source framework.&lt;/p&gt;
&lt;p&gt;In the coming months, we will describe how we and our customers use the Spectrum tools on a daily basis to design and implement security-critical systems. If you would like to know how Spectrum can help you, get in touch.&lt;/p&gt;
&lt;p&gt;&lt;a class=&quot;btn&quot; href=&quot;mailto:info@cryspen.com&quot;&gt;Get in touch&lt;/a&gt;&lt;/p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Software Verification in Lean</title>
        <published>2026-04-22T00:00:00+00:00</published>
        <updated>2026-04-22T00:00:00+00:00</updated>
        
        <author>
          <name>Unknown</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://pereq-website.pages.dev/blog/software-verification-in-lean-2026/"/>
        <id>https://pereq-website.pages.dev/blog/software-verification-in-lean-2026/</id>
        
        <content type="html" xml:base="https://pereq-website.pages.dev/blog/software-verification-in-lean-2026/">&lt;p&gt;This week in Paris, Cryspen is delighted to be co-hosting
&lt;a rel=&quot;external&quot; href=&quot;https://beneficial-ai-foundation.github.io/SVIL2026/&quot;&gt;Software Verification in Lean 2026&lt;/a&gt;, a
workshop and associated hackathon organized by the
&lt;a rel=&quot;external&quot; href=&quot;https://www.beneficialaifoundation.org/&quot;&gt;Beneficial AI Foundation&lt;/a&gt; and the
&lt;a rel=&quot;external&quot; href=&quot;https://lean-lang.org/fro/&quot;&gt;Lean FRO&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;SVIL 2026 brings together leading researchers and practitioners
working on using the &lt;a rel=&quot;external&quot; href=&quot;https://lean-lang.org/&quot;&gt;Lean proof assistant&lt;/a&gt; to
formalize and verify real-world software. On Monday, I gave a talk on
the challenges of verifying cryptographic applications, and the
opportunities that are being opened up by the rapid innovations
in Lean and by the emergence of AI-assisted formal proofs.&lt;/p&gt;
&lt;p&gt;SVIL 2026 is initiating several exciting new collaborations. On
Monday, BAIF and Lean FRO announced the &lt;a rel=&quot;external&quot; href=&quot;https://www.beneficialaifoundation.org/signal-shot&quot;&gt;Signal
Shot&lt;/a&gt;, a challenge
to the community to formally verify the Signal protocol and Signal
app.  Cryspen intends to contribute our tools and our expertise to this
effort, in collaboration with our colleagues in the
&lt;a rel=&quot;external&quot; href=&quot;https://github.com/AeneasVerif/aeneas&quot;&gt;Aeneas&lt;/a&gt; team.&lt;/p&gt;
&lt;p&gt;If you want to learn more about how Cryspen can help you build ambitious software with
strong security and correctness guarantees, &lt;a href=&quot;mailto:info@cryspen.com&quot;&gt;reach out to us&lt;/a&gt;.&lt;/p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Formally Specifying and Testing the Rust Standard Library</title>
        <published>2025-10-28T00:00:00+00:00</published>
        <updated>2025-10-28T00:00:00+00:00</updated>
        
        <author>
          <name>Unknown</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://pereq-website.pages.dev/blog/specify-rust-simd/"/>
        <id>https://pereq-website.pages.dev/blog/specify-rust-simd/</id>
        
        <content type="html" xml:base="https://pereq-website.pages.dev/blog/specify-rust-simd/">&lt;p&gt;Modern programming languages typically come with a large standard
library that implements essential language features like machine
arithmetic and I/O, offers efficient data structures, provides
interfaces to system libraries, etc. Although it is often overlooked,
this standard library should be considered as much part of the trusted
computing base (TCB) as the language compiler. Indeed, any bug in the standard
library is likely to break applications and could result in security vulnerabilities.&lt;/p&gt;
&lt;p&gt;Recognizing this concern, the Rust community has &lt;a rel=&quot;external&quot; href=&quot;https://model-checking.github.io/verify-rust-std/&quot;&gt;initiated an
effort&lt;/a&gt; to formally
verify the Rust standard library. Cryspen is participating in this
project, and as our first contribution, we proposed and implemented a
new methodology to formally specify and test the platform-specific
SIMD functions in the Rust core library. These functions are used in
a variety of performance-sensitive Rust applications, including cryptographic
libraries like &lt;a rel=&quot;external&quot; href=&quot;https://github.com/celabshq/libcrux&quot;&gt;libcrux&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;modeling-rust-s-core-arch-library&quot;&gt;Modeling Rust’s &lt;code&gt;core::arch&lt;/code&gt; library&lt;/h2&gt;
&lt;p&gt;The
&lt;a rel=&quot;external&quot; href=&quot;https://github.com/rust-lang/stdarch/tree/master/crates/core_arch&quot;&gt;&lt;code&gt;core::arch&lt;/code&gt;&lt;/a&gt;
library in Rust provides a number of platform-specific
functionalities, including wrappers for specific machine instructions.
In particular, it provides functions corresponding to the
single-instruction-multiple-data (SIMD) instructions provided by
different vectorized architectures such as Intel’s AVX, AVX2 and
AVX-512, and Arm’s Aarch64/Neon.&lt;/p&gt;
&lt;p&gt;To model the behaviour of each SIMD instruction in a testable manner,
we essentially write a reference implementation of the
function in Rust based on the instruction’s documentation.&lt;/p&gt;
&lt;p&gt;There are three kinds of SIMD intrinsics in &lt;code&gt;core::arch&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The first kind are &lt;code&gt;builtin&lt;/code&gt; Rust compiler intrinsics, some of which are
in the &lt;a rel=&quot;external&quot; href=&quot;https://github.com/model-checking/verify-rust-std/blob/main/library/core/src/intrinsics/simd.rs&quot;&gt;&lt;code&gt;intrinsics/simd.rs&lt;/code&gt; file&lt;/a&gt;
in the &lt;code&gt;core&lt;/code&gt; crate, and others are in the &lt;a rel=&quot;external&quot; href=&quot;https://github.com/model-checking/verify-rust-std/blob/main/library/stdarch/crates/core_arch/src/simd.rs&quot;&gt;&lt;code&gt;simd.rs&lt;/code&gt; file of &lt;code&gt;core_arch&lt;/code&gt;&lt;/a&gt;.
These builtin intrinsics define generic SIMD operations that the Rust compiler knows how to implement on each platform.&lt;/p&gt;
&lt;p&gt;The second kind are &lt;code&gt;extern&lt;/code&gt; intrinsics that are links to definitions in LLVM.
See, for example, &lt;a rel=&quot;external&quot; href=&quot;https://github.com/rust-lang/stdarch/blob/master/crates/core_arch/src/x86/avx2.rs#L3596C8-L3596C14&quot;&gt;this list&lt;/a&gt;
of &lt;code&gt;extern&lt;/code&gt; intrinsics used in the Intel x86 AVX2 library.
These extern intrinsics are typically platform-specific functions that map to low-level instructions.&lt;/p&gt;
&lt;p&gt;The third kind are &lt;code&gt;defined&lt;/code&gt; intrinsics that are given proper definitions in Rust, and their code may
depend on the builtin intrinsics or the extern intrinsics. These defined intrinsics represent higher-level
operations that are wrappers around one or more assembly instructions.&lt;/p&gt;
&lt;p&gt;For &lt;code&gt;builtin&lt;/code&gt; and &lt;code&gt;extern&lt;/code&gt; intrinsics, we need to define reference
implementations ourselves, but for &lt;code&gt;defined&lt;/code&gt; intrinsics, we have a
choice: we can either define a completely independent model of the
intrinsic based on its documentation, or we can copy and adapt the
implementation provided in the Rust core library and treat it as a
reference implementation. If our goal is to check the Rust core
library, it is always better to write a fresh model that can serve as
the official specification. Conversely, deriving models from the Rust
library implementations allows us to quickly obtain models for a large
class of functions, and these models accurately reflect what Rust does
in practice, which is useful when analyzing Rust programs that use
these intrinsics. We need to balance this tradeoff based on our goals,
and here, we only derive models for intrinsics whose bodies are
shallow wrappers around builtin or extern intrinsics.&lt;/p&gt;
&lt;h2 id=&quot;an-example-mm256-bsrli-epi128&quot;&gt;An Example: &lt;code&gt;_mm256_bsrli_epi128&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;For example, let us say the intrinsic we are modeling is
&lt;code&gt;_mm256_bsrli_epi128&lt;/code&gt; from the Intel AVX2 feature set.&lt;/p&gt;
&lt;p&gt;The official &lt;a rel=&quot;external&quot; href=&quot;https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_bsrli_epi128&amp;amp;ig_expand=628&quot;&gt;Intel documentation of this function&lt;/a&gt; provides a textual description:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Shift 128-bit lanes in a right by imm8 bytes while shifting in zeros, and store the results in dst.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It also provides pseudocode for the instruction:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;tmp := imm8[7:0]
IF tmp &amp;gt; 15
	tmp := 16
FI
dst[127:0] := a[127:0] &amp;gt;&amp;gt; (tmp*8)
dst[255:128] := a[255:128] &amp;gt;&amp;gt; (tmp*8)
dst[MAX:256] := 0
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Based on this pseudocode, we can write a &lt;code&gt;model&lt;/code&gt; for the function,
interpreting the 256-bit vector type &lt;code&gt;__m256i&lt;/code&gt; as an array of two
128-bit integers (&lt;code&gt;i128x2&lt;/code&gt;):&lt;/p&gt;
&lt;pre&gt;&lt;code data-lang=&quot;rust&quot;&gt;pub fn _mm256_bsrli_epi128&amp;lt;const IMM8: i32&amp;gt;(a: i128x2) -&amp;gt; i128x2 {
	i128x2::from_fn(|i| {
	    let mut tmp  = IMM8%256;
	    if tmp &amp;gt; 15 {tmp = 16}
	    ((a[i] as u128 ) &amp;gt;&amp;gt; (tmp*8)) as i128
	})
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;However, in the Rust core library, this is a &lt;code&gt;defined&lt;/code&gt; intrinsic, and
when we began our project, this intrinsic was implemented &lt;a rel=&quot;external&quot; href=&quot;https://github.com/rust-lang/stdarch/blob/35595690d7881b20bd419875c2b64f284534d237/crates/core_arch/src/x86/avx2.rs#L2778&quot;&gt;as shown
here&lt;/a&gt;. Notably,
the implementation aims to be efficient by branching over the shift
value (&lt;code&gt;tmp&lt;/code&gt;) and implementing the shift using byte-level shuffling
operations, presumably because this is faster than using a shift instruction.&lt;/p&gt;
&lt;p&gt;We now have two different interpretations of the same
instruction, a &lt;code&gt;model&lt;/code&gt; that follows the Intel documentation and an
&lt;code&gt;implementation&lt;/code&gt; that aims to be efficient. Since both these functions
are executable, we can test them against each other.&lt;/p&gt;
&lt;h2 id=&quot;testing-the-model-agains-the-rust-core-library&quot;&gt;Testing the Model agains the Rust Core library&lt;/h2&gt;
&lt;p&gt;We use the standard Rust testing framework to run a large number of tests for each intrinsic we model against the same intrinsic in the Rust core library. For convenience, we implemented a set of macros that allows us to generate random tests for large inputs and comprehensive tests for small inputs.&lt;/p&gt;
&lt;p&gt;For the &lt;code&gt;_mm256_bsrli_epi128&lt;/code&gt; function above, we test it for all
values of &lt;code&gt;IMM8&lt;/code&gt; from 0 to 256 (since the Intel pseudocode only looks
at the bottom 8 bits), and for a 100 random bitvectors representing
the &lt;code&gt;a&lt;/code&gt; vector (the number of tests is configurable). For each input,
we test whether our model returns the same output as the Rust
core. Often, this process reveals bugs in our hand-written models,
where we may have misinterpreted the Intel or Arm documentation.&lt;/p&gt;
&lt;p&gt;In the case of &lt;code&gt;_mm256_bsrli_epi128&lt;/code&gt; our tests revealed a bug in the
Rust core library. When the value of &lt;code&gt;tmp&lt;/code&gt; in the pseudocode above is
greater than 15, instead of setting the value to 16 as specified by
Intel, the Rust core implementation set it to &lt;code&gt;tmp % 16&lt;/code&gt;. This bug can
be seen on &lt;a rel=&quot;external&quot; href=&quot;https://github.com/rust-lang/stdarch/blob/35595690d7881b20bd419875c2b64f284534d237/crates/core_arch/src/x86/avx2.rs#L2782&quot;&gt;this
line&lt;/a&gt;. As
a result, the tests fail for values of &lt;code&gt;IMM8&lt;/code&gt; above 15.&lt;/p&gt;
&lt;p&gt;A similar bug affects &lt;code&gt;_mm512_bsrli_epi128&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;We opened an issue in the Rust &lt;code&gt;stdarch&lt;/code&gt; repository, reporting this bug,
along with the precise tests that fail. This helped the Rust developers
quickly agree on the bug and accept our fix, which has since been upstreamed.&lt;/p&gt;
&lt;h2 id=&quot;testable-models-for-the-rust-simd-intrinsics&quot;&gt;Testable Models for the Rust SIMD Intrinsics&lt;/h2&gt;
&lt;p&gt;In total, we formally specified 384 intrinsics for x86 platforms, 181
intrinsics for aarch64, and tested these specifications against the
Rust core library. In the course of this testing, we found and fixed
bugs in two intrinsics in the Rust library.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Our challenge to Verify Rust Std: &lt;a rel=&quot;external&quot; href=&quot;https://github.com/model-checking/verify-rust-std/issues/173&quot;&gt;Challenge 15&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Our solution to the challenge: &lt;a rel=&quot;external&quot; href=&quot;https://github.com/model-checking/verify-rust-std/pull/423&quot;&gt;Testable Models for SIMD Intrinsics&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;The bug we found in the Rust SIMD libraries: &lt;a rel=&quot;external&quot; href=&quot;https://github.com/rust-lang/stdarch/issues/1822&quot;&gt;Bug&lt;/a&gt;, &lt;a rel=&quot;external&quot; href=&quot;https://github.com/rust-lang/stdarch/pull/1823&quot;&gt;Fix&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This work was done as part of Aniket Mishra’s Internship at Cryspen, and is part
of a larger project to formally specify the Rust &lt;code&gt;core&lt;/code&gt; and &lt;code&gt;std&lt;/code&gt; libraries in a way that can be used in formal proofs of Rust programs in &lt;a rel=&quot;external&quot; href=&quot;https://hax.cryspen.com&quot;&gt;hax&lt;/a&gt;.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;If you want to learn more about how we test and verify Rust libraries, &lt;a href=&quot;mailto:info@cryspen.com&quot;&gt;get in touch&lt;/a&gt;.&lt;/p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Helping Secure Signal&#39;s Post-Quantum Transition</title>
        <published>2025-10-02T00:00:00+00:00</published>
        <updated>2025-10-02T00:00:00+00:00</updated>
        
        <author>
          <name>Unknown</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://pereq-website.pages.dev/blog/signal-spqr-verification/"/>
        <id>https://pereq-website.pages.dev/blog/signal-spqr-verification/</id>
        
        <content type="html" xml:base="https://pereq-website.pages.dev/blog/signal-spqr-verification/">&lt;p&gt;Signal just &lt;a rel=&quot;external&quot; href=&quot;https://signal.org/blog/spqr/&quot;&gt;announced&lt;/a&gt; the deployment
of their new post-quantum ratcheting protocol, called the Sparse
Post-Quantum Ratchet (SPQR), and Cryspen is proud to have contributed
to the formal analysis of the design and implementation of this new
Signal feature.&lt;/p&gt;
&lt;p&gt;The seeds of our collaboration with Signal reach back to 2023, when
Signal first published PQXDH, the post-quantum key establishment
protocol that marked the beginning of Signal’s post-quantum
transition.  We helped Signal to formally analyze and improve
PQXDH, resulting in a &lt;a rel=&quot;external&quot; href=&quot;https://www.usenix.org/conference/usenixsecurity24/presentation/bhargavan&quot;&gt;paper at
Usenix Security&lt;/a&gt;.
This time, Cryspen and Signal agreed to collaborate from the very
beginning of the design process for SPQR all the way through to its
implementation.&lt;/p&gt;
&lt;p&gt;The Signal &lt;a rel=&quot;external&quot; href=&quot;https://signal.org/blog/spqr/&quot;&gt;blog post&lt;/a&gt; wonderfully describes SPQR and the role
formal verification played in its design and implementation.
Here, we will briefly note three contributions Cryspen had towards
this effort, leaving deeper technical details to a future publication.&lt;/p&gt;
&lt;h2 id=&quot;analyzing-the-spqr-protocol-design&quot;&gt;Analyzing the SPQR Protocol Design&lt;/h2&gt;
&lt;p&gt;In our previous analysis of PQXDH, Cryspen collaborated with Charlie
Jacomme at Inria and Rolfe Schmidt at Signal to build formal models of
the protocol that could be analyzed symbolically by
&lt;a rel=&quot;external&quot; href=&quot;https://proverif.inria.fr&quot;&gt;ProVerif&lt;/a&gt; and verified computationally by
&lt;a rel=&quot;external&quot; href=&quot;https://cryptoverif.inria.fr&quot;&gt;CryptoVerif&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;For SPQR, we decided to build models in ProVerif, because the
protocol engineers found it easy to read and write ProVerif,
and the fully automatic tool provided quick and reliable
feedback on each design. We helped Signal engineers write the initial
models, but they were able to modify and maintain these models as the
protocol underwent a series of revisions until it reached its final
form. Using formal verification in this organic way allows protocol
designers to quickly try out new ideas, checking if a design change
breaks a desired security property. When all the protocol details
are settled, the final model can be comprehensively verified for all
desired security goals.&lt;/p&gt;
&lt;p&gt;The ProVerif models for SPQR are maintained in the &lt;a rel=&quot;external&quot; href=&quot;https://github.com/signalapp/SparsePostQuantumRatchet/tree/main/proofs/proverif&quot;&gt;SPQR
repository&lt;/a&gt; and are verified as part of CI.&lt;/p&gt;
&lt;h2 id=&quot;providing-post-quantum-cryptography&quot;&gt;Providing Post-Quantum Cryptography&lt;/h2&gt;
&lt;p&gt;The SPQR implementation uses our &lt;a rel=&quot;external&quot; href=&quot;https://github.com/celabshq/libcrux&quot;&gt;libcrux&lt;/a&gt;
implementation of the &lt;a rel=&quot;external&quot; href=&quot;https://csrc.nist.gov/pubs/fips/203/final&quot;&gt;ML-KEM&lt;/a&gt; post-quantum key encapsulation mechanism. Our Rust implementation is formally verified
for panic-freedom, functional correctness, and secret independence, and hence provides a high degree of assurance.&lt;/p&gt;
&lt;p&gt;Interestingly, Signal’s SPQR design required a novel &lt;em&gt;incremental&lt;/em&gt; API for ML-KEM, different
from the ones usually provided by crypto libraries. At the request of the Signal
developers, we implemented this new API in libcrux and helped them
integrate it into the SPQR implementation.
See our &lt;a rel=&quot;external&quot; href=&quot;https://github.com/celabshq/libcrux/pull/757&quot;&gt;PR&lt;/a&gt; for details on the incremental API, and see &lt;a rel=&quot;external&quot; href=&quot;https://github.com/celabshq/libcrux/blob/825f4a63aad0a1e69e1942d643750bc1f4be63c8/libcrux-ml-kem/tests/self.rs#L135&quot;&gt;this test&lt;/a&gt;
to understand how to use the API.&lt;/p&gt;
&lt;h2 id=&quot;verifying-the-spqr-implementation&quot;&gt;Verifying the SPQR Implementation&lt;/h2&gt;
&lt;p&gt;As the design of SPQR matured, the Signal team started implementing it
in Rust.  At this stage, we collaborated with them to build a
formal verification pipeline for their implementation using
&lt;a rel=&quot;external&quot; href=&quot;https://github.com/cryspen/hax&quot;&gt;hax&lt;/a&gt; and its
&lt;a rel=&quot;external&quot; href=&quot;https://fstar-lang.org/&quot;&gt;F*&lt;/a&gt; proof backend. We helped verify the new code
for panic-freedom and some correctness goals.&lt;/p&gt;
&lt;p&gt;The hax verification scripts are hosted on the &lt;a rel=&quot;external&quot; href=&quot;https://github.com/signalapp/SparsePostQuantumRatchet/tree/main/proofs&quot;&gt;SPQR repository&lt;/a&gt;.
They run in CI and flag errors whenever a code change
breaks some expected invariant and might (say) cause a panic at runtime. These
proofs only cover the core of the new SPQR code, and formally verifying
the full Signal codebase is still some distance away, but it is already
exciting to see how formal proofs like these can be maintained and
extended by Signal engineers in the normal course of their work.&lt;/p&gt;
&lt;p&gt;This experience taught us a lot about real-world code verification
and resulted in several improvements to hax and to our models of
the Rust libraries. We are excited to continue collaborating with
the Signal team to cover more of the Signal codebase and verify
it for more ambitious correctness and security properties in the future.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;To learn more about how Cryspen can help you with your cryptographic
protocol design or software verification, &lt;a href=&quot;mailto:info@cryspen.com&quot;&gt;email us&lt;/a&gt;.&lt;/p&gt;
</content>
        
    </entry>
</feed>
