Full Report
Contents8 sections
Truss
Truss
Overview
Truss is a programming language optimized for agent-written software. Truss aims to make software more reliable, secure, and performant by embracing the unique strengths of AI agents.
Traditional programming languages were designed for the ergonomics of human authors, effectively optimizing for the convenience of writing code. Truss, in contrast, assumes code is no longer written by hand, but instead written by AI agents. This fundamental assumption changes most of the design considerations for Truss relative to traditional programming languages:
| Traditional programming language | Truss |
|---|---|
| Optimize for human editing | Optimize for human verification |
| Optimize for convenience | Optimize for correctness |
| Minimize human authoring time | Spend tokens at authoring time to improve enduring correctness and performance |
Rather than optimizing for authoring convenience, Truss requires quite a bit of reasoning at authoring time to verify a program's correctness and performance. That tradeoff is sensible for agent-written software because it is not a burden to the software engineer and the one-time token spend can produce software with enduring robustness.
Popular programming languages like Rust are a small step in this direction, providing compile-time memory safety — making Rust code a bit harder to write for humans, but a fantastic language target for AI. Truss takes this idea a few steps further, formally verifying behaviors well beyond memory management.
I (Bret Taylor) think we will probably rewrite most software written before AI because that software is imperfect, insecure, and slow. I would like to have software that is provably correct, verifiably secure, and incredibly fast, and I would like to be able to use agents to produce software of unparalleled scale and complexity that has those qualities.
Truss is just a prototype, but I was hoping to start a conversation about the platforms we need to design to achieve that vision.
How Truss Works
The atomic unit of a Truss package is a contract. A contract specifies data structures and functions along with their formally verified behaviors, including what they return, what memory they can access, and what state they can change.
Providers implement contracts. For example, a Map contract could have multiple providers, a HashMap and a SortedMap. Each provider must provably satisfy all the claims in the contract, and each provider provides evidence of their conformance in the form of a proof alongside the implementation source code.
library/collections/map/
map.truss # The Map contract
package.truss # Map dependencies
inline/
inline_map.truss # InlineMap implementation of Map
package.truss # InlineMap dependencies
package.proof # Evidence that InlineMap satisfies Map
sorted/
sorted_map.truss # SortedMap implementation of Map
package.truss # SortedMap dependencies
package.proof # Evidence that SortedMap satisfies MapWhen your program uses Map, the Truss compiler will generate a proof of its correctness by relying on the claims in the Map contract without having to independently verify each provider.
When you bind Map to a provider like InlineMap, Truss uses the supplied evidence in package.proof to independently verify its conformance, a simple validation process that can be an order of magnitude faster than constructing the proof itself.
This approach enables formal verification to scale with large code bases, pushing the majority of the work of formal verification to package authors; when you publish a package, you spend as many tokens generating proofs as you do writing the code, and the programs depending on your package don’t need to recreate your efforts.
Truss brings verification all the way to code generation. A provider proves that it implements the contract. The compiler proves that its translation preserves the body’s observable behavior. A separate-compilation rule proves that the guarantee survives linking against conforming implementations.
Example
We’re going to make a package that replaces one element in a slice of UInt64 words and returns the value it overwrote.
replace-element/
package.truss
replace_element.truss
inline/
package.truss
inline_replace_element.truss
package.proofDeclare the Contract
Declare the contract in replace_element.truss. The contract guarantees that the element at index is replaced by value, and also protects against buffer overflow:
contract ReplaceElement {
function replace(words: &mutable Slice<UInt64>, index: UInt64, value: UInt64) -> UInt64
requires index < words.len
ensures result == old(words[index])
and snapshot(words) == update(old(snapshot(words)), index, value)
terminates
effects { read(words), write(words) }
}Define the Provider
Define the provider in inline_replace_element.truss:
implementation InlineReplaceElement of ReplaceElement {
function replace(words: &mutable Slice<UInt64>, index: UInt64, value: UInt64) -> UInt64 {
let previous = words[index]
words[index] = value
previous
}
}Generate the Contract Conformance Proof
Now that we’ve defined an implementation, we can generate a proof that it satisfies the ReplaceElement contract. The result of that proof lives side-by-side with the implementation so that clients of this package don’t need to reproduce the effort to prove conformance to the contract.
To generate the proof, we run this command in the provider directory, which emits the package.proof file:
truss proof updateUse the Package
To use the package in a program, you create a dependency on ReplaceElement and bind it to the provider:
package "hello-world" {
requires ReplaceElement from "replace-element" version "1.0.0"
bind ReplaceElement to provider "replace-element/inline" version "1.0.0"
}Try it Yourself
Build and run your first program in the getting-started chapter.
(注:更多技术实现细节与完整 API 文档请查阅原项目 README)