VeGo: Direct Deductive Formal Verification of Go Programs for Computer Science Education
VeGo:本科生不用学专用验证语言,也能对Go程序做机械形式验证:学形式验证常要同时学Hoare逻辑和Dafny这类专用语言,负担翻倍,很多学生因此放弃。VeGo把规约写进Go注释,文件照常编译运行,后端自动完成验证。教Go或写Go的人可以直接把形式规约带进日常代码。
传统本科形式验证课要学生同时学Hoare逻辑和Dafny等专用规约语言,认知负担双重。VeGo把规约以Go注释嵌入源文件,经SSA-HM[X]框架自动推导验证条件,课堂案例显示文件照常编译并通过机械验证。
把Hoare规约以Go注释嵌入标准源文件,可以消除同时学习专用规约语言的认知双重负担。证据来自SSA-HM[X]框架对课堂案例的机械验证,以及Go具名多返回值与后置条件的结构对应。
1. 旧假设:Dafny、TLA+、Coq要求学生另学一门与日常编程脱节的规约语言,纸笔证明无法机械检验,形式方法进不了本科核心课。 2. 方法与受控检查:选Go做宿主,`//@`注释不破坏合法Go;后端经SSA转换运行HM[X]推断和wp演算,具名多返回值(q,r)直接充当后置条件绑定符。 3. 决定性结果与行动:课堂案例和教材中规约可机械推导;实际用时优先给具名多返回值函数标Ensures,不要转向专用验证语言。
评估基于CS本科课堂案例和教学教材。论文没有给出测试题目数量、规约行数或量化对比指标。与Dafny、TLA+、Coq的比较限于语言选型的定性分析,维度是认知负担、语法噪声、与形式逻辑的对应度,没有系统性基准测试。并发规约支持仍在路线图阶段,未实现。
- 它要解决什么
- 能否让本科生不学专用验证语言,就对日常Go程序写出可机械检验的形式规约?
- 研究路径
- 源码解析`//@`注释后转为SSA。SSA与一阶函数式编程等价,HM[X]约束推断可直接作用于SSA节点。wp演算逆向传播规约,生成验证条件。clopen区间量词被脱糖,插入Reynolds' skip语句保持语义完整。wp与sp的精度对照HM[X]主类型机制,实现合同精度检查。
- 这对工程意味着什么
- 第一步:在Go项目里先给具名多返回值的函数标注Ensures合同,这是获得机械验证支持最直接的路径。要避开的捷径:不要改用Dafny等专用验证语言,那会切断代码与日常编译执行链的连接。
- 证据定位
- 作者在本科课堂案例和CS教材上评估VeGo,验证条件由HM[X]/SSA框架机械推导得出。与Dafny、TLA+的比较只是定性的语言选型分析,论文没有给出量化基准数据。(筛选维度:形式化验证)
- 适用边界
- 评估只覆盖课堂案例和教材,没有测试集规模和量化对比数据。并发规约(Owicki-Gries、Chandy-Misra、认识论时态逻辑)还在路线图阶段。论文未讨论规约标注覆盖率、工具误报率和生产代码库的适配性。
方法与英文摘要
规约用`//@`注释写进标准Go源文件,包括Requires、Ensures、Exsures、Preserves和带素变量的等式推理链。文件仍是100%合法Go,标准工具链照常编译执行。后端把源码转成SSA,利用SSA与一阶函数式编程的理论等价性,运行HM[X]约束推断和wp演算,生成并求解验证条件。clopen区间量词被脱糖,插入Reynolds' skip语句保证语义完整。合同精度检查借用wp/sp与HM[X]主类型机制的类比。
As formal methods are rapidly becoming accessible and practical due to AI coding agents, priority passes to assisting developers and students in generating specifications. Leveraging native HMX/SSA verifiers provide that support with rigorous mathematical guardrails. We present VeGo (Verified Go), a deductive formal verification system that enables direct verification of standard Go source code. VeGo incorporates Hoare-style contracts, loop invariants and integer variants, well-founded recursive measures, block-level scope invariants, and equational reasoning chains with primed variables directly as non-intrusive Go comments. We detail the language selection rationale justifying Go as an ideal balance over C, C++, Java, and Rust, strategically adopting Go's native multiple return values. We detail the tool architecture, exploiting the theoretical equivalence between Static Single Assignment (SSA) form and first-order functional programming to annotate code, desugar of clopen interval quantifiers, add Reynolds' skip statement, provide weakest precondition calculus, and native Hindley-Milner constraint inference, and verification condition resolution over the SSA form. We formalize contract-precision checking (weakest precondition vs. strongest postcondition) using an explicit analogy to type inference. Finally, we evaluate VeGo across educational textbooks and outline a roadmap for formal concurrency specifications using epistemic temporal logic.