MIT 6.5840:Lecture 15 IronFleet
本篇逐行译注 MIT 6.5840 Spring 2026 Lecture 15,覆盖 IronFleet、mechanized verification、Hoare logic、state-machine refinement、invariants、liveness/safety 与 Dafny 示例。
MIT 6.5840:Lecture 15 IronFleet
TL;DR
- IronFleet 的目标:把 distributed systems 的实现、协议和高层 specification 连接起来,用 mechanized verification 检查实现是否满足规范。
- 信任边界:proof 是 untrusted 的;proof checker、specification 和 verifier 构成主要的 trusted computing base(TCB)。
- 核心方法:先用 Hoare logic 验证局部方法,再用 state machines、refinement 和 inductive invariants 连接 implementation、protocol 与 spec。
- Raft 对照:即使 Raft thesis 有 proof、lab 通过 tests,也不能直接推出代码 bug-free;证明必须覆盖实际 code,并且要明确 specification。
- 局限:IronFleet 示例没有 local concurrency、crash recovery 或 verified client libraries;把 verified system 接入更大的 verified system 也并不直接。
名词解释
| 名词 | 含义 | 本讲对应物 |
|---|---|---|
| IronFleet | 面向 practical distributed systems 的 formal verification methodology | implementation → protocol → spec 的 refinement |
| Mechanized verification | 由工具检查 spec、proof 和 implementation 的形式化验证 | proof checker 输出 yes/no |
| Hoare logic | 通过 precondition、postcondition 和 loop invariant 证明程序性质的方法 | Dafny + SMT solver |
| Refinement | 低层行为是高层允许行为的子集 | implementation state machine refine protocol/spec |
| Invariant | 在整个 execution 中保持成立的性质 | Raft 中每个 term 至多一个 leader |
| Liveness | 系统最终持续取得进展的性质 | fairness 下节点反复获得 lock |
| Safety | 系统不会产生非法行为的性质 | 只允许 specification 中的行为 |
| Dafny | 支持 specification、verification 和编译的程序验证语言 | sort.dfy 示例 |
| TCB | Trusted Computing Base | spec 与 proof checker |
目录
| 章节 | 内容 |
|---|---|
| 版本与来源 | 固定 Lecture 15 源文件 |
| 原文逐行翻译 | 按 l-ironfleet.txt 顺序译注 |
| 机制小结 | verification、refinement、invariant 与 liveness/safety |
| 本篇验收 | 源行、图示占位和代码记录 |
版本与来源
- 课程版本:MIT 6.5840 Spring 2026。
- Lecture 源文件:l-ironfleet.txt,160 行,非空源行 139 行,SHA-256:ad9f5d2a8115fe7f1dabcfce4ba788516c215a05763ed8427a6f5007a25f7342。
- 配套论文:IronFleet: Proving Practical Distributed Systems Correct,2015。
- 课程日程:MIT 6.5840 Spring 2026 Schedule。
- 翻译边界:英文源行按原顺序保留,随后给出中文译文;IronFleet、Dafny、Hoare logic、SMT、Z3、TCB、state machine、refinement、invariant、liveness、safety、TLA 和 WF1 等术语原样保留。
- 图片结论:源文件没有独立图片文件;Picture:、Figure 3、Figure 12 和 conceptual picture 等文字占位按原文位置保留。
原文逐行翻译
IronFleet 与形式化验证的动机
6.5840 2026 Lecture 15: Verification: IronFleet
6.5840 2026 年 Lecture 15:Verification:IronFleet。
IronFleet: Proving Practical Distributed Systems Correct (2015)
IronFleet:证明 Practical Distributed Systems 正确(2015)。
Claim: my raft labs are bug-free because
主张:我的 raft labs 没有 bug,因为
(1) I passed all the test cases
(1)我通过了所有 test cases;
(2) Raft thesis has proofs
(2)Raft thesis 中有 proofs。
Q: Convincing?
问题:有说服力吗?
A: No.
回答:没有。
Tests are incomplete, proof could be wrong, proof is not about code. It
Tests 并不完整,proof 可能是错的,而且 proof 针对的不是 code。它
would be nice if there was another way. Today's lecture will be about another
如果还有另一种方式就好了。本讲讨论的就是另一种
way to achieving correctness.
实现 correctness 的方式。
IronFleet
IronFleet
IronFleet。
Formal verification for distributed systems
面向 distributed systems 的 formal verification。
Think about all the papers, all the "what-if"s. This is both an answer to "how
想想所有这些论文、所有这些“what-if”情形。这既是对“如何
to reason about those systems", and also might help more deeply understand why
推理这些系统”的回答,也可能帮助我们更深入地理解为什么
distributed systems are tricky to reason about.
distributed systems 很难进行推理。
By the end of studying this paper, the goal is to know the fundamental
学习完这篇论文后,目标是掌握 distributed systems verification 的基本
distributed systems verification techniques.
techniques。
Basic mechanized verification
Basic mechanized verification
基本的 mechanized verification。
Picture:
Picture:
implementation
implementation。
specification: definition of what system should provide (trusted)
specification:定义系统应该提供什么(trusted)。
proof: steps for showing that spec is satisfied (untrusted)
proof:用于展示满足 spec 的步骤(untrusted)。
proof checker: tool that reads spec, proof, and impl, and outputs "yes" or
proof checker:读取 spec、proof 和 impl,并输出“yes”或
"no" (trusted)
“no”的工具(trusted)。
TCB (trusted computing base) includes spec and verifier
TCB(trusted computing base)包括 spec 和 verifier。
IronFleet methodology 与 Hoare logic
IronFleet methodology.
IronFleet methodology。
Hoare logic:
Hoare logic:
demo
demo。
precondition, postcondition, SMT solver (e.g. Z3), assertions, loop invariants
precondition、postcondition、SMT solver(例如 Z3)、assertions、loop invariants。
sort function
sort function。
- spec (pre+post condition)
- spec(pre+post condition)。
- invariant
- invariant。
- introduce a bug in code -> dafny verification fails
- 在 code 中引入 bug → dafny verification fails。
Dafny can compile the verified code.
Dafny 可以编译已经 verified 的 code。
Lesson: specification is trusted.
Lesson:specification 是 trusted 的。
(Further topics: weakest preconditions, separation logic)
(Further topics:weakest preconditions、separation logic。)
What about distributed systems though?
但 distributed systems 呢?
State machines
State machines
State machines。
Specify overall distributed systems behavior
Specify 整体 distributed systems behavior。
State: per-machine state, network state
State:每台 machine 的 state、network state。
Init ⊆ State
Init ⊆ State。
Next ⊆ State × State
Next ⊆ State × State。
Picture:
Picture:
Spec state machine for lock
用于 lock 的 Spec state machine。
Implementation state machine for lock
用于 lock 的 Implementation state machine。
Concurrency -> interleaving transitions
Concurrency → interleaving transitions。
Transfer packets
Transfer packets。
State machines are just a tool---can be at whatever level
State machines 只是一个 tool——可以处于任意 level。
IronFleet-style refinement
IronFleet-style refinement
IronFleet-style refinement。
Low-level behaviors are subset of high-level behaviors; only care about
Low-level behaviors 是 high-level behaviors 的子集;只关心
"externally visible" events.
“externally visible”的 events。
Picture: lockservice refinement
Picture:lockservice refinement。
Could use stutters (v.s. IronFleet's more complex picture)
可以使用 stutters(相对于 IronFleet 更复杂的图示)。
Refinement is transitive
Refinement 是 transitive 的。
Invariants
Invariants:
Invariants:
Property that holds throughout execution
贯穿整个 execution 都成立的 Property。
Can capture important guarantees, or serve as an intermediate proof step
可以捕获重要 guarantees,或作为 intermediate proof step。
e.g. only one leader per term in Raft implementation
例如:Raft implementation 中每个 term 只有一个 leader。
True after all "atomic" transitions
在所有“atomic” transitions 之后都为 true。
Helps prove refinement
帮助证明 refinement。
IronFleet methodology 的三层结构
IronFleet methodology:
IronFleet methodology:
Figure 3.
Figure 3。
Complex implementation state machine
Complex implementation state machine。
Slightly simpler protocol state machine
稍微简单一些的 protocol state machine。
mathematical integers, unbounded sequences, immutable types, sending
mathematical integers、unbounded sequences、immutable types、发送
high-level messages (rather than bytes)
high-level messages(而不是 bytes)。
Trusted, simpler spec state machine
Trusted 且更简单的 spec state machine。
Q: How to connect pre+postconditions of methods to state machine
问题:如何把 methods 的 pre+postconditions 连接到 state machine
transitions?
transitions?
Q: how to prove refinement (for lock, need a refinement mapping)?
问题:如何证明 refinement(对于 lock,需要一个 refinement mapping)?
将 IronFleet methodology 应用于 Raft
How to apply IronFleet methodology to Raft?
如何将 IronFleet methodology 应用于 Raft?
Figure 3.
Figure 3。
Top-level spec: State is log. Init: empty. Transitions: Commit(op).
Top-level spec:State 是 log。Init:empty。Transitions:Commit(op)。
Prelecture question: where would the leader election restriction go wrong?
课前问题:leader election restriction 会在哪个地方出错?
A: Could go wrong at any step: if the protocol state machine is incorrectly
回答:可能在任何一步出错:如果 protocol state machine 写错了,可能
written, could prove refinement impl -> protocol, but get stuck at protocol ->
证明 refinement impl → protocol,却在 protocol →
spec. However, if protocol is correctly written, then impl -> protocol would
spec 处卡住。然而,如果 protocol 写得正确,那么 impl → protocol 会
get stuck (while protocol -> spec might be provable).
卡住(而 protocol → spec 可能是可证明的)。
Induction
Induction:
Induction:
Fundamental rule in program verification
program verification 中的 fundamental rule。
Loop invariants use induction
Loop invariants 使用 induction。
Inductive invariants for distributed systems
distributed systems 的 inductive invariants。
Conceptual picture.
Conceptual picture。
E.g.
例如:
(exists a valid Transfer packet for e and no node holds lock
(存在一个针对 e 的 valid Transfer packet,且没有 node 持有 lock
\/ all transfer packets are stale and one node holds lock)
∨ 所有 transfer packets 都是 stale 的,且一个 node 持有 lock)。
Proof engineering
Proof engineering:
Proof engineering:
Figure 12, Proof effort.
Figure 12,Proof effort。
Automation; lots of different decision procedures, tradeoffs
Automation;许多不同的 decision procedures,以及 tradeoffs。
Triggers
Triggers。
Libraries
Libraries。
Opaqueness (e.g. temporal logic formulas)
Opaqueness(例如 temporal logic formulas)。
Liveness versus safety
Liveness v.s. safety
Liveness v.s. safety。
Temporal Logic of Actions
Temporal Logic of Actions。
(Network is eventually good) -> every node will hold the lock infinitely often
(Network eventually good)→ every node will hold the lock infinitely often。
Must show:
必须证明:
- for any infinite execution (subject to assumptions), there is a "good" state
- 对于任意 infinite execution(服从这些 assumptions),都存在一个“good” state。
Assumptions are "fairness" assumptions
Assumptions 是“fairness” assumptions。
Reasoning principles like "WF1"
类似“WF1”的 reasoning principles。
Q&A 与局限
10min Q&A
10 分钟 Q&A。
Limitations:
Limitations:
No local concurrency => round robin scheduler
没有 local concurrency ⇒ round robin scheduler。
No crash recovery
没有 crash recovery。
No (verified) client libraries
没有(verified 的)client libraries。
Not clear how to use a verified IronFleet system as part of a bigger verified
还不清楚如何把一个 verified IronFleet system 作为更大的 verified
system.
system 的一部分来使用。
sort.dfy example
sort.dfy example
sort.dfy example。
predicate sorted(s: seq<int>) {
predicate sorted(s: seq<int>) {。
forall i, j :: 0 <= i < j < |s| ==> s[i] <= s[j]
forall i, j :: 0 <= i < j < |s| ==> s[i] <= s[j]。
}
}。
predicate pivoted(s: seq<int>, p: int) {
predicate pivoted(s: seq<int>, p: int) {。
forall i, j :: 0 <= i <= p < j < |s| ==> s[i] <= s[j]
forall i, j :: 0 <= i <= p < j < |s| ==> s[i] <= s[j]。
}
}。
method insertion_sort(a: array<int>)
method insertion_sort(a: array<int>)。
modifies a
modifies a。
ensures sorted(a[..])
ensures sorted(a[..])。
ensures multiset(a[..]) == multiset(old(a[..]))
ensures multiset(a[..]) == multiset(old(a[..]))。
{
{。
var i := 1;
var i := 1;
while i < a.Length
while i < a.Length。
invariant 1 <= i
invariant 1 <= i。
invariant sorted(a[..(if i < a.Length then i else a.Length)])
invariant sorted(a[..(if i < a.Length then i else a.Length)])。
invariant multiset(a[..]) == multiset(old(a[..]))
invariant multiset(a[..]) == multiset(old(a[..]))。
{
{。
var j := i;
var j := i;
while j > 0 && a[j-1] > a[j]
while j > 0 && a[j-1] > a[j]。
invariant 0 <= j <= i
invariant 0 <= j <= i。
invariant multiset(a[..]) == multiset(old(a[..]))
invariant multiset(a[..]) == multiset(old(a[..]))。
invariant sorted(a[..j])
invariant sorted(a[..j])。
invariant sorted(a[j..i+1])
invariant sorted(a[j..i+1])。
invariant pivoted(a[..i+1], j)
invariant pivoted(a[..i+1], j)。
{
{。
a[j-1], a[j] := a[j], a[j-1];
a[j-1], a[j] := a[j], a[j-1];
j := j - 1;
j := j - 1;
}
}。
i := i + 1;
i := i + 1;
}
}。
}
}。
机制小结
1. 从 Hoare logic 到 state-machine verification
Hoare logic 在局部方法层面用 precondition、postcondition 和 loop invariant 描述程序应满足的性质;SMT solver(如 Z3)负责检查这些条件是否足以推出 postcondition。分布式系统需要进一步把每台机器的 state、network state 和 transitions 组织成 state machine,才能表达跨节点行为。
2. Refinement 的三层连接
IronFleet 先验证复杂的 implementation state machine,再把它 refinement 到使用 mathematical integers、unbounded sequences、immutable types 和 high-level messages 的 protocol state machine,最后 refinement 到更简单、trusted 的 spec state machine。低层允许的 externally visible behaviors 必须是高层允许 behaviors 的子集;refinement 的 transitivity 使这条链可以组合。
3. Invariant 与 proof engineering
Inductive invariant 必须在初始化时成立,并在每个 atomic transition 后保持成立。它既可以表达 Raft 的 safety guarantee,也可以作为连接 methods 与 state-machine transitions 的中间 lemma。实际证明还依赖 automation、decision procedures、triggers、libraries 和对 temporal formulas 的 opaqueness 等 proof-engineering 技巧。
4. Safety、liveness 与可信边界
Safety 关注系统不会做错事,liveness 关注在 fairness 和 network 等 assumptions 下系统会持续前进。TLA 的 Temporal Logic of Actions 可用于描述这类性质,但最终仍要明确哪些是 trusted 的 specification、哪些是 untrusted 的 proof,以及 verifier 本身属于 TCB。形式化验证并不会自动消除 specification 错误。
5. sort.dfy 中的 loop invariants
示例中的 sorted 描述全序列有序,pivoted 描述当前插入位置两侧的大小关系;外层 loop 保持前缀有序和 multiset 不变,内层 loop 进一步保持左右区间有序与 pivoted。这说明代码中的 invariant 不是注释,而是 Dafny 验证 insertion sort 正确性的必要 proof obligations。
本篇验收
- [x] 官方 l-ironfleet.txt 已固定:160 行、139 个非空源行,SHA-256 与来源记录一致。
- [x] 源文本的非空行按原顺序逐行保留,中文译文紧随对应英文源行。
- [x] IronFleet、mechanized verification、Hoare logic、state machines、refinement、invariants、proof engineering、liveness/safety 和 limitations 全部覆盖。
- [x] Picture:、Figure 3、Figure 12、conceptual picture 等原文图示占位按原位置保留;源文件没有独立图片。
- [x] sort.dfy 的 predicate、method、loop invariants 和完整代码均保留。
- [x] IronFleet、Dafny、SMT、Z3、TCB、state machine、refinement、invariant、liveness、safety、TLA 和 WF1 等专用词没有强行翻译。
- [ ] 中文译文仍建议进行一次人工术语审校;自动审计只验证源文覆盖与顺序,不证明翻译语义正确。
评论 (0)