ContractLens: Latent Security Knowledge for Malicious Smart Contract Detection
Shuyi Miao, Xinyi Huang, Wangjie Qiu, Fei Shen, Jinchun He, Zhiming Zheng, Tat-Seng Chua
Abstract
Detecting malicious smart contracts is essential to safeguarding the Web3.0 ecosystem. However, existing auditing methods based on large language models (LLMs) largely rely on prompt engineering or attack-specific fine-tuning, while the internal representations that support malicious logic detection remain poorly characterized. To address this gap, we propose ContractLens, a framework that localizes and uses latent security knowledge in pretrained LLMs for interpretable malicious smart contract detection. Specifically, we first use layerwise linear probes to identify candidate layers that distinguish malicious from benign contracts, then select critical layers based on their sensitivity to malicious logic removal and stability under behaviour-preserving surface modifications. Next, within these critical layers, we combine activation contrast, malicious-logic specificity, and probe weights into a tri-factor importance score and adaptively select malicious contract-discriminative units (MCDUs) using the knee point of the ranked score curve. Finally, we concatenate the selected units' activations into a compact representation and train a lightweight classifier for detection, keeping the pretrained model frozen throughout. Neuron masking experiments show that masking MCDUs causes larger drops in detection performance than masking randomly selected neurons or neurons matched in activation magnitude. ContractLens achieves higher average detection accuracy than the evaluated methods on all three pretrained models. Further evaluations demonstrate generalization to unseen malicious intents and show that, with the identified MCDUs fixed, a classifier trained on few labelled samples can still achieve strong detection performance.
Create a lesson
Related papers
Verifiable Differential Privacy for Secure Aggregation in Malicious Settings
Shared title terminologycs.CRFuyi Wang, Jiahuai Mao, Wei Song
A Closer Look at the Quality of NPM Dataset for Malicious Code Detection
Shared title terminologycs.CRXuetao Li, Yuxia Zhang, Bohan Wang et al.
Safeguarding LLMs via Model-Agnostic Latent Safety Signals from Dark Knowledge
Shared title terminologycs.CRWonjun Lee, Kyungsik Yang, Gaeun Ji et al.
Deep Defence on Wheels: A Dual Intrusion Detection System Architecture for Comprehensive In-Vehicle Network Security
Shared title terminologycs.CRShashwat Khandelwal, Shanker Shreejith
GCTAuto-encoder: A Cross modal Framework for Security Flaw Detection in IoT Networks
Shared title terminologycs.CRNajmieh Sadat Safarabadi
Adaptive-Shot Hybrid Quantum Anomaly Detection for Tactile Internet Security: Reliability-Aware Measurement Allocation Under Resource Constraints
Shared title terminologycs.CRMubassir Serneabat Sudipto, Shakil Ahmed, Ashfaq Khokhar et al.