arXiv:2610.32639cs.NIOct 2026

Manuscript Offprint

arXiv:2610.32639

Peregrine: A Language-Agnostic Packet Processing Intermediate Representation with Formal Guarantees

Sean Rhee, Xiangyu Gao, Srinivas Narayana, Nate Foster, Joseph Tassarotti, Anirudh Sivaraman

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Many different programmable network devices and domain-specific languages (DSLs) for programming them have been developed in recent years. However, the affiliated compiler infrastructure for each DSL has not kept up, leading to unreliable compilation results and ultimately a poor experience for developers. In response to this fragmented ecosystem, we propose an intermediate representation, Peregrine, to consolidate the common compiler functionalities within this domain into a shared, open-source infrastructure.

We designed Peregrine to provide formal guarantees from the beginning, rather than adding them in a later step. The language comes with a formal semantics, along with an equivalence checker written and proven correct in Rocq. Experimental results show that Peregrine is general enough to express multiple applications written in various state-of-the-art network programming languages. The equivalence checker designed in Peregrine can be used for validating the correctness of a range of untrusted compiler passes, as well as for other surprising use cases such as certifying the correctness of packet classification algorithms within a reasonable amount of time.

1 Introduction

Recent years have seen a proliferation of network programmability in many different forms, ranging from programmable switches to smart network interface cards to programmable host kernels and Layer 7 proxies. Many production use cases have emerged including traffic engineering, network virtualization [54], network management [63], access control enforcement in NICs [35], in-band network telemetry [50], and in-network assistance for collective communication [40].

However, we also see growing pains. One is the fragmented ecosystem of domain-specific languages (DSLs), e.g., the NPL [11] and P4 [29] languages share many similarities but are distinct DSLs. Another is the presence of completely different ecosystems for switches (P4), hosts (eBPF), user space networking (DPDK), SmartNICs (various C-based SDKs), etc. And on top of this all is the general difficulty of building high-quality compilers and static analysis tools: developers with expertise to work on compilers and tools for niche domains such as packet processing are hard to find; we have also heard this sentiment echoed in conversations with engineers in industry.

A natural solution to this kind of profusion of incompatible frontend languages/APIs and backend compiler targets is a common intermediate representation (IR) that is sandwiched between the language and the target. An IR can consolidate common compiler (and static-analysis) functionality into a shared infrastructure that can be maintained by an open-source community of developers, allowing scarce developer resources to focus on a small number of common and high-impact compiler optimizations. A concrete payoff of having a mature IR is that new languages can be brought up faster (e.g., Swift and Rust with LLVM), and likewise, new backend targets can be added quickly (e.g., RISC-V with LLVM).

This paper takes inspiration from the success of IRs in other domains, notably LLVM [45] for general-purpose computing, XLA [15] for machine learning, and CIRCT [3] for hardware design. Namely, we have developed a new IR—Peregrine—for the specialized domain of packet processing. However, the nature of packet processing workloads presents both challenges and opportunities when developing such an IR.

In particular, packet processing is a challenging domain with a premium on high performance (e.g., line rate, low latency), but where the domain simultaneously has severe resource constraints (e.g., limited number of pipeline stages in a programmable switch). In response, several compilers for this domain have employed sophisticated search-based techniques (e.g., backtracking [4], superoptimization [72], synthesis [38], ILP engines [39, 41, 42], and SMT solvers [36]). However, search-based techniques that rely on blackbox components like solvers introduce the possibility of miscompilation bugs in compiler-generated code [58, 59], which can inadvertently affect billions of packets per second.

At the same time, however, packet processing languages have limited expressiveness thereby affording new opportunities. Notably, the absence of unbounded loops means that equivalence checking of many packet processing languages is decidable [34] and post hoc validation of compiler transformations is relatively straightforward, unlike in many general-purpose languages [59].

To this end, we propose a formally verified IR infrastructure for packet processing that rules out many compiler pass bugs by construction. Leveraging the restricted nature of packet processing (and hence our IR), the core mechanism within our IR is a formally verified equivalence checker of Peregrine IR programs. This verified equivalence checker allows us to validate the behavior of untrusted compilers after the fact: the compiler's output is retained only if the equivalence check between the original and compiled program succeeds, else the output is discarded and an error is returned. A verified equivalence checker permits the use of cutting-edge compilers without risking bugs, e.g., those based on unvetted community contributions [57], those based on the aforementioned search techniques, and compilers based on generative AI [27].

We provide motivation for why such an IR is desirable and why we opted to design a new one rather than leveraging an existing IR (Section 3). We also describe the design (Section 4) of our IR and present an initial implementation for an equivalence checker that converts two IR programs into an SMT expression, querying the Z3 SMT solver [21] on this SMT expression to verify whether these two programs are equivalent. We guarantee the correctness of this checker by using Rocq, an interactive theorem prover, to formalize Peregrine's semantics and prove the checker correct (Section 5). We apply this checker to a variety of use cases and validate transformations applied to P4 and eBPF, among other targets.

We evaluate Peregrine on a diverse set of open-source applications (Section 6) and show that it is expressive enough to represent benchmarks spanning multiple network applications and source languages. As initially intended, Peregrine can verify semantic equivalence across compiler transformations. Beyond this original goal, it can also establish equivalence between different algorithms implementing the same function (e.g., packet classification). With these capabilities, Peregrine validates correct compiler transformations and successfully uncovers bugs in existing compilers.

Our contributions can be summarized as follows:

  • We identify fragmentation in the packet-processing domain as a critical obstacle, and propose a unifying IR as a principled solution.

  • We design and implement Peregrine, a unifying IR for packet processing, together with Rocq-based mechanized proofs that formally establish the correctness of translations within the IR.

• We evaluate Peregrine across diverse applications and source languages, demonstrating its generality and scalability. We further use its verification capabilities to uncover both previously known and previously unknown bugs in existing compilers.

References (45)