Truss
Truss is a programming tongue optimized for agent-written software. Truss aims to create application additional reliable, secure, and performant by embracing the distinctive strengths of AI agents.
Traditional programming languages were designed for the ergonomics of individual authors, efficiently optimizing for the convenience of penning code. Truss, in contrast, assumes code is no longer written by hand, but alternatively written by AI agents. This essential assumption changes most of the scheme considerations for Truss related to traditional programming languages:
| Traditional programming language | Truss |
|---|---|
| Optimize for individual editing | Optimize for individual verification |
| Optimize for convenience | Optimize for correctness |
| Minimize individual authoring time | Spend tokens at authoring period to enhance enduring correctness and performance |
Rather than optimizing for authoring convenience, Truss requires fairly a bit of reasoning at authoring period to verify a program's correctness and performance. That tradeoff is sensible for agent-written application since it is not a burden to the application engineer and the one-time token expend can create application alongside enduring robustness.
Popular programming languages akin Rust are a small stage in this direction, providing compile-time recollection safety — making Rust code a bit harder to compose for humans, but a awesome tongue mark for AI. Truss takes this idea a few steps further, formally verifying behaviors fine beyond recollection management.
I (Bret Taylor) think we volition likely rewrite most application written before AI since that application is imperfect, insecure, and slow. I would akin to have application that is provably correct, verifiably secure, and incredibly fast, and I would akin to be capable to use agents to create application of unparalleled measure and complexity that has those qualities.
Truss is fair a prototype, but I was expecting to commencement a conversation concerning the platforms we need to scheme to accomplish that vision.
The nuclear component of a Truss package is a contract. A contract specifies data structures and functions alongside alongside their formally verified behaviors, including what they return, what recollection they can access, and what province they can change.
Providers execute contracts. For example, a Map agreement could have multiple providers, a HashMap and a SortedMap. Each provider must provably fulfill all the claims in the contract, and all provider provides evidence of their conformance in the form of a proof alongside the implementation origin 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 Map When your program uses Map, the Truss compiler volition create a evidence of its correctness by relying on the claims in the Map agreement without having to independently verify all provider.
When you tie Map to a provider akin InlineMap, Truss uses the supplied evidence in package.proof to independently verify its conformance, a uncomplicated validation procedure that can be an command of dimension faster than constructing the evidence itself.
This method enables ceremonial verification to measure alongside ample code bases, pushing the bulk of the activity of ceremonial verification to bundle authors; whenever you publish a package, you expend as many tokens generating proofs as you do penning the code, and the programs depending on your bundle 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 regulation proves that the justify survives linking against conforming implementations.
We’re going to create a bundle that replaces one component in a piece of UInt64 words and returns the value it overwrote.
replace-element/ package.truss replace_element.truss inline/ package.truss inline_replace_element.truss package.proof Declare the agreement in replace_element.truss. The agreement guarantees that the component at indicator is replaced by value, and additionally protects against buffer overflow:
contract ReplaceElement { function replace(words: &mutable Slice<UInt64>, index: UInt64, value: UInt64) -> UInt64 requires indicator < words.len ensures outcome == old(words[index]) and snapshot(words) == update(old(snapshot(words)), index, value) terminates effects { read(words), write(words) } } Define the provider in inline_replace_element.truss:
implementation InlineReplaceElement of ReplaceElement { function replace(words: &mutable Slice<UInt64>, index: UInt64, value: UInt64) -> UInt64 { let former = words[index] words[index] = value previous } } Now that we’ve defined an implementation, we can create a evidence that it satisfies the ReplaceElement contract. The outcome of that evidence lives side-by-side alongside the implementation so that clients of this bundle don’t need to reproduce the attempt to demonstrate conformance to the contract.
To create the proof, we run this command in the provider directory, which emits the package.proof file:
To use the bundle in a program, you create a dependency on ReplaceElement and tie it to the provider:
package "hello-world" { requires ReplaceElement from "replace-element" type "1.0.0" tie ReplaceElement to provider "replace-element/inline" type "1.0.0" } Build and run your archetypal program in the getting-started chapter.
If you desire to get a awareness of what Truss contracts can guarantee, obtain a appearance at the examples in the included norm library:
- Sort — Sort a array by one pillar and all key keeps its first payload, equal whenever keys repeat.
- SHA-256 — The streaming agreement proves that the digest covers exactly the bytes accepted, in order, nevertheless you divided them throughout calls.
- HTTP reply framing — The parser finds exactly anywhere the headers end equal whenever the final blank row is divided throughout reads. The bytes that prosecute are motionless accessible to the build reader.
- ZIP extraction — If extraction fails midway through, the reported document and byte counts shield exactly the prefix whose publish was confirmed.
- JSON strings — The agreement proves which Unicode character an escape sequence represents and exactly anywhere the next character begins, including whenever two escapes encode a sole character.
- Socket readiness — A delayed event for a closed association cannot be accepted for a new association that reuses the identical slot.
- CRC-32 — A evidence using the shipping checksum iteration shows that any divided of the identical bytes, including bare chunks, gives the identical checksum as one pass.
- Owned byte buffers — A prosperous append keeps all first byte and adds exactly the bytes supplied. If the append fails, the visitant gets rear the first allocation and contents.
Install Truss from source to compose and run packages. For compiler development, see Build the toolchain.
The truss command supports the following operations:
| Command | Description |
|---|---|
| --version | Print the compiler's publish version. |
| lock [package] [--target <triple>] | Resolve declared requirements and provider variants for the output mark and compose its bundle lock. |
| fetch --locked [package] | Restore pinned requirements from the bundled library, local cache, or recorded Git sources. |
| proof update|check|inspect [package] | Generate, independently replay, or depict the package’s published evidence. |
| check [package] | Check types, contracts, and proofs at the origin level. |
| build [package] | Check the bundle and emit a native executable for the selected target. |
| run [package] [-- <args>...] | Build for the presenter and run the executable. Arguments following -- go to the program. |
| test [package] | Run the pinned cases in package.tests. Use --list to preview cases, --case <name> for exact selection, or --affected to difference alongside the final complete passing run. |
| format [--check | --stdout] <file.truss>... | Format Truss origin records in place, inspect their formatting, or imprint the formatted origin of one file. |
| verify [package] --image <executable> | Use the Rust verifier to independently inspect selected connected code and presenter bindings in a self-hosted build against the pinned package. |
Truss is a project from Bret Taylor.