SCAFFOLD-CEGIS: Preventing Latent Security Degradation in LLM-Driven Iterative Code Refinement
Yi Chen, Yun Bian, Haiquan Wang, Shihao Li, Zhe Cui

TL;DR
This paper investigates security degradation in iterative code refinement with LLMs, revealing the limitations of static testing and proposing a novel CEGIS-based framework to ensure security consistency.
Contribution
It introduces SCAFFOLD-CEGIS, a multi-agent framework that explicitly enforces security constraints, significantly reducing security degradation during iterative code generation.
Findings
Security degradation occurs in over 43% of iterations without intervention.
Static security testing cannot effectively prevent security degradation.
SCAFFOLD-CEGIS reduces security degradation rate to 2.1% and achieves 100% safety monotonicity.
Abstract
The application of large language models to code generation has evolved from one-shot generation to iterative refinement, yet the evolution of security throughout iteration remains insufficiently understood. Through comparative experiments on three mainstream LLMs, this paper reveals the iterative refinement paradox: specification drift during multi-objective optimization causes security to degrade gradually over successive iterations. Taking GPT-4o as an example, 43.7 % of iteration chains contain more vulnerabilities than the baseline after ten rounds, and cross-model experiments show that this phenomenon is prevalent. Further analysis shows that simply introducing static application security testing (SAST) gating cannot effectively suppress degradation; instead, it increases the latent security degradation rate from 12.5% under the unprotected baseline to 20.8 %. The root cause is…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsSecurity and Verification in Computing · Advanced Malware Detection Techniques · Software Testing and Debugging Techniques
