首页|期刊导航|计算机技术与发展|基于Frama-C的快速排序算法的形式化验证

基于Frama-C的快速排序算法的形式化验证OA

Formal Verification of Quicksort Algorithm Based on Frama-C

中文摘要英文摘要

快速排序作为一种经典的分治排序算法,在操作系统、数据库及嵌入式系统等基础软件领域有着广泛的应用.C.A.R.Hoare 提出算法时已经证明了其算法的正确性,但是对于算法实现的功能正确性仍缺乏系统性研究.快速排序算法的 C 语言实现过程涉及递归调用、指针操作和复杂的分区逻辑,容易引入功能错误(如非严格递增、元素丢失)和安全性问题(如数组越界、递归不终止等).为此,该文采用 Frama-C 平台及其 WP 插件,对快速排序的 C 语言实现进行形式化验证.通过编写精确的 ACSL 规范,定义算法的功能契约和循环不变式,并通过调用 Alt-Ergo、Z3、CVC4 等定理证明器验证算法实现的功能正确性.实验结果表明,Frama-C 成功验证快速排序 C 语言程序的功能正确性,为快速排序算法在关键系统中的可靠应用提供了有力保证.

As a classic divide-and-conquer sorting algorithm,Quicksort is widely used in fundamental software domains such as operating systems,databases,and embedded systems.While C.A.R.Hoare provided a proof of correctness for the algorithm itself upon its intro-duction,systematic verification of its concrete implementations—particularly in C—remains underexplored.The C language implementa-tion of the Quicksort algorithm involves recursion,pointer manipulation,and intricate partitioning logic,making it susceptible to functional errors(such as non-strictly ordered output or missing elements)and security vulnerabilities(such as out-of-bounds array access or non-terminating recursion).To address these issues,we employ the Frama-C platform and its WP plugin to conduct formal verification of a C implementation of Quicksort.By crafting precise ACSL specifications that define functional contracts and loop invariants,and by lever-aging automated theorem provers such as Alt-Ergo,Z3,and CVC4,we verify the correctness of the code.Experimental results confirm that Frama-C is capable of verifying both functional correctness and termination of the Quicksort C program,thereby providing strong as-surance for the reliable deployment of Quicksort in safety-critical systems.

牟欣雨;王旭;江建国

辽宁师范大学 数学学院,辽宁 大连 116029辽宁师范大学 数学学院,辽宁 大连 116029辽宁师范大学 数学学院,辽宁 大连 116029

信息技术与安全科学

程序验证快速排序定理证明器Hoare逻辑Frama-C

program verificationQuicksorttheorem proverHoare logicFrama-C

《计算机技术与发展》 2026 (9)

24-30,7

10.20165/j.cnki.ISSN1673-629X.2026.0081

评论