Towards Automated Formal Verification of zkEVMs Using LLM-Guided Constraint Synthesis
VeriSynth:LLM引导的zkEVM形式化验证框架:zkEVM的隐性语义错误可以绕过密码学证明验证。VeriSynth将LLM严格限制为Rust操作码的翻译前端,输出Python/Z3符号约束,用SMT求解器做最终的正确性仲裁。在首个源码级基准上,检测率超过90%,比生产级手写变异测试套件多发现32个漏洞。
zkEVM手写规范随实现迭代无法扩展,纯LLM方案幻觉频发且缺乏形式保证;VeriSynth将LLM限定为Rust到Z3约束的翻译前端,SMT求解器作为仲裁后端。在首个源码级基准(95个注入漏洞)上,检测率超过90%(87/95),比生产级手写变异测试套件多发现32个漏洞。
将LLM严格限定为Rust到符号约束的翻译前端、SMT求解器作为正确性仲裁后端,可自动化zkEVM形式化验证;首个源码级基准上检测率超过90%(87/95),优于直接LLM基线和生产级手写变异测试(55/95)。
1. 现有zkEVM验证依赖人工编写规范(如手写变异测试),随低层Rust实现频繁优化无法扩展;纯LLM直接生成约束存在幻觉且无形式保证,缺少将Rust操作码隐性语义自动转化为求解器可用约束的工具链,且此前无源码级标准基准。 2. VeriSynth构建闭环流水线:语义分解将栈、内存、存储、gas等多组件状态转换拆分为子任务,检索增强提示提供代码上下文,LLM生成候选Python/Z3约束,验证引导自动修复纠正语法与排序错误,SMT求解器最终仲裁;基准含95个注入漏洞,覆盖正确与错误两类操作码实现。 3. VeriSynth检测87/95漏洞(超过90%),生产级手写变异测试套件仅检测55个(约58%);消融实验显示去除自动修复使检测率从91.6%骤降至66.3%,早期失败主要源于语法与排序错误而非语义理解不足,检索增强和语义分解各自提供独立增益。
首个源码级zkEVM Rust实现验证基准,含正确与错误两类操作码实现,共注入95个漏洞。指标:漏洞检测率。对比:直接LLM基线、对话式LLM基线、生产级手写变异测试套件(检测55/95,约58%)。VeriSynth检测87/95(超过90%)。消融:去除自动修复使检测率从91.6%降至66.3%,早期失败主要为语法与排序错误而非语义理解不足;检索增强与语义分解各自提供独立增益。
- 它要解决什么
- 如何将Rust实现的zkEVM操作码自动转化为可执行形式化验证模型,同时避免LLM幻觉并提供形式化保证?
- 研究路径
- Rust操作码处理器经语义分解拆分为栈、内存、存储、gas等子组件;检索增强提示将相关代码上下文注入LLM;LLM生成候选Python/Z3符号约束;验证引导自动修复识别语法或排序错误并在闭环中重新生成;SMT求解器对最终约束执行可满足性检验,判定实现是否违反操作码规范。
- 这对工程意味着什么
- 在形式化验证规范编写代价高的场景,可采用LLM翻译+SMT仲裁+验证引导自动修复闭环;有效性依赖自动修复消除语法错误,切勿直接将LLM输出作为最终约束并略过求解器仲裁步骤。
- 证据定位
- VeriSynth在95个注入漏洞中检测87个(超过90%),显著优于直接LLM和对话式LLM基线;生产级手写变异测试套件仅检测55个。消融:去除自动修复使检测率从91.6%骤降至66.3%,各组件均有独立贡献。(筛选维度:形式化验证、可复核评测)
- 适用边界
- 基准仅覆盖zkEVM操作码层Rust实现,不涵盖更高协议层或其他语言;注入漏洞的数量(95个)和类型由构建者决定,代表性有限;论文摘录未说明基准覆盖的操作码种类及数量边界。
方法与英文摘要
数据集:首个源码级zkEVM Rust实现验证基准,包含正确与错误两类操作码实现,共注入95个漏洞。流程:①语义分解将栈、内存、存储、gas等多组件状态转换拆分为子任务;②检索增强提示为LLM提供相关代码上下文;③LLM将Rust操作码翻译为候选Python/Z3符号约束;④验证引导自动修复在闭环中纠正语法与类型错误;⑤SMT求解器执行最终正确性仲裁。
Zero-Knowledge Ethereum Virtual Machines (zkEVMs) secure Ethereum rollups by generating zero-knowledge proofs that guarantee off-chain execution correctness. However, subtle implementation bugs (e.g., incorrect gas accounting) can lead to valid proofs certifying semantically faulty states, thereby silently defeating cryptographic guarantees. Formal verification via SMT solvers can prevent this, but is bottlenecked by specification: current zkEVM development practice lacks automated methods to translate Rust opcode handlers into verification models. Current practices rely on unsustainable manual specifications, while LLM-based approaches suffer from hallucination and lack formal guarantees. To address this, we propose VeriSynth, a framework that synthesizes executable Python/Z3 verification models from Rust zkEVM code. VeriSynth enforces a hybrid paradigm: an LLM acts strictly as a formalization frontend to translate code into symbolic constraints, while an SMT solver serves as the correctness arbiter. To handle complex multi-component state transitions, VeriSynth integrates semantic decomposition, retrieval-grounded prompting, and verification-guided auto-repair into a closed-loop pipeline. We evaluate VeriSynth on the first source-level zkEVM verification benchmark, encompassing both correct and faulty opcode implementations. VeriSynth achieves a bug detection rate of over 90%, substantially outperforming direct and conversational LLM baselines, as well as a production-grade handwritten mutation-testing suite. Ablation studies confirm that each pipeline component is critical to the framework's overall effectiveness.