CloakFEM: Agentic FEM Code Generation for Red-Teaming Computational Resource Exhaustion
Organizations: STAR Lab, George Mason University
Abstract
Finite element method (FEM) solvers are foundational to scientific and engineering simulation, yet their susceptibility to efficiency attacks remains largely unexplored. An adversary can craft syntactically valid and runnable FEM programs that complete successfully while forcing excessive computational work, enabling computational denial-of-service (DoS) attacks. Finding such inputs is challenging because FEM programs occupy a vast, structured space constrained by numerical, geometric, and constitutive requirements. We introduce CloakFEM, a domain-guided LLM-agent framework for automatically generating runnable adversarial FEM programs that amplify solver computation. CloakFEM combines LLM-guided search with an FEM-specific intermediate representation and a deterministic validity gate that enforces runnable constraints. Across three FEM stacks, 17 problem classes, and 1,068 seeds, CloakFEM discovers adversarial inputs that substantially amplify solver work while remaining valid and solvable. In the most extreme case, solver iterations increase from 43 to 247,367, a amplification. CloakFEM outperforms five generic black-box baselines and retains an advantage over evolutionary search under a controlled bounded action space. Cross-solver analysis further reveals both problem-intrinsic and solver-specific sources of vulnerability. Our results uncover an underexplored efficiency-attack surface in FEM solvers and show that runnable FEM programs can serve as adversarial inputs.
Figures & tables
| CloakFEM (DeepSeek) | CloakFEM (GPT) | |||||
| Elmer | PDE-Agent | NAFEMS | Elmer | PDE-Agent | NAFEMS | |
| Median | 3.01 | 1.54 | 8.72 | 5.00 | 1.93 | 11.85 |
| Arithmetic mean | 24.17 | 90.30 | 17.88 | 39.59 | 131.34 | 22.77 |
| Geometric mean | 4.79 | 3.32 | 7.52 | 7.24 | 4.92 | 8.37 |
| P75 | 12.08 | 6.38 | 17.22 | 17.18 | 11.03 | 36.47 |
| P90 | 42.33 | 24.00 | 43.36 | 97.04 | 171.21 | 55.30 |
Appendix figures & tables18 assets
Supplementary material from the paper’s appendix.
Appendix
| ( ) | ( ) | |||||
|---|---|---|---|---|---|---|
| Method | Median | P90 | Median | P90 | ||
| Random | 1.000 | 1.228 | 5.9% | 1.000 | 1.250 | 6.5% |
| Evolutionary | 1.000 | 1.920 | 12.8% | 1.087 | 5.358 | 23.8% |
| CMA-ES | 1.000 | 1.215 | 4.7% | 1.000 | 1.656 | 10.4% |
| OnePlusOne | 1.000 | 1.119 | 4.3% | 1.000 | 1.128 | 5.7% |
| ngCMA | 1.000 | 1.307 | 7.6% | 1.000 | 1.938 | 13.4% |
| Method | Calls | Input tokens | Output tokens | Time/seed | Total time |
|---|---|---|---|---|---|
| CloakFEM (DeepSeek) | 171 | 748,918 | 80,022 | 9.9 min | 238.1 h |
| CloakFEM (GPT) | 124 | 468,754 | 48,494 | 13.3 min | 293.6 h |
| Method | Median | P90 | Valid (%) | Incomplete | |||
| Count metrics ( ) | |||||||
| Random | 1.00 | 1.61 | 11.6% | 4.1% | 25.8% | 12 | 82 |
| Evolutionary | 1.14 | 6.47 | 29.9% | 17.2% | 48.2% | 12 | 68 |
| CMA-ES | 1.00 | 1.86 | 12.5% | 5.1% | 43.9% | 14 | 109 |
| OnePlusOne | 1.00 | 1.81 | 12.6% | 5.4% | 63.9% | 20 | 119 |
| ngCMA | 1.00 | 2.17 | 16.3% | 6.8% | 46.6% | 13 | 105 |
| Trajectory | Finite | Median | P90 | Completed | |
|---|---|---|---|---|---|
| Seed 0 | 79 | 1.027 | 1.721 | 19.0% | 53/79 |
| Seed 1 | 79 | 1.017 | 1.901 | 20.3% | 52/79 |
| Seed 2 | 79 | 1.027 | 1.792 | 15.2% | 52/79 |
| Method | Finite | Median | P90 | Completed | |
|---|---|---|---|---|---|
| Evolutionary | 79 | 1.095 | 6.745 | 26.6% | 72/79 |
| Boundary prior (no LLM) | 79 | 1.139 | 19.379 | 39.2% | 46/79 |
| CloakFEM (GPT) | 80 | 2.058 | 125.051 | 61.3% | 54/80 |
| Method | Overall | Surface | Physical | ||
|---|---|---|---|---|---|
| Random | 0.997 | 1.000 | 1.000 | 11.6% | 3.6% |
| Evolutionary | 0.992 | 1.000 | 0.988 | 25.7% | 13.5% |
| CMA-ES | 0.997 | 1.000 | 1.000 | 14.0% | 5.8% |
| OnePlusOne | 1.000 | 1.000 | 1.000 | 17.5% | 5.4% |
| ngCMA | 0.994 | 1.000 | 1.000 | 21.5% | 5.6% |
| CloakFEM (DeepSeek) | 0.970 | 1.000 | 0.942 | 27.8% | 17.9% |
| Physics | Work | Native | scikit-fem | DOLFINx | Transfer | Magnitude | |
|---|---|---|---|---|---|---|---|
| Elasticity | CG | 45 | 10.99 | 10.25 | 10.25 | 42/45 | 42/45 |
| Poisson | CG | 10 | 2.26 | 2.21 | 2.26 | 7/10 | 7/10 |
| Convection–diffusion | GMRES | 8 | 1.80 | 1.51 | 1.51 | 4/8 | 4/8 |
| Stokes | MINRES | 34 | 5.24 | 1.53 | 1.70 | 17/34 | 1/34 |
| Navier–Stokes | Newton | 3 | 12.33 | 9.00 | 9.50 | 3/3 | 3/3 |
| System class | Defense | Paired | Benign overhead | Work ratio | Time ratio | |
|---|---|---|---|---|---|---|
| Biharmonic | Stage-wise CG | 33 | 33/33 | 1.00 | 1.15 | 1.00 |
| Elasticity | CG | 45 | 45/45 | 1.00 | 2.91 | 2.88 |
| Elasticity | CG + Jacobi | 45 | 45/45 | 1.01 | 2.88 | 2.88 |
| Elasticity | GMRES + ILU | 45 | 40/45 | 10.31 | 1.33 | 1.26 |
| Elasticity | CG + AMG | 45 | 45/45 | 5.01 | 2.74 | 2.12 |
| Elasticity | Direct LU | 45 | 45/45 | 2.00 | — | 0.98 |
| IR component | Representative content | Search access |
|---|---|---|
| Physics | Equation or problem-class label | Read only |
| Materials | Region parameters and constitutive values | Editable |
| Conditions | Boundary conditions, loads, and sources | Editable |
| Geometry | Supported parametric dimensions | Editable |
| Mesh edits | Explicit node displacements | Editable |
| Solver state | Method, tolerances, limits, and resolution | No access |
| Editable IR leaf | Seed | Candidate |
|---|---|---|
| Geometry height | ||
| Young’s modulus | ||
| Poisson’s ratio | ||
| Right traction |
| Dataset | Collected | Included | Source representation | Target solver |
|---|---|---|---|---|
| Elmer | 1,087 | 618 | Native .sif / .grd regression cases | ElmerSolver |
| PDE-Agent | 645 | 444 | Versioned benchmark records with parametric meshes | DOLFINx 0.9 + PETSc 3.24 |
| NAFEMS | 14 | 6 | Independently reproduced benchmark IR and .msh meshes | scikit-fem 12.0.2 or DOLFINx scalar bridge |
| Total | 1,746 | 1,068 | Fixed before attack search | |
| Reached | Coverage | Median | Arithmetic mean | P90 | |
|---|---|---|---|---|---|
| 40 | 330/444 | 74.3% | 2.05 | 130.06 | 125.89 |
| 60 | 294/444 | 66.2% | 2.21 | 131.45 | 136.87 |
| 80 | 269/444 | 60.6% | 2.33 | 132.39 | 150.93 |
| 100 | 249/444 | 56.1% | 2.42 | 132.54 | 150.93 |
Adversarial Attacks
Adversarial attacks exploit crafted inputs, poisoned data, or system interactions to manipulate AI predictions, behavior, privacy, or reliability.
See all 470 papers