Verification of Autonomous Neural Car Control with KeYmaera X

Enguerrand Prebet, Samuel Teuber, André Platzer

In the world of autonomous driving, Neural Networks (NNs) are the go-to solution for complex control tasks. However, NNs are notoriously "black boxes," making it difficult to guarantee they won't cause a collision. This paper, a contribution to the ABZ’25 case study, tackles this head-on by using formal methods to prove the safety of NN-based car control.

TL;DR

Researchers used Differential Dynamic Logic (dL) and the KeYmaera X theorem prover to create a formally verified safety "shield" for autonomous highway driving. They demonstrated that while standard reinforcement learning agents often fail in worst-case scenarios, a verified runtime monitor can guarantee collision-freedom over an infinite time horizon, even uncovering significant "Model-to-Simulation" gaps in popular training environments.

What Problem Does This Paper Address?

The core challenge is the safety of Neural Network Control Systems (NNCS). While we can train an agent to drive well in a simulator, how do we know it will remain safe forever?

Most existing verification methods only look a few seconds into the future (reachability analysis). Furthermore, there is often a discrepancy between a formal safety specification and the actual simulation environment used for training—a "sim-to-real" style problem the authors call the Model-to-Simulation (model2sim) gap. The authors aim to provide a rigorous mathematical foundation that bridges the gap between abstract safety proofs and concrete neural network implementations.

Methods

The authors employ a multi-layered formal approach:

  1. Differential Dynamic Logic (dL): They model the car’s movement (continuous dynamics) and the controller’s decisions (discrete actions) as a "hybrid system."
  2. KeYmaera X: A theorem prover used to verify that if a car follows certain acceleration constraints, it is mathematically impossible to collide, regardless of trip length (infinite time horizon).
  3. ModelPlex: A technique that automatically transforms these formal proofs into runtime monitors. These monitors act as a "sandbox" or "shield" (Justified Speculative Control). If the NN suggests an unsafe action, the shield overrides it with a safe fallback (like braking).
  4. NCubeV: A "white-box" verification tool used to check the internal weights of the NN against the formal constraints to find every possible input state where the NN might choose an unsafe action.
  5. Refinement Logic: They prove that a complex model (including the NN's discrete actions) "refines" (follows the rules of) their simpler, proven-safe abstract model.

Datasets

  • highway-env: A popular OpenAI Gym environment for highway driving simulations.
  • ABZ’25 Case Study: The formal specification provided for the competition, which defines the physical constants (max braking, reaction times, etc.).
  • Custom Trained NNs: The authors trained their own NNs using Reinforcement Learning (DQN) within highway-env to test their verification tools.

Key Insights and Ideas

  • The Model2Sim Gap: The authors discovered that highway-env's default "brake" action doesn't always result in deceleration—it actually tries to match a reference velocity. This contradicts the formal specification and can lead to crashes that the simulator ignores but a formal model catches.
  • Euler Crashes: They identified "spurious crashes" caused by the simulator's numerical integration (Euler method). When the simulation step size is too large, the math breaks, causing "impossible" collisions.
  • Infinite Horizon Safety: Unlike many AI safety papers that check if a car is safe for the next 5 seconds, this paper proves safety for any duration, provided the environment behaves within the modeled physical limits.
  • Neglect of Worst-Case Scenarios: RL agents rarely experience emergency braking during training. Consequently, they don't learn to handle it. Formal verification (via NCubeV) was able to find over 14,000 "regions" of state space where the NN would fail, even if it looked "perfect" during standard training.

Key Results

  • Formal Proofs: Successfully proved collision-freedom for both "car-behind" and "car-ahead" scenarios in KeYmaera X.
  • Verification Performance: Verifying a two-layer NN took between 1.9 and 3.6 hours, identifying thousands of counterexample regions where the NN was unsafe.
  • Shielding Success: In a "braking" environment where the standalone NN crashed 99.6% of the time, the JSC (Justified Speculative Control) shield reduced the crash rate to 0% while maintaining high performance (reward).
  • Refinement: Mathematically proved that their NN-specific controller correctly implements the abstract safe controller.

Limitations and Future Work

  • Single Lane Only: The current model focuses on straight-line driving and does not yet account for lane changes or intersections.
  • Environment Assumptions: The proof relies on the assumption that other cars won't perform "impossible" maneuvers (e.g., exceeding physical braking limits).
  • Scalability: While they verified a small NN (2 layers, 16 neurons), verifying much larger, deeper networks remains a computational challenge.
  • Simulator Fidelity: The "Model2Simulation" gap highlights that even "verified" code is only as good as the accuracy of the underlying physical model. Future work involves tightening the link between symbolic models and high-fidelity simulators.

Summary updated

BibTeX
@inproceedings{prebet2025verification,
  author = {Enguerrand Prebet and Samuel Teuber and André Platzer},
  title = {{Verification of Autonomous Neural Car Control with KeYmaera X}},
  booktitle = {ABZ},
  year = {2025},
  url = {https://openreview.net/forum?id=ZSqQmH2BYB},
}
Figure