← Lab /Software

Iterative LLM code refinement degrades security, but SCAFFOLD-CEGIS limits degradation to 2.1%

Iterative LLM-driven code refinement causes latent security degradation, and the SCAFFOLD-CEGIS framework reduces the degradation rate to 2.1%

Software arXiv 9 Mar 2026 Defense Prototype evidence

Published as “SCAFFOLD-CEGIS: Preventing Latent Security Degradation in LLM-Driven Iterative Code Refinement”

Why it matters

The approach makes AI-assisted iterative coding safer by preventing hidden security regressions that static analysis alone misses.

Summary

SCAFFOLD-CEGIS cuts latent security degradation from 20.8% to 2.1% and attains 100% safety monotonicity while keeping a 77.14% task completion rate. The paper shows that iterative LLM refinement often degrades security-43.7% of GPT-4o chains have more vulnerabilities after ten rounds and degradation persists even with security-hardening prompts (28.6%). Evidence comes from controlled experiments on 96 GPT-4o chains and 288 chains across three models (2,880 iteration steps).

What they found 5

  1. SCAFFOLD-CEGIS reduces latent security degradation to 2.1%

    “the full framework reduces the latent security degradation rate from 20.8% to 2.1%”

  2. The framework achieves 100% safety monotonicity

    “achieves 100% safety monotonicity under our experimental setting”

  3. Iterative LLM refinement often worsens security

    “43.7% of chains have more vulnerabilities at iteration 10 than at baseline”

  4. Degradation persists even with explicit hardening prompts

    “Even under explicit security-hardening prompts, the degradation rate remains 28.6%”

  5. Post-hoc SAST can mask latent degradation

    “Post-hoc SAST yields a higher SSDR (20.8%) than the unsecured Baseline (12.5%)”

Caveats 5

  • SCAFFOLD-CEGIS still leaves 2.1% latent security degradation, so it is not a complete fix.
  • Post-hoc SAST and Hybrid Guard achieve DR=0% and SMR=100% yet SSDR remains high (20.8% and 12.5%), showing static-analysis metrics can be misleading.
  • Task completion rate under SCAFFOLD-CEGIS is 77.14%, indicating some functional loss despite safety gains.
  • The applicability of conclusions is limited to the covered task types; extension to multi-file projects or larger codebases requires further validation.
  • Our experiments are conducted on single-file or smallmodule code samples. The scalability of the framework to industrial codebases, statistical validation on larger sample sets, adaptation to cross-language toolchains, and the design of human-in-the-loop collaboration mechanisms remain for future study.

What’s new here 4

  • Transforms soft-prompt security specifications into explicit, verifiable hard constraints via semantic anchoring.
  • Introduces a four-layer gated verification that enforces correctness, safety monotonicity, change budget, and anchor integrity.
  • Adds failure assimilation to learn from rejected candidates and improve subsequent generations.
  • Detects latent security degradations that static analysis tools miss, such as removed validation logic.