PDD Kit Uses Formal Proofs to Check Rust Code Against Developer Intent
- Gate
- Machine Learning
- Departs
- Crew
- Alex Lavaee, Matthai Philipose
- Passengers
- 969
PDD Kit turns plain-language requirements into Verus proofs and tests, checking Rust code against an agreed specification and exposing existing login bugs.


Proofs can make an agent’s plan enforceable
Coding agents can now produce tens of thousands of lines in a single feature. Reviewing every line doesn’t scale, and a test suite can look healthy while checking only that the generated code behaves as the agent expected. The harder question is whether it matches what the developer asked for. That gap is where PDD Kit makes its case. It helps a team turn plain-language intent into a formal specification, then usesFrom rough intent to checked behavior
PDD Kit starts with a conversation, not code. Its planning workflow reads the existing implementation, asks questions about ambiguous requirements, and records the answers in an intent document. It turns formalizable requirements into Verus specifications and uses tests for requirements that must remain trusted or can’t be expressed as proofs. The team reviews the plan before the agent implements it. The workflow distinguishes two kinds of evidence. Formal verification proves that code satisfies its specification for every possible input, using a verifier. PDD Kit currently uses Verus, a proof language for Rust co-developed by Microsoft Research, Carnegie Mellon University, VMware Research, ETH Zurich, MPI-SWS, UNSW Sydney, the University of Texas at Austin, the University of Michigan, the University of British Columbia, the University of Wisconsin–Madison, and the Weizmann Institute of Science. Empirical verification runs the code and observes the results. It covers areas a proof can’t inspect, such as third-party cryptography libraries and user interfaces, through unit and end-to-end tests, terminal automation, browser agents, and computer-use agents. A passing test is evidence about the inputs it exercised; it isn’t a proof about every possible input. The boundary between proved code and assumed behavior is the Trusted Computing Base, or TCB. PDD Kit makes that boundary visible and asks developers to approve each trusted component. This is a useful discipline, though it doesn’t remove the need to judge whether the assumptions are sound.
Login is a revealing test case
Pet Store is about 5,000 lines of Rust. Its backend uses Axum and SQLite to handle inventory, promotions, orders, and checkout. The storefront uses Leptos, compiled to WebAssembly. PDD Kit recommends beginning with sensitive parts of an application and expanding verification over time, so the demonstration targets authentication. The developer’s request in Chopin was deliberately brief:Verify the login logic in backend/src/handlers/auth.rs. Here are my requirements:You only get a token with the right password.Only admin accounts get admin tokens.




Choosing what to prove
PDD Kit’s first proposal proved the central login decision while leaving the surrounding handler trusted and tested. The developer wanted the proof to cover more: database lookups are awaited and tokens are signed in the handler, so an implementation change could accidentally alter that orchestration. The team therefore gave the login handler its own asynchronous specification. That moved more of the behavior into the proof, while requiring additional trusted wrappers and assumptions for components such as database lookups, clocks, and JWT signing. PDD Kit presented that tradeoff before the developer chose it, then asked for approval again after updating the plan.
What remains trusted
A proof can’t establish everything about a login system. Verus can’t inspect the implementations of bcrypt, sqlx, or jsonwebtoken in their separate crates. It can’t establish what the SQLite database currently contains or what time the clock returns. It also doesn’t prove that a query finishes promptly, that an error message is clear, or that an unwritten requirement has been met. PDD Kit represents these limits through explicit assumptions, using Verus annotations such as `#[verifier::external_body]` and `external_fn_specification`. The developer approves each trusted piece, and the plan includes tests for every assumed clause. For this login flow, the approved assumptions cover:Customer::find_by_emailandAdmin::find_by_username: a successful awaited lookup returns the row in the corresponding table for the requested email or username, or no row.check_password, a wrapper aroundbcrypt::verify: it errors only when bcrypt can’t read the stored hash, and returnsOk(true)exactly when the password is correct.generate_token: it signs the supplied claims with the configured secret and reports signing failures as HTTP 500.expiry_from_now: it reads the clock and sets expiry 24 hours later.database_error: it turns a failed lookup into the current HTTP 500 response with sqlx’s message.- The login handler shell: it unpacks the request and passes the fields to
login_flowunchanged.
/// Looks up a customer by exact email.
/// Trusted, not proved: the SQL query runs in sqlx, which Verus cannot check.
/// Every customer promise of `login_flow` rests on it.
#[verifier::external_fn_specification]
pub async fn ex_customer_find_by_email(pool: &sqlx::SqlitePool, email: &str)
-> (r: Result
What the proof leaves outside
Formal verification draws a boundary around specific claims. Verus can prove the login logic for every input, but the surrounding system still depends on assumptions about libraries, the database, and the clock. That distinction is more significant than it looks: a proof can be rigorous and still cover only the part whose behavior has been specified./// Reads the clock and sets a token expiry 24 hours later.
/// Trusted, not proved: chrono's clock is outside the proof.
/// It can panic if the time is out of range, as today's login does;
/// that panic is not promised against.
#[verifier::external_body]
pub fn expiry_from_now() -> (r: Expiry)
ensures
// Expiry is exactly 86,400 seconds after the clock reading.
r.exp as int == r.now as int + 86_400,
{
...
}
The clock function’s contract says the returned expiry is exactly 86,400 seconds after the recorded time. Verus accepts that relationship as a trusted boundary; it doesn’t prove what the clock reads, and the function may still panic on an out-of-range time.

login_flow, login_core, lookup_target, decide_login, and issue_token—sit inside the verified core. SQLite queries, bcrypt checks, token signing, clock access, error handling, and request parsing sit outside it. Each outside dependency has a contract the developer accepts, then a planned empirical check. The plan marks a check as planned until it runs; after that, it records the command result and the commit tested.

check_password, Verus takes two clauses on faith; the developer accepts them, and two tests are planned to check the behavior. That makes the tests useful evidence, but it doesn’t turn the bcrypt implementation into part of the proof.

check_password trust card: two clauses are assumed by Verus, accepted by a person, and checked by two tests.
check_password, written before implementation. A passing test is recorded as evidence, not proof.People review the contract
The team reviews an intent artifact: a plain-language rendering of the formal specification that PDD Kit writes as Verus contracts. The coding agent produces the proof, and Verus checks it at build time. If any clause could fail for even one input, the build fails and identifies the clause. So reviewers don’t need to inspect every proof step; they need to decide whether the promises in the spec match the intended behavior. Each function’sensures block states conditions that must hold for every possible input. The clauses read as implications, and one of the most telling examples connects a successful login to a single account throughout: the password must match that account’s stored hash, and the token must carry the same account’s ID and role.

login_flow clause for “You only get a token with the right password.” Reusing the same account a ties the password check to the token claims./// The customer row held by the database for this email, if any.
/// Its meaning comes from Customer::find_by_email's trusted contract.
pub uninterp spec fn customer_on_file(email: Seq<char>) -> Option<customer>;
...
/// Bcrypt's verdict for this password and stored hash:
/// Some(true) for a match, Some(false) for a mismatch,
/// or None if bcrypt cannot read the hash.
/// Its meaning is trusted through check_password.
pub uninterp spec fn bcrypt_verdict(
password: Seq<char>,
hash: Seq<char>
) -> Option<bool>;
pub open spec fn password_matches(
password: Seq<char>,
hash: Seq<char>
) -> bool {
bcrypt_verdict(password, hash) == Some(true)
}
The same approach represents administrator rows with admin_on_file(username) and token contents with token_claims(token, secret). The proof reasons from those abstract values; trusted contracts connect them to actual database lookups, bcrypt checks, and token signing. In effect, the core proof says login handles whatever those dependencies return according to the contract, while the trusted contracts say what each dependency returns.
A ghost function, named_account(email, username), defines which account the request refers to: if an email is supplied, it selects the matching customer row; otherwise, it uses the admin row for the supplied username; if neither lookup finds a row, it returns none. It looks like Rust, but it exists only in the specification. Verus checks this ghost code, and the compiler removes it from the running program.
pub open spec fn named_account(
email: Option<string>,
username: Option<string>
) -> Option<namedaccount> {
match email {
Some(e) => match customer_on_file(e@) {
Some(c) => Some(NamedAccount {
id: c.id@,
password_hash: c.password_hash@,
role: customer_role()
}),
None => None,
},
None => match username {
Some(u) => match admin_on_file(u@) {
Some(a) => Some(NamedAccount {
id: a.id@,
password_hash: a.password_hash@,
role: admin_role()
}),
None => None,
},
None => None,
},
}
}
The developer’s two-sentence request and the “Both ways” design decision become eight guarantees on login_flow. Four preserve existing refusals, keeping the storefront and current API tests working.

login_flow guarantees, including four that preserve current refusal behavior.pub async fn login_flow(
pool: &sqlx::SqlitePool,
config: &Config,
email: Option<string>,
username: Option<string>,
password: &str
) -> (r: Result<string>)
ensures
email is None && username is None
==> (r matches Err(AppError::BadRequest(m))
&& m@ == missing_identity_text()),
r matches Ok(t)
==> (named_account(email, username) matches Some(a)
&& password_matches(password@, a.password_hash)
&& token_claims(t@, config.jwt_secret@) matches Some(c)
&& c.sub@ == a.id && c.role@ == a.role),
(named_account(email, username) matches Some(a)
&& password_matches(password@, a.password_hash))
==> (r is Ok || r matches Err(AppError::Internal(_))),
(email is Some || username is Some)
&& named_account(email, username) is None
==> (r matches Err(AppError::Unauthorized)
|| r matches Err(AppError::Internal(_))),
(named_account(email, username) matches Some(a)
&& bcrypt_verdict(password@, a.password_hash) == Some(false))
==> (r matches Err(AppError::Unauthorized)
|| r matches Err(AppError::Internal(_))),
(named_account(email, username) matches Some(a)
&& bcrypt_verdict(password@, a.password_hash) is None)
==> r matches Err(AppError::Internal(_)),
r matches Ok(t)
&& token_claims(t@, config.jwt_secret@) matches Some(c)
&& c.role@ == admin_role()
==> (email is None && username matches Some(u)
&& admin_on_file(u@) is Some),
r matches Ok(t) && email is Some
==> (token_claims(t@, config.jwt_secret@) matches Some(c)
&& c.role@ == customer_role()),
{
unimplemented!()
}What the proof leaves in trusted hands
The password guarantee rests on a boundary Verus can’t cross. check_password is marked as an external body, so Verus assumes its contract instead of checking its implementation. That contract models bcrypt with bcrypt_verdict, an uninterpreted function with no axioms: the result is successful exactly when the stored hash can be read, and the returned Boolean matches bcrypt’s verdict. The wrapper calls bcrypt::verify and converts errors to strings. As its comment makes clear, every password promise in login_flow depends on trusting this contract.
login_flow accounts for every outcome in the login process: only a successful authentication produces a token. The other paths return errors, including 400 for missing credentials, 401 for a missing account or bad password, and 500 for a failed lookup or unreadable password hash.

There’s a separate limit on what the async proof guarantees. Verus checks an async function’s preconditions when the call creates its future; its postconditions apply only if awaiting that future returns a value. The contract says nothing about whether the database query finishes. A query that hangs violates no postcondition because there’s no result to check. The login_flow documentation states this plainly: “No promise the future completes.”

Small contracts make the flow tractable
The top-level function stays compact because its work is split among smaller functions with their own contracts. lookup_target selects the customer table for a supplied email, or the admin table for a username when no email was supplied; with neither identity, it returns MissingIdentity. login_core awaits the lookup and passes the result to decide_login. That password gate refuses a missing account as unauthorized, returns claims only when the stored hash matches, and assigns the role associated with the selected table: “admin” for an admin lookup and “customer” for a customer lookup. issue_token signs claims or maps a refusal to the corresponding HTTP error.
Verus proves login_flow using the contracts of those pieces. If decide_login changes, Verus needs to recheck that function; it can continue to reason about callers through the contract. This makes the proof easier to maintain, provided the contracts capture the behavior the team actually needs.
Reading the specification file
In verified/src/login.rs, the specification is arranged in layers: headers and types, an abstract model of external behavior, trusted contracts connecting that model to real code, and five proved functions: login_flow, login_core, issue_token, lookup_target and decide_login.

Some external types expose very different amounts of information to the proof. The database connection pool is opaque: only the lookup contracts describe what it returns. A customer row, by contrast, has visible fields. LoginError keeps the reason for refusal separate from its HTTP response: MissingIdentity maps to 400, Unauthorized covers a missing account or wrong password and maps to 401, while an unreadable bcrypt hash and a database query failure map to 500. The latter errors retain their messages.
From approved intent to a checked build
After reviewers check the derived specification against the intent artifact, the developer signs off on the spec. The build plan then gives pdd-prove an approved target to implement and check. For this login, it creates seven tasks: make login.rs build under Verus in the backend crate, prove the decision logic, token issuance and full flow, test the trusted wrappers, and run end-to-end login and token-signing checks.

Each task puts implementation and proof through the same review loop. A coding agent writes both, and Verus checks the result against the formal specification. The trusted boundary gets the tests required by the plan. An LLM verifier compares the intent, specification and results, then sends uncovered requirements back for work. If requirements conflict or the specification itself needs a decision, that question goes to the developer.
The most important guard against “vibe verification” is checking whether the clauses actually rule out bad behavior. A weak invariant can pass a prover while saying very little. To catch that, pdd-prove makes a scratch copy and introduces one bug for each ensures clause—for example, rejecting every login or checking a username before an email. Verus must reject each altered version on the clause it was meant to violate. If a mutant passes, that clause hasn’t constrained the code enough, and the gap returns for review.
The process also holds to the approved contract when tooling hits a limit. If the pinned Verus version can’t express an async construct, the task stops for a team decision rather than switching to a non-async helper or weakening the specification.
What “verified” means here
“Fully verified” needs a precise boundary. Verus proves that the bodies of login_flow, login_core, lookup_target, decide_login and issue_token meet their contracts for every input. Those contracts specify which table is searched, when credentials yield claims, which account ID and role go into the token, and which 400, 401 or 500 response accompanies a refusal.
Several pieces remain trusted and tested rather than proved: both database lookups, bcrypt through check_password, the clock, token signing, database error messages and the handler’s request unpacking. Tests exercise the real bcrypt implementation, SQLite schema and router. The proof also assumes the correctness of Verus, the Rust compiler, Z3 and Verus’s standard library.
That boundary is where the guarantee is most vulnerable. The password claims depend on check_password; claims about which account a token names depend on the two database lookups. Tests provide evidence for those pieces, but no proof covers them. The project expects that trusted boundary to shrink over time, though this example doesn’t establish how far the approach will scale.
Rust, and what teams should expect
PDD Kit currently verifies Rust because Verus works with Rust. A Rust codebase can use it without a language migration; teams working in other languages can port code to Rust and check it against the same specification, or call verified Rust through bindings. There’s also a practical shift in how language choice is weighed: if teams rely less on line-by-line review for generated code, readability may carry less weight than speed and memory safety, as long as changes continue to meet the specification.
PDD Kit remains a research prototype, and proofs still take work—especially the proof construction itself. Clear specifications help control that effort. A sensible starting point is a component where a bug would be costly, such as login, payments or permissions, then expanding piece by piece.
The larger claim is about review. Teams can spend more attention deciding what the software should guarantee, then use proofs to hold the implementation to that decision. That’s a meaningful change in how agent-written code gets checked. It doesn’t remove the need for judgment: the team still owns the intent, and every assumption at the trusted boundary still matters.
Acknowledgments
This work brings together the Microsoft Research Catalyst Lab, GitHub Next and the Research in Software Engineering (RiSE) group. The team thanks Maggie Appleton and Krzysztof Cieślak of GitHub Next for collaborating on Chopin; Nikhil Swamy, Lef Ioannidis, Janardhan Kulkarni and Shuvendu Lahiri for discussions and feedback on formal verification and intent formalization; the F*/Pulse and Verus teams for their support; and Idan Gazit of GitHub Next for supporting the collaboration.