Fuzzing the brain: automated stress testing for the safety of ML-driven neurostimulation

Mara Downing, Matthew Peng, Jacob Granley, Michael Beyeler, Tevfik Bultan

TL;DR

This paper introduces a novel approach to automatically test the safety of machine learning (ML) models used in neurostimulation devices. By adapting "coverage-guided fuzzing" from software testing, they can uncover potentially harmful stimulation patterns that traditional methods miss, paving the way for safer and more reliable neural interfaces.

What Problem Does This Paper Address?

As ML models become increasingly sophisticated in generating electrical stimulation patterns for devices like visual prostheses, a critical challenge emerges: ensuring these patterns are safe for direct neural tissue delivery. Current ML models are often trained to optimize for perceptual fidelity, but they don't inherently guarantee adherence to strict biophysical safety limits (e.g., charge density, current). Relying solely on built-in hardware safeguards or penalizing unsafe stimuli during training can obscure the model's inherent safety and prevent thorough validation. This leaves a gap in systematically assessing and quantifying the safety of these ML-driven neurostimulation systems before they are deployed in patients.

Methods

The core innovation is the adaptation of coverage-guided fuzzing (CGF), a technique from software testing, to the domain of neural stimulation. In this context:

  • Fuzzing: The system takes input data (e.g., images for a visual prosthesis) and systematically perturbs it (mutations like rotation, brightness changes, etc.) to generate new test cases.
  • Black-Box Approach: The ML model (stimulus encoder) is treated as a black box; its internal workings are not inspected. The focus is solely on the input-output relationship.
  • Safety Constraints: Predefined biophysical limits (e.g., maximum charge density per electrode, total instantaneous current, number of active electrodes) are formalized as inequality constraints.
  • Violation Detection: If a perturbed input results in stimulation parameters that violate any of these constraints, it's flagged as a "violation input."
  • Coverage Metrics: To guide the fuzzing process and ensure exploration of diverse unsafe behaviors, the authors introduce novel violation-focused coverage metrics. These metrics go beyond traditional neuron coverage and instead quantify:
  • VO-KMVP (Violation-Output K-Multisection Violation Proportion): Measures how thoroughly test cases push stimulation parameters towards physiological limits, identifying inputs that provoke severe violations.
  • VO-KMOC (Violation-Output K-Multisection Output Coverage): Measures how broadly test cases explore the range of possible stimulation patterns across electrodes, emphasizing the diversity of violation types and spatial distributions.
  • Seed Selection: A weighted seed selection strategy is used to prioritize inputs that have previously led to new violations or increased coverage.

Datasets

The paper uses simulated data generated by ML models trained on:

  • Retinal Stimulus Encoders: Models trained on visual data for epiretinal implants.
  • Cortical Stimulus Encoders: Models trained on visual data for cortical implants.

The input data for fuzzing includes:

  • Images from the models' own training distributions.
  • Images from ImageNet, representing out-of-distribution inputs.

The paper does not introduce new datasets but rather uses existing model architectures and training paradigms to evaluate their proposed fuzzing framework.

Key Insights and Ideas

  • Safety as an Empirical Property: The most significant insight is reframing safety not as an abstract training goal but as an empirically measurable property of the input-output mapping. This allows for direct, quantitative assessment.
  • Fuzzing's Power for Rare Failures: CGF is highly effective at uncovering rare but clinically significant safety violations that might be missed by standard testing or validation procedures, especially with out-of-distribution inputs.
  • Violation-Focused Metrics are Key: The proposed VO-KMVP and VO-KMOC metrics are crucial for guiding the fuzzing process. They effectively balance the discovery of severe violations with the exploration of diverse unsafe behaviors, providing more actionable insights than traditional neuron coverage metrics.
  • Trade-offs Between Safety and Performance: The study highlights that optimizing for perceptual fidelity doesn't automatically ensure safety. Different regularization strategies can lead to varying trade-offs, and the fuzzing framework can help quantify these.
  • Biophysical Relevance: By operating directly on stimulation parameters (charge density, current, etc.), the metrics provide results that are directly interpretable in clinically relevant units, bridging the gap between ML outputs and patient safety.

Key Results

  • The violation-focused fuzzing framework systematically uncovered diverse stimulation regimes that exceeded established safety limits in both retinal and cortical ML-driven neurostimulation models.
  • The VO-KMVP and VO-KMOC metrics consistently outperformed basic and neuron-coverage baselines in discovering a higher number and diversity of unsafe outputs.
  • For retinal models, the framework identified physically impossible pulse violations (VPI) that were missed by conventional testing.
  • Regularization strategies for retinal models showed varying impacts: frequency clipping was most effective for VPI violations, while pulse duration and frequency regularization had nuanced effects on other violation types.
  • Cortical models with coactivation-aware loss terms showed improved safety margins by reducing total current and active electrode counts, but none fully eliminated unsafe conditions.
  • The study demonstrated that even biologically motivated modeling choices can introduce new risks if not empirically verified through robust testing.

Limitations and Future Work

  • Simulation-Based: The current experiments rely on simulation-based encoders and safety thresholds derived from published specifications.
  • Hardware-in-the-Loop: Future work should include hardware-in-the-loop validation to incorporate real-world factors like electrode impedance, charge-transfer efficiency, and tissue response.
  • Differentiable Signal: Integrating violation feedback as a differentiable signal during training could enable joint optimization of perceptual fidelity and safety.
  • Functional Outcomes: Extending violation analysis to include functional outcomes and perceptual learning would provide a more holistic safety assessment.
  • Broader Applications: While focused on visual prostheses, the methodology is applicable to other neuromodulatory systems (deep brain, spinal, vagus nerve stimulators).
  • Temporal Dynamics: For systems with time-varying stimulations and violations, mutation options may need modification, but the core CGF framework and metrics remain applicable.

Summary updated

Abstract

<i>Objective.</i>Machine learning (ML) models are increasingly used to generate electrical stimulation patterns in neuroprosthetic devices such as visual prostheses. While these models promise precise and personalized control, they also introduce new safety risks when model outputs are delivered directly to neural tissue. We propose a systematic, quantitative approach to detect and characterize unsafe stimulation patterns in ML-driven neurostimulation systems.<i>Approach.</i>We adapt an automated software testing technique known as coverage-guided fuzzing to the domain of neural stimulation. Here, fuzzing performs stress testing by perturbing model inputs and tracking whether resulting stimulation violates biophysical limits on charge density, instantaneous current, or electrode co-activation. The framework treats encoders as black boxes and steers exploration with coverage metrics that quantify how broadly test cases span the space of possible outputs and violation types.<i>Main results.</i>Applied to deep stimulus encoders for the retina and cortex, the method systematically reveals diverse stimulation regimes that exceed established safety limits. Two violation-output coverage metrics identify the highest number and diversity of unsafe outputs, enabling interpretable comparisons across architectures and training strategies.<i>Significance.</i>Violation-focused fuzzing reframes safety assessment as an empirical, reproducible process. By transforming safety from a training heuristic into a measurable property of the deployed model, it establishes a foundation for evidence-based benchmarking, regulatory readiness, and ethical assurance in next-generation neural interfaces.
BibTeX
@article{downing2026fuzzing,
  author = {Mara Downing and Matthew Peng and Jacob Granley and Michael Beyeler and Tevfik Bultan},
  title = {{Fuzzing the brain: automated stress testing for the safety of ML-driven neurostimulation}},
  journal = {Journal of Neural Engineering},
  year = {2026},
  doi = {10.1088/1741-2552/ae4927},
}
Figure