KGBERT4Eth: A Feature-Complete Transformer Powered by Knowledge Graph for Multi-Task Ethereum Fraud Detection

Yifan Jia, Ye Tian, Liguo Zhang, Yanbin Wang, Jianguo Sun, Liangliang SongarXiv 2025

TL;DR

KGBERT4Eth is a novel pre-training framework that unifies sequence modeling and graph learning to tackle Ethereum fraud detection. By combining an enhanced Transaction Language Model (TLM) with a Transaction Knowledge Graph (TKG) via a specialized attention synergy mechanism, it achieves state-of-the-art performance in identifying phishing accounts and de-anonymizing blockchain entities.

What Problem Does This Paper Address?

Detecting malicious activity on Ethereum (such as phishing scams and money laundering) is incredibly challenging due to transaction anonymity and the sheer volume of data. Currently, fraud detection approaches are siloed into three distinct paradigms:

  1. Expert-defined features: Manually designed statistical indicators of account behavior.
  2. Graph embeddings: Models that map the topological structure of money flow.
  3. Sequence modeling: Transformer-based architectures that capture the chronological order of transactions.

While these three perspectives form a complete feature space, existing methods fail to integrate them natively. Practitioners are forced to choose one paradigm or rely on simplistic, late-stage feature concatenation. Furthermore, blockchain data is highly homogeneous (repetitive transaction structures) and malicious entities represent a tiny minority, causing standard machine learning and natural language processing (NLP) models to suffer from representation bias and over-smoothing.

Methods

The authors introduce KGBERT4Eth, a "feature-complete" dual-encoder framework that natively fuses semantic, structural, and expert-defined signals during pre-training.

Model Architecture Overview

The architecture consists of three core innovations:

  • Transaction Semantic Extractor (TLM) with Biased Masking: Instead of treating transactions as raw numbers, the framework textualizes transaction logs into sentences. To combat the issue of highly repetitive text, the authors discard standard random masking. Instead, they use a Biased Mask Strategy powered by BM25 scores to prioritize masking rare, highly informative tokens (statistical outliers), forcing the model to learn anomalous behavior.
  • Transaction Knowledge Graph (TKG): The authors construct a multi-relational graph where nodes represent Ethereum addresses (EOAs and Contract Accounts) and edges represent transaction types. Nodes are initialized with 31 expert-engineered features spanning financial statistics, temporal activity patterns, and network centrality metrics.
  • Mask-Invariant Attention Synergy (MiAS): Fusing graph data with text sequences too early can corrupt the language model's training objective. MiAS uses a cross-attention mechanism with a specialized visibility matrix that restricts information exchange exclusively through the [CLS] token. This ensures that structural graph knowledge enriches the overall account representation without altering original sentence semantics or disrupting masked token predictions.

The entire framework is jointly optimized using two self-supervised tasks: Biased Mask Prediction (BMP) for the language model and Transaction Link Prediction (TLP) for the graph encoder.

Datasets

The model was pre-trained on a massive dataset extracted from Etherscan, Kaggle, and Xblock, comprising 3,251,082 transaction records across 496,740 accounts, forming a graph with roughly 500k entities and 1M edges.

For downstream evaluation, the authors tested the model on two primary tasks across multiple benchmarks:

  • Phishing Account Detection: Evaluated on three public datasets: MultiGraph, B4E, and SPN.
  • Account De-anonymization: Evaluated using real-world labels from GitHub across four distinct entity types: Airdrop Hunters (972), ICO Wallets (178), Mev Bots (331), and Synthetix accounts (524).

Key Insights and Ideas

  • Random Masking Fails on Structured Logs: In standard NLP, random masking works because language is diverse. Transaction logs, however, are highly repetitive. Randomly masking common fields just teaches the model to guess predictable syntax. Biased masking based on BM25 forces the model to focus on the "weird" parts of a transaction—which is exactly where fraud hides.
  • Isolation Preserves Learning Integrity: Cross-modal models often suffer from representation conflicts. By forcing the graph and sequence encoders to talk only through the [CLS] token, the model successfully aligns structural and semantic spaces without causing the encoders to interfere with each other's primary tasks.
  • The Power-Law of Fraud: Quantitative analysis of phishing accounts reveals a heavy-tailed distribution: most malicious accounts are short-lived and execute very few transactions, while a tiny fraction are hyper-aggressive.
Empirical distribution of phishing accounts

Incorporating temporal indicators (like account lifespan and active days) into the graph nodes is vital for capturing these atypical behaviors.

Key Results

KGBERT4Eth was evaluated against 15 strong baselines (including random walk methods, advanced GNNs like GrabPhisher, and sequential transformers like BERT4ETH and ZipZap) and consistently outperformed them all.

  • Phishing Detection: Achieved absolute F1-score improvements of 8–16% across the three benchmarks. On the MultiGraph dataset, it achieved an F1-score of 87.60%, outperforming the best GNN baseline by 8.71%.
  • De-anonymization: Achieved absolute F1-score improvements of 6–26% overall. Notably, in the highly sparse ICO Wallets category, KGBERT4Eth achieved an F1-score of 65.66%, vastly superior to baseline methods that struggled with data scarcity.
  • Ablation Success: Removing the TKG dropped the F1 score by up to 1.6%, while removing the MiAS module or the Biased Masking strategy caused even sharper performance declines, proving that tight cross-paradigm fusion is key.

Limitations and Future Work

The primary limitation of KGBERT4Eth stems from the architectural constraints of the underlying BERT model, which restricts the maximum input sequence length ($L_{max}$) to 512 tokens. Because of this, the model can only process around 15 transaction records per account during training, potentially missing long-term behavioral patterns for highly active accounts.

To address this, the authors plan to explore long-context language models in future iterations, alongside model compression techniques to allow for lightweight deployment in resource-constrained environments.

Summary updated

BibTeX
@misc{jia2025kgbert,
  author = {Yifan Jia and Ye Tian and Liguo Zhang and Yanbin Wang and Jianguo Sun and Liangliang Song},
  title = {{KGBERT4Eth: A Feature-Complete Transformer Powered by Knowledge Graph for Multi-Task Ethereum Fraud Detection}},
  year = {2025},
  eprint = {2509.03860},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2509.03860},
}
Figure