用大模型将自然语言协议文档转为可测试的正式规范
Synthesizing Precise Protocol Specs from Natural Language for Effective Test Generation
- 分两阶段:先提取协议元素,再结合实现生成形式化规范
- 对5个互联网协议测试,平均恢复92.8%客户端消息类型
- 产出可审查、可版本控制的规范,适合安全关键系统测试
安全与安全关键系统必须严格依据规范进行测试。当前实践依赖自然语言规范手动生成测试用例,效率低且易出错。形式化规范虽适合自动化测试生成,但编写维护困难。本文提出一种两阶段管道,利用大语言模型(LLMs)桥接这一鸿沟:首先从自然语言规范中提取协议元素;其次,借助协议实现,基于这些元素合成并精炼出形式化协议规范,进而用于大规模测试其他实现。该方法优于端到端的LLM测试生成,因其可生成可检查的规范,保留原始文本追溯性;测试生成不再需要大模型;结果规范具备可读性,支持人工审查、版本控制与增量优化;长期还可构建自然语言到形式化规范的映射语料库,反哺模型训练。原型系统AUTOSPEC在五个主流互联网协议(SMTP、POP3、IMAP、FTP、ManageSieve)的RFC文档上验证,采用近期的I/O语法形式化规范与模糊测试框架,平均恢复92.8%的客户端消息类型和80.2%的服务器消息类型,在真实多系统环境下实现81.5%的消息接受率。
原文摘要 · Abstract (English)
Safety- and security-critical systems have to be thoroughly tested against their specifications. The state of practice is to have _natural language_ specifications, from which test cases are derived manually - a process that is slow, error-prone, and difficult to scale. _Formal_ specifications, on the other hand, are well-suited for automated test generation, but are tedious to write and maintain. In this work, we propose a two-stage pipeline that uses large language models (LLMs) to bridge the gap: First, we extract _protocol elements_ from natural-language specifications; second, leveraging a protocol implementation, we synthesize and refine a formal _protocol specification_ from these elements, which we can then use to massively test further implementations. We see this two-stage approach to be superior to end-to-end LLM-based test generation, as 1. it produces an _inspectable specification_ that preserves traceability to the original text; 2. the generation of actual test cases _no longer requires an LLM_; 3. the resulting formal specs are _human-readable_, and can be reviewed, version-controlled, and incrementally refined; and 4. over time, we can build a _corpus_ of natural-language-to-formal-specification mappings that can be used to further train and refine LLMs for more automatic translations. Our prototype, AUTOSPEC, successfully demonstrated the feasibility of our approach on five widely used _internet protocols_ (SMTP, POP3, IMAP, FTP, and ManageSieve) by applying its methods on their _RFC specifications_ written in natural-language, and the recent _I/O grammar_ formalism for protocol specification and fuzzing. In its evaluation, AUTOSPEC recovers on average 92.8% of client and 80.2% of server message types, and achieves 81.5% message acceptance across diverse, real-world systems.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。