O(x)Caml in Space
242 points
• 4 days ago
• Article
Link
2026 年 4 月 23 日,一个纯 OCaml 实现的 CCSDS(Consultative Committee for Space Data Systems)协议栈,代号为 Borealis,在 DPhi Space 的 ClusterGate-2 载荷模块中成功在低地球轨道启动。该项目由 Parsimoni 开发,实现了端到端加密的命令与控制以及后量子密钥轮换,全部用安全的 OCaml 编写。这一里程碑是历经十年工程攻关、为 OCaml 5 带来安全且高性能多线程能力的成果;Parsimoni 团队把曾被戏言"会到达月球"的设想字面化,将协议栈部署到一颗每 90 分钟绕地球一圈的卫星上。
Borealis 作为守护进程运行在 Arm SoC(四核 Cortex-A53 、 4 GB RAM)的托管载荷环境中。由于卫星没有直接的网络连接,系统采用延迟容忍网络模型,命令和遥测被序列化为 BPv7(Bundle Protocol version 7)包并写入文件系统,DPhi Space 的 API 在卫星过境时转发这些文件。为保障共享硬件上的安全——以防像 "Dirty Frag" 或 "Copy Fail" 之类的内核级漏洞破坏租户隔离——每个数据包都被封装在 BPSec(Bundle Protocol Security)扩展块中。这个加密信封对有效载荷进行加密和认证,确保即便底层 Linux 内核被攻破,卫星运营方或其他租户也无法读取、篡改或伪造内容。
系统还实现了 OTAR(Over-The-Air Rekeying)用于后量子签名密钥 ML-DSA-65,设计以覆盖卫星的 10 到 15 年寿命,允许运营方在无需物理重刷硬件的情况下进行密钥轮换。当前飞行循环在接收新密钥时即刻激活,但协议也支持更保守的地面驱动激活步骤,允许运营方在提交前验证安装。值得注意的是,一旦卫星在轨,主密钥并无轮换路径——在缺乏硬件安全元件(如 TPM)的长期任务中,这是一种现实存在的失败模式。
为提升性能,团队正在引入 OxCaml(Jane Street 的 OCaml 编译器分支)。通过使用 `exclave_ stack_` 注解将分配标记为栈绑定,开发者可以在热路径上消除垃圾回收压力。在一项涉及 2500 万个 CCSDS 包调度的基准测试中,该方法将单包 p99.9 延迟从 29 ns 降至 9 ns,并完全消除了 394 次次要 GC 。这种抖动的减少对具有严格调度截止的实时机载调度至关重要——这是欧盟 ORCHIDE Horizon Europe 项目的核心负载之一。
选择 OCaml 源于对数学严谨性与内存安全的需求:在该领域,C/C++ 的内存损坏约占严重 CVE 的 70% 。采用 OCaml 可消除一整类攻击面,例如在现有 C 库(如 NASA CryptoLib)中常见的堆缓冲区溢出。开发流程采用"纵深防御"策略:针对传输格式使用类型化 schema 、用 GADTs(Generalized Algebraic Data Types)在编译时强制有效的协议状态转换,并与参考实现做互操作测试。这遵循 nqsb-TLS 的做法:同一段代码既可作为飞行软件、地面软件,又可作为测试判定器,从而实现跨角色的逐字节比对。
Borealis 协议栈建立在为期十年的 MirageOS 生产级库之上,MirageOS 最初为云 unikernel 设计。尽管当前部署以 Linux 进程形式运行,而非 unikernel,但它展示了这些函数式系统的适用性。 Parsimoni 的下一个挑战是将该方案扩展到卫星编队,重点包括安全部署、签名更新、载荷隔离和认证。随着把硬件送入轨道变得常态化,行业中最有趣的问题正逐步转向软件层面,这与云计算的发展轨迹相呼应——最终,堆栈比服务器本身更重要。
On April 23, 2026, a pure-OCaml implementation of the CCSDS (Consultative Committee for Space Data Systems) protocol stack, codenamed Borealis, successfully booted in low Earth orbit aboard DPhi Space's ClusterGate-2 payload module. Developed by Parsimoni, the project features end-to-end encrypted command and control with post-quantum key rotation, all written in safe OCaml. This milestone follows a decade-long engineering effort to bring safe, performant multi-threading to OCaml 5, which its creators speculated would eventually reach the moon. The team at Parsimoni took that vision literally, deploying the stack on a satellite that circles the Earth every ninety minutes.
Borealis functions as a daemon running on an Arm SoC (four Cortex-A53 cores, 4 GB RAM) within a hosted-payload environment. Because the satellite lacks direct network connectivity, the system uses a delay-tolerant network model where commands and telemetry are serialized into BPv7 (Bundle Protocol version 7) bundles and written to a filesystem. DPhi Space's API then forwards these files during orbital passes. To ensure security on shared hardware where kernel-level vulnerabilities like "Dirty Frag" or "Copy Fail" could break tenant boundaries, every bundle is wrapped in BPSec (Bundle Protocol Security) extension blocks. This cryptographic envelope encrypts and authenticates the payload, ensuring that even if the underlying Linux kernel is compromised, the satellite operator or other tenants cannot read, modify, or forge the contents.
The system also implements OTAR (Over-The-Air Rekeying) for post-quantum signing keys (ML-DSA-65), designed to last the 10-to-15-year lifespan of the satellite. This allows operators to rotate keys without physically re-flashing the hardware. While the current flight loop activates new keys upon receipt, the protocol supports a more cautious ground-driven activation step where operators verify the installation before committing. The master key, however, has no rotation path once the satellite is in orbit, representing an honest failure mode for long missions lacking hardware-backed secure elements like TPMs.
Looking toward performance optimization, the team is integrating OxCaml, Jane Street's compiler branch for OCaml. By using `exclave_ stack_` annotations to mark allocations as stack-bound, developers can eliminate garbage collection pressure on the hot path. In benchmarks involving 25 million CCSDS packet dispatches, this approach reduced p99.9 latency from 29 ns to 9 ns per packet and eliminated 394 minor GCs entirely. This reduction in jitter is critical for real-time on-board dispatch with hard scheduling deadlines, a workload central to the EU's ORCHIDE Horizon Europe project.
The choice of OCaml is driven by the need for mathematical rigor and memory safety in a domain where C/C++ memory corruption accounts for roughly 70% of severe CVEs. By using OCaml, the team removes entire classes of attack surfaces, such as the heap buffer overflows found in incumbent C-based libraries like NASA CryptoLib. The development process relies on a "defense in depth" strategy: typed schemas for wire formats, GADTs (Generalized Algebraic Data Types) to enforce valid protocol state transitions at compile time, and interop testing against reference implementations. This follows the nqsb-TLS approach, where the same code serves as flight software, ground software, and a test oracle, allowing for byte-for-byte comparison across roles.
The Borealis stack is built on a decade of production-tested libraries from MirageOS, originally designed for cloud unikernels. While the current deployment runs as a Linux process rather than a unikernel, it demonstrates the versatility of these functional systems. The next challenge for Parsimoni is scaling this to a fleet of satellites, focusing on safe deployment, signed updates, payload isolation, and attestation. As launching hardware into orbit becomes routine, the industry's most interesting problems are shifting to the software layer, mirroring the evolution of cloud computing where the stack eventually mattered more than the servers.
55 comments • Comments Link
- OCaml 被用于 2016 年 GHGSat-D 卫星的有效载荷软件:它作为 SystemD 服务通过 D-Bus 运行,使用对称密钥加密,且整个地面处理链也完全用 OCaml 编写,证明了 OCaml 在航天应用中的可行性。
- 在 GHGSat 星座中,16 颗卫星的有效载荷软件仍以 OCaml 为主,尽管较新的组件开始使用 Rust 编写;主要挑战是培训 OCaml 开发人员。
- 常见的困扰是公司声称找不到 OCaml 这样"冷门"语言的人才,但擅长这些语言的人往往难以获得机会,这表明问题更多源于地域、薪资等非技术性限制,而非人才本身短缺。
- OxCaml 在 Rust 和 OCaml 之间提供了一个吸引人的折衷:默认启用 GC,同时可通过栈分配注解在性能关键路径上消除 GC 压力,从而显著降低延迟。
- 在允许使用 Python 的平台上,OCaml 的开发体验通常优于 Rust:OCaml 提供更高效的开发周期,同时仍能保证较强的安全性。
- 只要将垃圾回收(GC)的影响限制在必要的区域,GC 语言就可以接近 C 的性能。 OxCaml 、 .NET 、 Java 等现代实现都表明自动资源管理并不必然导致性能劣势。
- 大型语言模型(LLM)在 Hindley-Milner 类型系统语言(如 OCaml)上的表现令人惊讶,通常能产出优于 Python 或 PHP 的代码,这可能得益于强类型系统作为可验证的"预言机"。
- OxCaml 被视为 Rust 在系统编程领域的有力竞争者:它兼顾安全性和可用性,但因需运行时支持,不适合某些 Rust 擅长的深度嵌入式场景。
- 在卫星软件的选择上,OCaml 被选中而非 Ada 、 Rust 或 Haskell,是因为它在开发速度与可靠性之间取得了良好平衡;OxCaml 的模式系统能在热路径上实现零 GC,同时让其余部分由 GC 管理。
- 卫星软件生态还面临一项挑战:许多 CCSDS 协议需要自行实现,因为缺乏可用的优质开源实现,尤其是 SDLS 安全层。
讨论显示对 OCaml 在航天领域的强烈支持;GHGSat 在 16 颗卫星上的成功部署提供了实证。关键矛盾在于 OCaml 的技术优势与实际招聘难题:与会者指出招聘困难更多来自非技术性限制,而非人才稀缺。 OxCaml 经常被提及为缓解 OCaml 性能问题的演进方案,在保持安全性的同时,可作为许多系统编程任务中 Rust 的可行替代。讨论还涉及语言设计的更广泛趋势:越来越多的 GC 语言采用栈分配等技术以最小化 GC 压力,从而挑战"自动资源管理必然性能低下"的刻板印象。 • OCaml was used for payload software on the GHGSat-D satellite in 2016, running as SystemD services over DBus with symmetric-key encryption, and the entire ground processing chain was also written in OCaml, demonstrating its viability for space applications.
• The GHGSat constellation's payload software remains mostly OCaml across 16 satellites, though newer components are being written in Rust, with the main challenge being developer training in OCaml.
• There's a recurring frustration about companies claiming they can't find talent in "weird" languages like OCaml, while developers skilled in these languages struggle to find opportunities, suggesting the issue is often other constraints like location or pay rather than actual talent scarcity.
• OxCaml offers a compelling middle ground between Rust and OCaml, providing GC by default with the ability to eliminate GC pressure on performance-critical paths through stack allocation annotations, achieving significant latency improvements.
• The development experience with OCaml is often preferred over Rust on platforms where Python is already allowed, as OCaml offers a nicer development cycle while still providing strong safety guarantees.
• GCed languages can achieve near-C performance when garbage is minimized to only necessary areas, with modern approaches in languages like OxCaml, .NET, and Java showing that automatic resource management doesn't have to mean poor performance.
• LLMs show a surprising facility with Hindley-Milner based languages like OCaml, often producing better code in these languages than in more mainstream ones like Python or PHP, likely due to the strong type systems serving as testable oracles.
• OxCaml is positioned as a competitor to Rust for systems programming, offering both safety and ergonomics, though it still requires a runtime making it unsuitable for some deeply embedded applications where Rust excels.
• OCaml was chosen over Ada, Rust, and Haskell for satellite software because it offers a good balance between development speed and trust, with OxCaml's mode system providing zero GC on hot paths while keeping the rest GC-managed.
• The satellite software ecosystem faces challenges with CCSDS protocols requiring custom implementations, as there are no good open-source implementations available, particularly for the SDLS security layer.
The discussion reveals a strong advocacy for OCaml in space applications, with real-world validation from the GHGSat constellation operating successfully across 16 satellites. A key tension emerges between OCaml's technical merits and the practical challenges of developer recruitment, with participants noting that hiring difficulties often stem from non-technical constraints rather than genuine talent shortages. OxCaml is frequently highlighted as an evolution that addresses traditional OCaml performance concerns while maintaining its safety advantages, positioning it as a viable alternative to Rust for many systems programming tasks. The conversation also touches on broader trends in language design, with garbage-collected languages increasingly incorporating stack allocation and other techniques to minimize GC pressure, challenging the assumption that automatic resource management inherently means poor performance.