Skip to content
Crypto.world

Research

Vision-Based Learning for Cyberattack Detection in Blockchain Smart Contracts and Transactions

Blockchain platforms, particularly Ethereum, are repeatedly exploited through vulnerable smart contracts and malicious transactions — the paper cites DeFiHacksLabs data reporting over 150 smart…

Vision-Based Learning for Cyberattack Detection in Blockchain Smart Contracts and Transactions
arXiv
2512.11272
Published
2025-12-12
Authors
Do Hai Son, Le Vu Hieu, Tran Viet Khoa, Yibeltal F. Alem, Hoang Trong Minh, Tran Thi Thuy Quynh, Nguyen Viet Ha, Nguyen Linh Trung

AI summary

Overview

Research area: Blockchain security / cyberattack detection — applying computer-vision deep learning (Vision Transformers) to Ethereum smart contract and transaction data.

Technical level: Intermediate. The conceptual pipeline is easy to follow, but the paper includes formal notation for TF-IDF vectorization, bilinear interpolation, and multi-head self-attention that assumes some familiarity with machine learning and deep learning.

Scope (1 sentence): The paper proposes a pipeline that converts Ethereum transaction bytecode and numeric fields into grayscale images using NLP techniques, then classifies them with a compact Vision Transformer to detect six types of smart contract and transaction attacks.

What This Paper Is About

Blockchain platforms, particularly Ethereum, are repeatedly exploited through vulnerable smart contracts and malicious transactions — the paper cites DeFiHacksLabs data reporting over 150 smart contract attack incidents in 2024 with losses exceeding $328 million. A core practical obstacle is that only about 1% of smart contracts have publicly available source code, so detectors must work directly on deployed bytecode, which is a raw sequence of hexadecimal values that is hard to analyze reliably in real time. The goal is a detection framework that turns this awkward bytecode-plus-transaction data into something a powerful vision model can read, and that does so more accurately than prior machine learning and deep learning baselines.

Key Contributions

  1. An NLP-based preprocessing technique that disassembles transaction bytecode into an opcode sequence, treats it as a text document, and vectorizes it with TF-IDF over a vocabulary built from the training opcode corpus. This opcode vector is concatenated with standard-scaler-normalized gas and input length, plus a log-normalized transaction value appended as an extra image row, producing a unified grayscale image for both smart contracts and transactions.

  2. A Vision Transformer architecture with convolutional patch embedding, in which three sequential convolutional layers downsample the input image and expand channels to the Transformer embedding dimension before patching, combined with a class token, positional embeddings, and pre-normalized Transformer encoder blocks.

  3. An empirical demonstration that preprocessing matters as much as the model: the same ViT architecture jumps from 95.1665% to 99.5200% test accuracy when the proposed preprocessing replaces the baseline image-transformation technique, and the same swap lifts a CNN baseline from 93.8490% to 98.8582%.

  4. A parameter-efficiency analysis showing the proposed model uses 899,559 trainable parameters — only 8% of ResNet's 11,173,831 and 40% of MobileNetv2's 2,233,543 — while outperforming every compared model on accuracy, precision, and recall.

Main Findings

  • Best overall accuracy: On the BTAT test set, the proposed ViT-based model reaches 99.5200% accuracy, 99.4393% precision, and 99.6050% recall, ahead of MobileNetv2 (99.0080% / 98.8280% / 99.2818%), CNN (98.8582% / 98.5740% / 99.2734%), SVM (96.0198% / 95.7315% / 97.6686%), KNN (95.5299% / 94.2707% / 94.7914%), and LR (94.8836% / 94.6416% / 96.3814%).

  • Preprocessing drives large per-attack gains: With the same ViT architecture, the proposed preprocessing improves detection of Function Default Visibility by approximately 30%, Delegatecall by 11%, and Re-entrancy by 14% compared to the baseline image transformation.

  • ResNet overfits badly: ResNet achieves near-perfect training accuracy but collapses to 89.5446% test accuracy with 87.9960% precision and 93.3549% recall — the lowest accuracy of any model tested — which the authors attribute to overfitting given its large parameter count relative to the simplicity of the task.

  • Convergence speed: ResNet, MobileNetv2, and the proposed ViT-based model need fewer than 20 epochs to reach near-perfect training accuracy (up to 100%), whereas the CNN model on BTAT requires more than 150 epochs to stabilize at approximately 98.5%.

  • Consistency across attack classes: The ViT-based model achieves over 99.4% accuracy in six out of the seven classification categories (one normal class plus six attack types).

  • Lightweight footprint: At 899,559 parameters the proposed model is almost the same size as the baseline CNN (806,727) despite its Transformer design, making it a candidate for resource-constrained deployment.

  • Not reported: The paper does not state the train/test split ratio, the specific values of image height and width, the number of Transformer layers or attention heads, or per-class precision/recall tables beyond the visual confusion-matrix figures.

Methodology in Plain English

The starting point is a transaction record. From it, the authors pull out four things: the raw input field (which is the contract bytecode for deployments and calls), the length of that input, the gas used, and the amount of ETH transferred.

The bytecode is the hard part, so they translate it. A disassembler turns the hexadecimal bytecode into a sequence of opcodes — the contract's actual instructions, things like arithmetic or storage operations — and this sequence is then treated exactly as if it were a sentence in a document. Using TF-IDF, which scores how common a word is in one document versus how rare it is across the whole corpus, each transaction becomes a fixed-length vector of opcode importance scores. Rare-but-distinctive opcodes get high weight; ubiquitous ones get low weight.

The small numeric fields are handled separately — gas and input length get standardized so they sit on a comparable scale, and the transferred value gets squeezed through a log formula scaled to the 0–255 pixel range, then placed along the bottom edge of the image as a distinctive "stripe." Everything is concatenated into one long vector, stretched with bilinear interpolation into a rectangular grid, and read as a grayscale image.

That image goes into a Vision Transformer, but not the standard one. Rather than chopping the image into fixed patches with a single linear projection, three stacked convolutional layers first downsample the image and build up feature channels. The resulting feature map is flattened into a token sequence, given a learnable class token and positional embeddings, and passed through Transformer encoder blocks that use layer normalization before each sub-layer. The class token's final state is fed to a classification head that outputs normal versus one of six attack types.

All detection is framed as happening at a detector placed on top of each Ethereum node, so pending transactions and contract deployments can be inspected before or as they are processed. Evaluation uses accuracy, precision, and recall, with precision and recall computed using macro averaging to keep the imbalanced classes from being dominated by the largest one.

Why This Matters

Impact on research: The paper's most transferable insight is that representing bytecode as a language-like object and then reusing vision architectures is a viable route around both the source-code availability problem and the fragility of hand-crafted attack-vector matching. The ablation showing that preprocessing swaps move accuracy by several points — while the ResNet result shows a bigger model performing worse — is a useful corrective to the tendency to treat model architecture as the sole lever in this literature.

Real-world applications:

  • Node-level transaction screening by Ethereum node operators, who could flag pending malicious transactions before execution.
  • Wallet and decentralized application providers, who could warn users before they sign a transaction interacting with a vulnerable contract.
  • Blockchain analytics and forensics firms, who could triage deployed contracts without needing verified source code.
  • Critical-infrastructure blockchain deployments in healthcare, energy, and IoT, where the paper notes future attacks could have direct consequences for human well-being.

Industry relevance: The 899,559-parameter model size (8% of ResNet, 40% of MobileNetv2) is the commercially interesting number. Security screening that runs on every node must not itself become a bottleneck, and the paper explicitly positions this footprint as suitable for edge devices. The only-1%-of-source-code-available statistic is also a strong argument for bytecode-only detection in production settings.

Future Directions

  • Adversarial robustness: The authors state they plan to evaluate the framework under adversarial scenarios — a natural next step, since attackers who know a detector exists have an incentive to craft bytecode that evades it.
  • Cross-chain transaction analysis: Also named by the authors as future work; the current framework is explicitly scoped to Ethereum, and generalizing beyond it raises questions about opcode vocabularies and feature sets that differ per chain.
  • Evolving and unseen attack types: The approach is trained on six known attack categories from a laboratory private network. How it behaves on novel attack patterns, or on mainnet distributions that differ from the synthetic BTAT data, is an open question the paper does not evaluate.
  • Deployment cost under real-time load: The paper reports offline accuracy and parameter counts but not inference latency, throughput, or how the per-node detector handles pending-transaction volume in practice.

Target Audience

Researchers and graduate students working on blockchain security, smart contract vulnerability detection, or the crossover between NLP/computer-vision techniques and non-image data. It is also useful for security engineers at exchanges, wallet providers, or node operators who need a concrete, lightweight bytecode-analysis pipeline, and for applied ML practitioners interested in how far a well-designed preprocessing step can carry an otherwise standard Vision Transformer.

Authors’ abstract

Blockchain technology has experienced rapid growth and has been widely adopted across various sectors, including healthcare, finance, and energy. However, blockchain platforms remain vulnerable to a broad range of cyberattacks, particularly those aimed at exploiting transactions and smart contracts (SCs) to steal digital assets or compromise system integrity. To address this issue, we propose a novel and effective framework for detecting cyberattacks within blockchain…

The full abstract on arXiv
Read the original paper