Abstract
Neural Networks (NNs) have become the standard for complex control tasks in autonomous driving, yet their "black box" nature poses significant challenges for safety-critical applications. This paper presents a formal verification framework for NN-based car controllers, developed as part of the ABZ’25 case study. By utilizing Differential Dynamic Logic (dL) and the KeYmaera X theorem prover, we demonstrate that it is possible to guarantee collision-freedom over an infinite time horizon. Our approach bridges the gap between abstract safety proofs and concrete implementations through runtime monitoring and white-box verification, effectively eliminating collisions in scenarios where standard reinforcement learning agents frequently fail.
Introduction
In the domain of autonomous driving, ensuring that a vehicle will never cause a collision is a paramount concern. While Reinforcement Learning (RL) can produce agents that perform well in standard simulations, these agents often lack the robustness required for worst-case scenarios. Traditional verification methods, such as reachability analysis, often only provide safety guarantees for a limited time window.
This research addresses the safety of Neural Network Control Systems (NNCS) by providing a rigorous mathematical foundation for highway driving. We focus on two primary objectives: proving safety for an infinite time horizon and addressing the "Model-to-Simulation" (model2sim) gap—the discrepancy between formal safety specifications and the actual behavior of simulation environments.
Methodology
Our verification pipeline employs a multi-layered formal approach to ensure that the neural controller adheres to physical safety constraints.
1. Differential Dynamic Logic and KeYmaera X
We model the car’s movement as a hybrid system, combining continuous dynamics (the physics of motion) with discrete actions (the controller's decisions). Using Differential Dynamic Logic (dL) and the KeYmaera X theorem prover, we mathematically prove that if a vehicle adheres to specific acceleration and braking constraints, a collision is impossible regardless of the duration of the trip.
2. Runtime Monitoring with ModelPlex
To apply these abstract proofs to a real-time system, we use ModelPlex to generate runtime monitors. These monitors function as a safety "shield" under a framework called Justified Speculative Control (JSC). If the NN suggests an action that violates the proven safety constraints, the shield overrides the command with a guaranteed safe fallback action, such as emergency braking.
3. White-Box Verification with NCubeV
While the shield provides a safety net, we also analyze the internal structure of the NN. Using NCubeV, we check the network's weights against formal constraints to identify every region in the input state space where the NN might choose an unsafe action. This allows for a comprehensive understanding of the agent's vulnerabilities before deployment.
4. Refinement Logic
Finally, we use refinement logic to prove that the concrete discrete actions of the NN-specific controller correctly implement the rules of the simpler, proven-safe abstract model. This ensures that the implementation remains faithful to the mathematical proof.
The Model-to-Simulation (Model2Sim) Gap
A significant finding of this work is the identification of discrepancies between formal models and popular simulators like highway-env.
- Action Semantics: In
highway-env, the "brake" action does not always result in immediate deceleration; instead, it often attempts to match a reference velocity. This contradicts standard formal specifications and can lead to crashes that the simulator might ignore but a formal model would flag as unsafe. - Numerical Integration Errors: We identified "Euler crashes," where collisions occur due to the simulator's numerical integration method. If the simulation step size is too large, the math behind the simulation fails, resulting in physically impossible collisions.
Results
Our experiments utilized NNs trained via Deep Q-Networks (DQN) within the highway-env environment. The key results include:
- Safety Guarantees: We successfully proved collision-freedom for both "car-behind" and "car-ahead" scenarios in KeYmaera X.
- Verification Efficiency: Verifying a two-layer NN (16 neurons) took between 1.9 and 3.6 hours. This process identified over 14,000 regions where the NN would have made unsafe decisions.
- Shielding Effectiveness: In a high-risk braking environment where a standalone NN crashed 99.6% of the time, the JSC shield reduced the crash rate to 0%. Importantly, this was achieved without a significant loss in the agent's performance or reward.
Conclusion and Future Work
This research demonstrates that formal methods can provide a robust safety layer for neural network controllers in autonomous driving. By bridging the gap between symbolic proofs and neural implementations, we can guarantee safety even when the underlying AI is imperfect.
Future work will focus on expanding the model to include multi-lane dynamics, such as lane changes and intersections. Additionally, we aim to improve the scalability of white-box verification to handle deeper and more complex neural architectures, further tightening the link between formal models and high-fidelity simulation environments.
Summary updated