Least-Squares Slope Attack
- Least-Squares Slope Attack is a targeted adversarial technique that manipulates trends in financial forecasts by optimizing input perturbations under strict bounds.
- It employs least-squares regression to calculate the best-fit slope over forecasting points, enabling controlled directional changes in models like N-HiTS.
- Empirical evaluations reveal substantial slope alterations and stealth effectiveness, highlighting the need for robust security measures in ML pipelines.
The Least-Squares Slope Attack (LSSA) is a targeted adversarial methodology designed to manipulate the long-term directional trend (slope) of financial time-series forecasts. Unlike adversarial perturbations that target classification errors, LSSA seeks to introduce subtle yet strategically significant trend alterations within the prediction outputs of sequence models such as N-HiTS. The attack is formulated by optimizing input perturbations bounded in -norm () to ensure stealthiness, and is characterized by its use of the least-squares best-fit slope to modulate the trajectory of the forecast over the entire prediction horizon. LSSA bypasses common security mechanisms, including CNN-based discriminators, and demonstrates empirical efficacy and stealth in financial forecasting benchmarks (Luszczynski, 24 Nov 2025).
1. Mathematical Framework and Slope Optimization
LSSA departs from endpoint-based adversarial techniques by fitting a least-squares regression across all forecast points. For a time-series input (e.g., 300 days of adjusted prices) processed by an N-HiTS forecaster , the attack objective is to find a perturbation such that the forecast exhibits an anomalous slope in a designated direction (downward, flat, upward).
The least-squares slope over forecast points () is given by: where , .
The slope-based loss function is parameterized to penalize undesired trends: where and are scalar hyperparameters controlling penalty strength.
2. Iterative Adversarial Perturbation Algorithm
LSSA implements projected gradient descent to optimize subject to , maximizing the slope deviation. The canonical iteration is: with and as the total number of steps (typically ).
The stepwise procedure is as follows:
- Initialize
- For :
- Enable gradients on
- Extract features (e.g., rolling means, returns)
- Forecast
- Compute slope
- Calculate loss
- Backpropagate to obtain gradients
- Update
- Project within perturbation bounds
- Detach gradients
Return
3. Integration with N-HiTS and Generative Architectures
LSSA is implemented with direct white-box access to the N-HiTS inference pipeline via PyTorch-Forecasting (encoder length=100, forecast=20), leveraging backpropagation for slope loss optimization through all layers. Feature extraction includes rolling statistics and returns to match the forecasting model’s expected input.
In the generative context, LSSA is incorporated within a Conditional Wasserstein GAN (A-GAN) that produces synthetic 99-day log-return sequences conditioned on actual returns. The generator () yields price-space samples, which are input to N-HiTS. The LSSA loss is appended to the generator’s objective: where is the WGAN critic and modulates the adversarial component. The critic employs a gradient penalty . By backpropagating through N-HiTS into , the model learns to synthesize realistic but slope-manipulated data.
4. Experimental Evaluation and Metrics
Empirical analysis on financial time-series (first 300 days) demonstrates slope manipulation effectiveness and stealth:
| Attack Type | MAE | GenSlope | LS-Slope |
|---|---|---|---|
| Normal | 2.15 | 3.37e–2 | 2.22e–2 |
| FGSM | 2.57 | ≈3.22e–2 | ≈2.34e–2 |
| TIM (Upward) | — | 3.72e–2 | 2.00e–2 |
| LSSA (Upward) | 2.49 | 5.38e–2 | 4.96e–2 |
| LSSA (Downward) | — | — | –5.04e–3 |
LSSA (Upward) increases LS-Slope by +120% versus normal; downward attacks invert the predicted trend. Epsilon sweeps show that LS-Slope under LSSA grows roughly linearly with , ranging from 2.97e–2 (0.5%) to 7.22e–2 (4%), compared to normal’s 2.22e–2.
Discriminator stealth metrics indicate that a 4-layer CNN (trained to detect adversarial samples) achieves only 56.25% accuracy and 26.40% specificity under LSSA; Cohen’s is near random, confirming covert characteristics. In contrast, A-GAN samples are highly detectable (accuracy=92.8%).
On stock “A,” A-GAN manipulates LS-Slope from real data’s –2.41e–3 to 2.17e–1 (a 90× increase), while maintaining moment statistics comparable to the real distribution (MMD=1.2e–4).
5. Implementation Details and Malware Injection
Algorithmic parameters include iterations, , , , (). A-GAN configuration comprises a conditional WGAN with a 4-layer TCN generator and a 5-layer TCN+GRU critic, gradient penalty , and an adversarial loss coefficient across five 50-epoch blocks.
The malware sample is structured to inject the slope attack within the model’s inference library (e.g., in __init__.py), intercepting model calls and embedding the attack code while eliminating torch.no_grad() blocks.
6. Limitations and Security Implications
Adversarial training for N-HiTS is rendered operationally impractical due to rolling window constraints and feature dependencies on prices. A-GAN is susceptible to mode collapse, yielding low-diversity outputs that become less covert. The General Slope Attack (GSA) maintains stealth near endpoints but cannot invert long-term trends.
Security challenges are pronounced: standard input discriminators (e.g., 4-layer CNN) exhibit low specificity (28%) against slope attacks, allowing adversaries to manipulate model outputs while remaining undetected. Malware injection at the model interface enables white-box adversary capabilities, circumventing input validation and gradient-blocking measures.
Recommended countermeasures include adversarial training on less complex models or modified N-HiTS architectures that avoid direct price features, input sanity checks utilizing stronger or ensemble discriminators, and securing the ML pipeline via code hashing, rigorous reviews, and runtime integrity verification.
7. Context and Implications for ML Security
The LSSA underscores the necessity of holistic ML security beyond model-level robustness, extending protection requirements to data pipelines and inference infrastructure. The demonstrated effectiveness of LSSA and related slope-based attacks in manipulating financial forecasts and evading detection mechanisms suggests an elevated risk profile for time-series ML applications within critical domains. A plausible implication is that approaches focusing solely on model architecture are insufficient; comprehensive defenses must encompass pipeline integrity, input validation, and adversarial awareness throughout deployment (Luszczynski, 24 Nov 2025).