# Temporal Motif-aware Graph Test-time Adaptation for OOD Blockchain Anomaly Detection

Crypto.world

> Anomaly detection on cryptocurrency blockchains is hard because malicious behaviour keeps changing: models trained on historical transactions degrade when deployed against new fraud strategies and…

**arXiv**: 2605.29526

**Published**: 2026-05-28

**Authors**: Runang He, Tongya Zheng, Huiling Peng, Yuanyu Wan, Bingde Hu, Jiawei Chen, Canghong Jin, Mingli Song, Can Wang

## AI summary

## Overview

**Research area:** Blockchain security and graph machine learning — specifically graph anomaly detection (GAD) on cryptocurrency transaction networks, combined with test-time adaptation (TTA) for out-of-distribution (OOD) settings.

**Technical level:** Advanced. The paper assumes familiarity with graph neural networks, message passing, contrastive learning (InfoNCE), teacher-student self-training, and motif-based graph representations.

**Scope:** The paper proposes TEMG-TTA, a framework that represents each blockchain address by its 3-node temporal motif distribution and adapts a pre-trained graph detector at inference time to shifting transaction patterns, evaluated on five real-world Ethereum datasets.

## What This Paper Is About

Anomaly detection on cryptocurrency blockchains is hard because malicious behaviour keeps changing: models trained on historical transactions degrade when deployed against new fraud strategies and new transaction semantics, an out-of-distribution (OOD) problem. The authors argue that two things are missing from existing graph anomaly detection methods — explicit modelling of fine-grained temporal motifs (small recurring subgraph patterns), and a way to adapt a trained model to an unlabeled, shifted test graph without labels.

Their goal is a detector that both captures higher-order temporal transaction structure and adapts itself at test time, so that it stays accurate when the test distribution drifts away from training.

## Key Contributions

1. **A temporal motif-aware graph representation for blockchain addresses.** Each active address is described by its distribution over 36 types of 3-node temporal motifs, computed by an efficient matching algorithm that reduces complexity from O(M³) to O(M·k²), where M is the number of transactions and k is the maximum number of edges in a constrained time window. Motif-role counts are stored in a matrix C ∈ ℝ^(N×(3×36)).
2. **A motif embedding scheme with shared prototypes, roles, and positional encodings.** A shared motif prototype matrix M = [m₁, …, m₃₆] is combined with a learnable role embedding and a positional encoding that captures temporal order (a sine function of timestamp) and source/destination role, producing motif-role embeddings that are aggregated into node-level motif features and fused with original node features.
3. **A label-free graph test-time adaptation strategy for blockchains.** A student GNN is adapted on the unlabeled test graph while a teacher GNN (updated by exponential moving average, α ∈ [0.9, 0.999]) provides stable supervision. Supervision is restricted to a "trustable node" confidence band (τ_low < p_i ≤ τ_high), and the student is regularized by an embedding-similarity loss plus an InfoNCE contrastive loss where positives are nodes with similar motif features.
4. **A real-world deployment collaboration and extensive benchmarking.** The work is done with the Zhejiang Provincial Public Security Department, which supplied reliable on-chain anomaly labels and cases, including a private Trace dataset (money laundering). Experiments span four public datasets and one private dataset, and the method is tested with four GNN backbones (GCN, GraphSAGE, SpaceGNN, DGAGNN).

## Main Findings

- **Headline improvement:** Across five real-world datasets, TEMG-TTA outperforms state-of-the-art GAD approaches by an average of **54.88%**.
- **Large gains where distribution shift is severe:** When the source model transfers poorly — for example from CryptopiaHacker to PlusTokenPonzi — the authors report that TEMG-TTA consistently and substantially improves results, with many improvements significant at p < 0.001 in a paired t-test.
- **No damage when the source model is already strong:** In transfers such as AlphaHomora to CryptopiaHacker, where the original model already performs well, TEMG-TTA maintains or further improves performance, indicating the adaptation does not destroy source-domain knowledge.
- **Motifs help, and help weaker backbones most:** In the ablation on four public datasets, adding motif representation consistently improved detection. On AlphaHomora, GCN improved from 0.6034 to 0.7173 AUC-PRC without and with motifs respectively, and on UpbitHack SpaceGNN improved from 0.7177 to 0.7329. GCN showed the largest benefit, suggesting motif features compensate for limited structural expressiveness. The gain on PlusTokenPonzi was minor, attributed to its high anomaly ratio (80.34%) and near-saturated performance.
- **Motif structure is interpretable and fraud-relevant:** A case study on the private dataset found two recurring patterns confirmed with the partner: a "distribution" pattern where assets flow from one node to a frequently used private exchange service and a suspicious address (a strong fraud signal within a short time window, since malicious actors avoid reusing accounts), and an "aggregation" pattern where assets are collected into one account before payment, corresponding to a cash-out behaviour.
- **Parameter sensitivity:** A larger teacher momentum α usually weakens TTA performance (for example, in the AlphaHomora to PlusTokenPonzi transfer) because it slows knowledge transfer from the student. Appropriate edge limits k and time aggregation ranges Δt generally improve results; default settings are k = 100 and Δt = 3600.
- **Efficiency:** Edge limiting and time aggregation cut motif-matching runtime considerably. On AlphaHomora, matching took 1,307.01 s with k alone but 176.04 s with both k and Δt; on Trace it took 3,005.07 s with Δt alone but 349.05 s with both. In deployment the method runs on localized k-hop subgraphs around seed accounts, with motif matching costing about **0.12 ms per edge** and forward/backward passes of **40.25/169.69 ms**, giving second-level latency at Ethereum-scale throughput.
- **Scalability limits:** Out-of-memory errors occurred mainly when combining the large Trace dataset with SpaceGNN, because TTA must hold both a teacher and a student model.
- **Some baselines were infeasible:** Temporal GNN baselines DyGFormer and SALoM were attempted, but training cost was prohibitive — several runs exceeded 24 hours on public datasets and were harder on Trace — so the main comparison uses representative GNN-based anomaly detection backbones.

## Methodology in Plain English

The authors treat a blockchain as a directed temporal multi-graph: each transaction is a tuple of sender, receiver, timestamp, and amount, and each address is a node to be classified as benign or anomalous.

**Step 1 — Describe each address by its small transaction shapes.** Rather than only looking at who sends money to whom, they look at recurring three-account patterns: three transactions among three addresses occurring in a short time window. There are 36 possible directed shapes of this kind. To make counting affordable on graphs with millions of edges, they sort transactions by time, sample at most k recent transactions per transaction within a window t_w, optionally merge duplicate same-direction transactions within Δt, and only test pairs of recent transactions against the current one. This is what turns an infeasible cube-of-transactions search into something linear in transactions times k².

**Step 2 — Turn counts into learnable features.** Each motif type gets a learned prototype vector; each of the three positions in a motif gets a learned role vector; and each position also gets a positional encoding that mixes a sinusoidal function of the event timestamp with a small network that says whether the node was sender or receiver on that edge. Adding these three pieces gives a motif-role embedding. Multiplying the per-node motif count matrix by the stacked embeddings gives node-level motif features, which are fused with the original node features through a small network.

**Step 3 — Pre-train normally.** The fused features go into any standard GNN backbone (GCN, GraphSAGE, SpaceGNN, or DGAGNN), trained with binary cross-entropy and early stopping on validation AUC-PRC. Splits are chronological, 6:2:2, based on each anomalous node's activation time, to avoid data leakage.

**Step 4 — Adapt at test time without labels.** Two copies of the trained model are made: a student that learns on the new graph, and a teacher that follows the student slowly. Only nodes whose teacher confidence falls inside a middle band are used — neither too uncertain nor too over-confident — to avoid reinforcing the model's own mistakes. The student sees a lightly perturbed version of the test graph (random edge dropping). It is trained to keep its embeddings close to the teacher's for the selected nodes, and additionally to pull embeddings of nodes with similar motif profiles together and push dissimilar ones apart. The teacher is then updated as a moving average of the student.

**Step 5 — Evaluate under imbalance.** Because anomalies are rare, the authors report AUC-PRC, Recall@k (with k set to the number of anomalous test nodes), and F1, and compare against the anomaly ratio of each test set as a random baseline.

## Why This Matters

**Impact on research.** The work connects two literatures that are usually separate — motif-based higher-order graph representation and graph test-time adaptation — and argues that fine-grained temporal structure, not just global distribution alignment, is what makes adaptation work on financial transaction graphs. It also provides a rare labelled private dataset and a real operational collaboration, which is uncommon in blockchain anomaly detection papers. The complexity reduction from O(M³) to O(M·k²) makes motif analysis practical on graphs of the scale reported here (Trace has 1,698,331 nodes and 2,969,691 edges).

**Real-world applications:**

- Real-time flagging of suspicious Ethereum addresses such as anomalous exchangers, as described in the paper's collaboration with a provincial public security department.
- Money-laundering detection, the focus of the private Trace dataset (0.16% anomaly ratio).
- Detection of Ponzi schemes (PlusTokenPonzi) and hacker attack proceeds (CryptopiaHacker, UpbitHack).
- Cash-out and layering analysis, where the case study shows aggregation motifs corresponding to fund collection before payout.

**Industry relevance.** The reported latency figures — roughly 0.12 ms per edge for motif matching and second-level end-to-end latency under Ethereum-scale throughput when running on localized k-hop subgraphs around seed accounts — suggest the approach is meant for production monitoring rather than offline forensics. Exchanges, analytics vendors, and compliance teams all face the same problem the paper names: labels from historical fraud do not stay valid as attack strategies change.

## Future Directions

- **Extending beyond 3-node, 3-edge motifs.** The authors deliberately stop at 3-node motifs for tractability, noting that 4-node motifs are far more expensive and harder to represent compactly. Whether richer structures pay off, and how to compute them cheaply, is open.
- **Relaxing the memory bottleneck.** SpaceGNN ran out of memory on Trace because TTA keeps both teacher and student models. Reducing the memory footprint of adaptation would broaden which backbones are usable on million-node graphs.
- **Making adaptation to the hardest shifts reliable.** On Trace, several backbones show very low absolute scores even after adaptation, and some Recall@k values remain at or near zero. The paper does not report a mechanism that guarantees improvement on extremely sparse anomaly regimes (Trace is 0.16% anomalous), which remains an open gap.
- **Choosing adaptation hyperparameters without labels.** The sensitivity analysis shows that α, τ_low, and τ_high all shift results, and the paper fixes α during training. Selecting these without any target labels, or adapting them online, is a natural next question.

## Target Audience

Researchers and practitioners in graph machine learning and blockchain security who already understand GNNs and self-training: PhD students working on graph anomaly detection or test-time adaptation, security engineers at exchanges and analytics firms building on-chain fraud detection, and applied scientists who need a concrete, scalable recipe for temporal motif extraction on large directed temporal graphs. Readers new to graph neural networks will find the method sections dense, though the motivation and case study are accessible.

## Authors’ abstract

Ever-evolving transaction patterns have significantly hindered anomaly detection on emerging cryptocurrency blockchains due to the vast number of addresses and diverse anomalous behaviors. Recently, advanced Graph Anomaly Detection (GAD) approaches applied to blockchains have faced two critical challenges: \textit{adversarial pattern evolution by malicious actors} and \textit{the out-of-distribution (OOD) problem caused by varied transaction semantics on blockchains}. To…

[The full abstract on arXiv](https://arxiv.org/abs/2605.29526)

[Read the original paper](https://arxiv.org/abs/2605.29526)

---

Canonical: https://crypto.world/paper/temporal-motif-aware-graph-test-time-adaptation-for-ood-blockchain-2605.29526
