One email each morning — yesterday's AI, sortedGet it in your inbox

METAL LAB

Frequency-Aware Continual Learning for Smart Contract Vulnerability Detection with Large Language Models

arXiv:2608.196802026-08-21

A smart-contract vulnerability detector that keeps learning new bug types without forgetting old ones, then folds everything into one model

New categories of smart contract vulnerabilities keep emerging, but retraining a large language model from scratch every time is too costly. The researchers built a three-stage pipeline that adapts cheaply, rehearses at-risk knowledge to avoid forgetting, and merges all learned versions into a single deployable model. On the DIVE benchmark of real smart contracts, the merged model came within 2.7% of the accuracy of training separate models per task, while merging took only 156 milliseconds.

What they did

  1. Problem: deployed smart contracts can't be patched afterward, so vulnerabilities must be caught beforehand, but new attack patterns keep appearing over time; retraining the whole model each time is prohibitively expensive, and keeping separate models per vulnerability type is costly to store and run.
  2. Method 1 (FA-LoRA): keeps the large language model's core weights frozen and trains only a tiny slice of parameters (0.4% of the total), performing this lightweight adaptation in the Fourier (frequency) domain with a learnable gate that decides which frequency components matter most.
  3. Method 2 (FAR): sequential training across tasks causes 'catastrophic forgetting' of earlier knowledge, so the method tracks how much each training example's loss (prediction error) changes over time and prioritizes replaying examples that are most at risk of being forgotten.
  4. Method 3 (APPM): since separate adapters trained per task must eventually become one deployable model, this stage picks the adapter that generalizes best as a protected 'anchor,' then combines the rest through weighted averaging and lets frequency gates compete with each other during merging.
  5. Result: FA-LoRA outperformed standard LoRA and QLoRA while using only 0.4% trainable parameters; FAR reached an average Micro-F1 of 0.8022 across sequential tasks; APPM's merged model stayed within 2.7% of the independently-trained-per-task upper bound (Micro-F1 0.8085), merging in 156 milliseconds with no extra runtime memory.
Fig. 1: Overview of the proposed continual learning framework for LLM-based smart contract vulnerability detection.
Fig. 1: Overview of the proposed continual learning framework for LLM-based smart contract vulnerability detection.
Fig. 2: Architecture of FA-LoRA.
Fig. 2: Architecture of FA-LoRA.
TABLE I: DIVE benchmark statistics.
Splittask_Atask_Btask_Ctask_D
Train5,2625,2625,2625,262
Validation542504536651
Test530542513648
Total6,3346,3086,3116,561
Fig. 3: The FAR mechanism performing forget-aware prioritization via per-sample loss recomputation and temperature-scaled softmax sampling.
Fig. 3: The FAR mechanism performing forget-aware prioritization via per-sample loss recomputation and temperature-scaled softmax sampling.
Fig. 4: The two-stage APPM workflow.
Fig. 4: The two-stage APPM workflow.
TABLE II: Hyperparameter Configuration
HyperparameterValue
FA-LoRA rank r [16]16
Frequency mode [5]High-frequency retention
Retain fraction γ [5]0.2
Optimizer [30]AdamW
Learning rate (CL) [16]5×10−5
Learning rate (PEFT) [16]3×10−5
Batch size B [16]8
Max sequence length1,024
Epochs per task (CL)3–5
Epochs (PEFT)3
Replay buffer capacity [6]2,000
Replay batch ratio [6]0.25
FAR temperature τ2.0
APPM protection ρ1.0
Fig. 5: Continual learning algorithm comparison on the DIVE benchmark. Grouped bars show per-task Micro-F1 for each method, with dashed lines indicating the Independent single-task upper bound.
Fig. 5: Continual learning algorithm comparison on the DIVE benchmark. Grouped bars show per-task Micro-F1 for each method, with dashed lines indicating the Independent single-task upper bound.
Fig. 6: APPM merging comparison on the DIVE benchmark. Grouped bars show per-task Micro-F1 for each merging method, with dashed lines indicating the Independent single-task upper bound. APPM achieves the best average Micro-F1 of 0.8085, closest to the Independent upper bound.
Fig. 6: APPM merging comparison on the DIVE benchmark. Grouped bars show per-task Micro-F1 for each merging method, with dashed lines indicating the Independent single-task upper bound. APPM achieves the best average Micro-F1 of 0.8085, closest to the Independent upper bound.
TABLE III: Parameter breakdown of FA-LoRA.
ComponentParams (M)Fraction
Total1,241.0100.0%
Frozen (LLaMA base)1,235.899.6%
Trainable (FA-LoRA)5.20.4%
— LoRA (𝑼,𝑽)5.00.40%
— Gates (𝒈)0.20.02%
Per-task storage∼10 MB
Fig. 7: APPM component ablation. All variants merge 4 FAR adapters. The full APPM configuration achieves the best balance across all four tasks, while removing either anchor protection or frequency competition degrades performance, so both mechanisms are necessary.
Fig. 7: APPM component ablation. All variants merge 4 FAR adapters. The full APPM configuration achieves the best balance across all four tasks, while removing either anchor protection or frequency competition degrades performance, so both mechanisms are necessary.
Fig. 8: Sensitivity analysis across four hyperparameter dimensions. (a) LoRA rank r is robust with ΔF1=0.0041. (b) Frequency retention γ is similarly insensitive with ΔF1=0.0022. (c) APPM protection ρ is the only impactful parameter, yielding +3.07% monotonic improvement. (d) FAR temperature τ has negligible impact with ΔF1=0.0021.
Fig. 8: Sensitivity analysis across four hyperparameter dimensions. (a) LoRA rank r is robust with ΔF1=0.0041. (b) Frequency retention γ is similarly insensitive with ΔF1=0.0022. (c) APPM protection ρ is the only impactful parameter, yielding +3.07% monotonic improvement. (d) FAR temperature τ has negligible impact with ΔF1=0.0021.
TABLE IV: Comparison of PEFT methods on the full DIVE dataset without task splitting.
MethodQuant.Trainable (M)Storage (MB)Micro-F1Macro-F1Subset Acc.
1B3B1B3B1B3B
WaRA [15]35.77136.50.83980.85150.65290.71330.55440.5840
QLoRA [9]1.726.60.81850.83650.61330.64070.51810.5298
SLoRA [17]6.8526.20.81380.83050.59450.62630.49660.5262
LoRA [16]bf163.4213.00.80940.83700.56130.63560.48450.5428
FourierFT [13]0.160.60.74490.78880.47240.55850.34710.4331
FouRA [5]0.552.10.76350.80200.49980.59300.40040.4648
FA-LoRA2.6210.00.81850.84240.59040.66160.50740.5544
(b) Sensitivity to frequency retention γ.
(b) Sensitivity to frequency retention γ.
(c) Sensitivity to APPM protection ρ.
(c) Sensitivity to APPM protection ρ.
TABLE V: Resource metrics for adapter merging methods. All methods produce identical model architectures.
MethodMerge (ms)CPU Δ(MB)SpeedupΔInd
Simple-Mean1020.070×+5.5%
TIES [40]2,1230.03.4×+5.5%
DARE [44]4,2040.01.7×+7.9%
HAM g=27,16468.11.0×+11.0%
SFA a=0.5720.0100×+33.0%
APPM (ours)1560.046×+2.7%
(d) Sensitivity to FAR temperature τ.
(d) Sensitivity to FAR temperature τ.
TABLE VI: Backward evaluation matrix for FAR. Bold entries denote in-task F1, entries below the diagonal denote backward transfer, and entries above the diagonal denote forward transfer.
After trainingtask_Atask_Btask_Ctask_D
task_A0.74950.61210.63310.6028
task_B0.72530.75030.73030.7065
task_C0.71620.72260.89740.8864
task_D0.71280.71710.89350.8854
Forgetting−0.0367−0.0332−0.0039

Why it matters

For blockchain security teams, this means a detection model can absorb newly discovered vulnerability types cheaply and still ship as a single unified model, rather than juggling separate models or paying for full retraining. It offers a practical path for keeping up with an auditing environment where threat knowledge changes constantly.

Terms in this paper

  • LoRA (Low-Rank Adaptation) · a technique that adapts a large model to a new task by training only small extra matrices instead of the whole model
  • Catastrophic Forgetting · when a model loses previously learned knowledge while learning something new
  • Fourier Transform · a mathematical transform that breaks data down into different frequency components
  • Adapter · a small add-on module trained for a specific task while the main model stays frozen
  • Micro-F1 · a metric combining precision and recall across multiple labels, used here since a contract can have several vulnerability types at once

Original abstract (English)

Smart contract vulnerability detection with Large Language Models (LLMs) faces three causally linked challenges. First, new vulnerability categories demand parameter-efficient adaptation, since full retraining is prohibitive for sequentially arriving tasks. Second, training per-task adapters on a shared backbone causes catastrophic forgetting of previously learned vulnerabilities. Third, the resulting multiplicity of adapters must be consolidated into a single model, since task identity is unknown at inference time. Each challenge arises directly from the solution to its predecessor, making an integrated framework essential. We propose a three-stage pipeline in which each stage addresses one challenge and feeds into the next. The adaptation stage uses Frequency-Aware Low-Rank Adaptation (FA-LoRA), which performs adaptation in the Fourier domain with per-frequency importance gates, requiring only 0.4% trainable parameters while outperforming standard LoRA and QLoRA. The continual learning stage applies Forget-Aware Replay (FAR), which uses these frequency gates to estimate per-sample forgetting risk via loss dynamics and prioritizes vulnerable knowledge for rehearsal, achieving an average Micro-F1 of 0.8022 across sequential tasks. The deployment stage employs Anchor-Protected Progressive Merging (APPM), which exploits the asymmetric generalization produced by FAR training to identify the strongest-generalizing adapter as an anchor and consolidates all adapters into a single model via anchor-protected weighted merging with frequency-domain gate competition. APPM achieves a Micro-F1 of 0.8085, within 2.7% of the independent per-task upper bound, at a merge cost of 156 ms and no additional runtime memory. Experiments on DIVE confirm the framework effectively addresses all three challenges for evolving blockchain ecosystems.

Authors · Tenghui Huang, Jiawen Kang, Dongning Liu, Changyan Yi, Chengjun Cai, Anjia Yang, Li Li, Dong In Kim

Read on arXiv

Latest papers

All papers →

Latest from METAL LAB

Figures: Tenghui Huang et al., arXiv:2608.19680, arxiv-nonexclusive