Spec2Code: Mapping Protocol Specification to Function-Level Code Implementation
Yuekun Wang, Lili Quan, Xiaofei Xie, Junjie Wang, Jianjun Chen
Abstract
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.
Ask about this paper
Your agent reads all of it.
Lune indexed this paper to the last equation, along with the top-tier papers that cite it. Ask a question and the answer quotes them.
Builds on11
- Exploring the Potential of ChatGPT in Automated Code Refinement: An Empirical StudyQi Guo, Junming Cao, Xiaofei Xie, Shangqing Liu et al.ICSE 2024 · 107 citations
- Host of Troubles: Multiple Host Ambiguities in HTTP ImplementationsJianjun Chen, Jian Jiang, Hai-Xin Duan, Nicholas Weaver et al.CCS 2016 · 49 citations
- Improving the effectiveness of traceability link recovery using hierarchical bayesian networksKevin Moran, David N. Palacio, Carlos Bernal-Cárdenas, Daniel McCrystal et al.ICSE 2020 · 40 citations
- SpecGen: Automated Generation of Formal Program Specifications via Large Language ModelsLezhi Ma, Shangqing Liu, Yi Li, Xiaofei Xie et al.ICSE 2025 · 25 citations
- Using Consensual Biterms from Text Structures of Requirements and Code to Improve IR-Based Traceability RecoveryHui Gao, Hongyu Kuang, Kexin Sun, Xiaoxing Ma et al.ASE 2022 · 20 citations
Related papers
- ProtocolGuard: Detecting Protocol Non-compliance Bugs via LLM-guided Static Analysis and Dynamic VerificationXiangpu Song, Longjia Pei, Jianliang Wu, Yingpei Zeng et al.NDSS 2026 · 3 citations
- LLMs Unleashed: Generating Protocol Code from RFC SpecificationsJunfeng Long, Jinshu Su, Biao HanAAAI 2026
- Validating Network Protocol Parsers with Traceable RFC Document InterpretationMingwei Zheng, Danning Xie, Qingkai Shi, Chengpeng Wang et al.ISSTA 2025 · 4 citations
- RFCAudit: AI Agent for Auditing Protocol Implementations Against RFC SpecificationsMingwei Zheng, Chengpeng Wang, Xuwei Liu, Jinyao Guo et al.ASE 2025 · 5 citations
- Semi-automated protocol disambiguation and code generationJane Yen, Tamás Lévai, Qinyuan Ye, Xiang Ren et al.SIGCOMM 2021 · 33 citations
