Spec2Code: Mapping Protocol Specification to Function-Level Code Implementation
Yuekun Wang, Lili Quan, Xiaofei Xie, Junjie Wang, Jianjun Chen
摘要
Protocol specifications, defined in Request for Comments (RFCs), play a critical role in ensuring the correctness of protocol software systems. To check consistency, specification-implementation pairs are essential for testing and verification. However, existing efforts in specification-to-code mapping remain largely manual and are typically limited to the file level, lacking the fine-grained granularity needed for function-level analysis, which is crucial for effective consistency checking. To address this gap, we present SPEC2CODE, the first LLM-driven framework that automates fine-grained mapping from protocol specifications to function implementations. Given a RFC document and a protocol codebase, SPEC2CODE first performs preprocessing to extract structured specification requirements (SRs) and function-level code representations, along with contextual and dependency information. To ensure scalability, SPEC2CODE employs a two-stage process comprising relevance filtering and clustering-based SR organization to reduce the candidate pairs. For accuracy, SPEC2CODE performs finegrained constraint-level matching on each candidate SR-function pair using LLMs, leveraging enriched context to determine whether a function fully, partially, or does not relate to an SR. We evaluate SPEC2CODE on real-world implementations of HTTP, TLS and BFD protocols, including Apache Httpd, Nginx, OpenSSL, BoringSSL, FRRouting, and BIRD. Experimental results show that SPEC2CODE outperforms four state-of-the-art baselines, achieving up to 49%, 66%, and 66% improvement in precision, recall, and F1, respectively. Additionally, SPEC2CODE successfully recovers the mappings for 16 known inconsistency bugs and discovers 11 previously unreported inconsistencies using an integrated lightweight consistency verifier, 5 of which have been confirmed by project developers.
问 Lune
几分钟读透这篇 Paper,不用再花一下午。
Lune 能读完全文,也能读引用它的顶会 Paper,讲清它的结论、证据和局限,每一点都注明出自哪篇 Paper。不用硬啃,也不靠猜。
脉络
它引用的 Paper11
- Exploring the Potential of ChatGPT in Automated Code Refinement: An Empirical StudyQi Guo, Junming Cao, Xiaofei Xie, Shangqing Liu 等ICSE 2024 · 107 次引用
- Host of Troubles: Multiple Host Ambiguities in HTTP ImplementationsJianjun Chen, Jian Jiang, Hai-Xin Duan, Nicholas Weaver 等CCS 2016 · 49 次引用
- Improving the effectiveness of traceability link recovery using hierarchical bayesian networksKevin Moran, David N. Palacio, Carlos Bernal-Cárdenas, Daniel McCrystal 等ICSE 2020 · 40 次引用
- SpecGen: Automated Generation of Formal Program Specifications via Large Language ModelsLezhi Ma, Shangqing Liu, Yi Li, Xiaofei Xie 等ICSE 2025 · 25 次引用
- Using Consensual Biterms from Text Structures of Requirements and Code to Improve IR-Based Traceability RecoveryHui Gao, Hongyu Kuang, Kexin Sun, Xiaoxing Ma 等ASE 2022 · 20 次引用
相关 Paper
- Validating Network Protocol Parsers with Traceable RFC Document InterpretationMingwei Zheng, Danning Xie, Qingkai Shi, Chengpeng Wang 等ISSTA 2025 · 4 次引用
- ProtocolGuard: Detecting Protocol Non-compliance Bugs via LLM-guided Static Analysis and Dynamic VerificationXiangpu Song, Longjia Pei, Jianliang Wu, Yingpei Zeng 等NDSS 2026 · 3 次引用
- LLMs Unleashed: Generating Protocol Code from RFC SpecificationsJunfeng Long, Jinshu Su, Biao HanAAAI 2026
- RFCAudit: AI Agent for Auditing Protocol Implementations Against RFC SpecificationsMingwei Zheng, Chengpeng Wang, Xuwei Liu, Jinyao Guo 等ASE 2025 · 5 次引用
- Semi-automated protocol disambiguation and code generationJane Yen, Tamás Lévai, Qinyuan Ye, Xiang Ren 等SIGCOMM 2021 · 33 次引用
