# ContractLens: Latent Security Knowledge for Malicious Smart Contract Detection

DevFeed: [ContractLens: Latent Security Knowledge for Malicious Smart Contract Detection](<https://devfeed.tech/articles/contractlens-latent-security-knowledge-for-malicious-smart-contract-detection-119895.md>)

Original publisher: [Read original article](<https://arxiv.org/abs/2610.04992>)

Author: Shuyi Miao, Xinyi Huang, Wangjie Qiu, Fei Shen, Jinchun He, Zhiming Zheng, Tat-Seng Chua

Published: 2026-11-06T05:00:00Z

Content type: article

Language: en

Sources: [arXiv: Cryptography and Security](<https://devfeed.tech/sources/arxiv-cryptography-and-security.md>)

Topics: [smart contract](<https://devfeed.tech/topics/smart-contract.md>), [threat detection](<https://devfeed.tech/topics/threat-detection.md>), [Representation learning](<https://devfeed.tech/topics/representation-learning.md>), [ai security](<https://devfeed.tech/topics/ai-security.md>)

Tags: [activation](<https://devfeed.tech/tags/activation.md>), [auditing](<https://devfeed.tech/tags/auditing.md>), [contracts](<https://devfeed.tech/tags/contracts.md>), [critical](<https://devfeed.tech/tags/critical.md>), [cs-cr](<https://devfeed.tech/tags/cs-cr.md>), [detection](<https://devfeed.tech/tags/detection.md>), [ecosystem](<https://devfeed.tech/tags/ecosystem.md>), [evaluations](<https://devfeed.tech/tags/evaluations.md>), [fine-tuning](<https://devfeed.tech/tags/fine-tuning.md>), [knowledge](<https://devfeed.tech/tags/knowledge.md>), [large-language-models-llms](<https://devfeed.tech/tags/large-language-models-llms.md>), [linear](<https://devfeed.tech/tags/linear.md>), [llms](<https://devfeed.tech/tags/llms.md>), [logic](<https://devfeed.tech/tags/logic.md>), [malicious](<https://devfeed.tech/tags/malicious.md>), [masking](<https://devfeed.tech/tags/masking.md>), [model](<https://devfeed.tech/tags/model.md>), [models](<https://devfeed.tech/tags/models.md>), [neuron](<https://devfeed.tech/tags/neuron.md>), [security](<https://devfeed.tech/tags/security.md>), [smart-contract](<https://devfeed.tech/tags/smart-contract.md>)

## AI overview

ContractLens detects malicious smart contracts by identifying security-relevant units inside pretrained language models, then using their activations with a lightweight classifier while keeping the models frozen. It selects candidate layers with linear probes, filters for sensitivity to removing malicious logic and stability under behavior-preserving surface changes, and ranks units using activation contrast, malicious-logic specificity, and probe weights. Masking these selected units harms detection more than masking random or activation-matched neurons, supporting their relevance to the task. The abstract reports higher average detection accuracy than evaluated methods across all three tested pretrained models, generalization to unseen malicious intents, and strong results from classifiers trained on few labeled samples when the selected units are fixed. It provides no numerical results or details of the evaluated baselines.

## Source excerpt

arXiv:2610.04992v2 Announce Type: replace 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.