Frequency-Aware Continual Learning for Smart Contract Vulnerability Detection with Large Language Models
智能合约漏洞检测AI能不断学新漏洞、不忘旧知识,还能合并成一个模型上线
智能合约的漏洞类型在不断增加,但每次都把大语言模型全部重新训练一遍成本太高。研究团队设计了一套三阶段方案,先用极少参数完成轻量适配,再通过有针对性的复习防止遗忘旧知识,最后把多个阶段学到的模块合并成一个统一模型。在真实智能合约数据集DIVE上,合并后的模型性能与逐任务单独训练的理论上限相差仅2.7%,而合并过程只需156毫秒。
他们做了什么
- 问题:已部署的智能合约无法事后修改,漏洞必须提前发现,但新的攻击手法不断出现;每次都全量重训大模型代价太高,而给每类漏洞单独训练一个模型又会造成存储和运行开销过大。
- 方法一(FA-LoRA):保持大语言模型主体参数冻结,只训练极小一部分参数(仅占总参数的0.4%),并且把这部分适配放到傅里叶(频率)域中进行,用一个可学习的门控来决定哪些频率成分更重要。
- 方法二(FAR):依次学习多个任务时,模型容易发生对旧知识的'灾难性遗忘',该方法通过跟踪每个训练样本的损失(预测误差)变化,识别出最容易被遗忘的样本,并在后续训练中优先复习这些样本。
- 方法三(APPM):多个按任务顺序训练出的小模块最终需要合并成一个统一模型才能部署,该方法先选出泛化能力最强的模块作为受保护的'锚点',再对其余模块做加权平均,并让各模块的频率门控相互竞争来完成合并。
- 结果:FA-LoRA仅用0.4%的可训练参数就超过了标准LoRA和QLoRA;FAR在连续任务学习中取得平均Micro-F1 0.8022;APPM合并后的模型与逐任务独立训练的性能上限相差仅2.7%(Micro-F1为0.8085),合并耗时156毫秒且不增加运行时内存。


| Split | task_A | task_B | task_C | task_D |
|---|---|---|---|---|
| Train | 5,262 | 5,262 | 5,262 | 5,262 |
| Validation | 542 | 504 | 536 | 651 |
| Test | 530 | 542 | 513 | 648 |
| Total | 6,334 | 6,308 | 6,311 | 6,561 |


| Hyperparameter | Value |
|---|---|
| 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 length | 1,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 |
| Component | Params (M) | Fraction |
|---|---|---|
| Total | 1,241.0 | 100.0% |
| Frozen (LLaMA base) | 1,235.8 | 99.6% |
| Trainable (FA-LoRA) | 5.2 | 0.4% |
| — LoRA (𝑼,𝑽) | 5.0 | 0.40% |
| — Gates (𝒈) | 0.2 | 0.02% |
| Per-task storage | ∼10 MB |
| Method | Quant. | Trainable (M) | Storage (MB) | Micro-F1 | Macro-F1 | Subset Acc. | |||
|---|---|---|---|---|---|---|---|---|---|
| 1B | 3B | 1B | 3B | 1B | 3B | ||||
| WaRA [15] | ✓ | 35.77 | 136.5 | 0.8398 | 0.8515 | 0.6529 | 0.7133 | 0.5544 | 0.5840 |
| QLoRA [9] | ✓ | 1.72 | 6.6 | 0.8185 | 0.8365 | 0.6133 | 0.6407 | 0.5181 | 0.5298 |
| SLoRA [17] | ✓ | 6.85 | 26.2 | 0.8138 | 0.8305 | 0.5945 | 0.6263 | 0.4966 | 0.5262 |
| LoRA [16] | bf16 | 3.42 | 13.0 | 0.8094 | 0.8370 | 0.5613 | 0.6356 | 0.4845 | 0.5428 |
| FourierFT [13] | ✓ | 0.16 | 0.6 | 0.7449 | 0.7888 | 0.4724 | 0.5585 | 0.3471 | 0.4331 |
| FouRA [5] | ✓ | 0.55 | 2.1 | 0.7635 | 0.8020 | 0.4998 | 0.5930 | 0.4004 | 0.4648 |
| FA-LoRA | ✓ | 2.62 | 10.0 | 0.8185 | 0.8424 | 0.5904 | 0.6616 | 0.5074 | 0.5544 |
| Method | Merge (ms) | CPU Δ(MB) | Speedup | ΔInd |
|---|---|---|---|---|
| Simple-Mean | 102 | 0.0 | 70× | +5.5% |
| TIES [40] | 2,123 | 0.0 | 3.4× | +5.5% |
| DARE [44] | 4,204 | 0.0 | 1.7× | +7.9% |
| HAM g=2 | 7,164 | 68.1 | 1.0× | +11.0% |
| SFA a=0.5 | 72 | 0.0 | 100× | +33.0% |
| APPM (ours) | 156 | 0.0 | 46× | +2.7% |
| After training | task_A | task_B | task_C | task_D |
|---|---|---|---|---|
| task_A | 0.7495 | 0.6121 | 0.6331 | 0.6028 |
| task_B | 0.7253 | 0.7503 | 0.7303 | 0.7065 |
| task_C | 0.7162 | 0.7226 | 0.8974 | 0.8864 |
| task_D | 0.7128 | 0.7171 | 0.8935 | 0.8854 |
| Forgetting | −0.0367 | −0.0332 | −0.0039 | — |
为什么重要
对区块链安全团队而言,这意味着可以低成本地把新发现的漏洞类型纳入检测模型,而不必整体重训,也不用同时维护多个模型,最终仍能以单一模型形式部署上线。这为漏洞知识随时间不断更新的真实审计场景提供了一条实用路径。
本文术语
- LoRA(低秩适配) · 不重新训练整个大模型,只训练少量额外参数矩阵来让模型适应新任务的技术
- 灾难性遗忘 · 模型在学习新任务过程中丢失此前学到的知识的现象
- 傅里叶变换 · 将数据分解为不同频率成分的一种数学变换方法
- 适配器(Adapter) · 在主模型保持冻结的情况下,为特定任务额外训练的小模块
- Micro-F1 · 综合精确率和召回率的评价指标,适用于一个样本可能同时属于多个标签(漏洞类型)的情况
论文原文摘要(英文)
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.
在 arXiv 阅读最新论文
- Specification-delta-driven data governance: an empirical study of the {\guillemotleft}spec-delta{\guillemotright} as the unit of change in lakehouse data platforms把数据平台的变更当作可审阅的'规格增量'来管理,而不是靠代码差异——一篇实验设计论文
- Are LLMs becoming similarly creative? Evidence from three years of models三年数据显示,不同AI聊天机器人给出的答案正变得越来越相似
- Auditing Cross-Lingual Fairness in Language Model Watermarking本该识别AI生成文本的水印技术在非英语语言中表现明显更差,而且这种差距按语系而非单个语言呈现
- TESTNAV: Pareto-Guided Search for Compositional Robustness Testing测试AI模型面对多种叠加干扰时不必穷举所有组合,也能找出真正危险的失败案例
- Optimal Skill Selection for LLM Agents with Provable Bicriteria Guarantees让AI编程智能体挑选该装入哪些技能文档,并从数学上保证接近最优的方法
- Reliable Financial Named Entity Recognition under Domain ShiftAI在正式文件里学到的自信,一到推特上就变得不可信
- FlashPrefill V2: Block-Sparse Prefill Attention for Long-Context LLM Serving把稀疏注意力从论文原型变成能真正上线服务的加速方案
- Robust Incomplete Multimodal Sentiment Analysis via Iterative Proxy Correction文本信息缺失或损坏时,这个AI不靠一次性猜测,而是反复修正猜测结果,从而更准确地判断情绪
METAL LAB 最新报道
图片来源: Tenghui Huang et al., arXiv:2608.19680, arxiv-nonexclusive