Training custom ML models for Web3 threat detection

By Jeremy Ryan, Founder & CEO · September 2026

Machine learning system analyzing suspicious wallet, smart contract, and bridge transaction connections across Web3 networks.

Training custom ML models to identify malicious transaction patterns in Web3 ecosystems requires more than feeding historical blockchain data into a classifier. The hard part is defining malicious behavior precisely, assembling labels that survive scrutiny, and deploying scores that security teams can act on before losses spread. I recommend treating the model as one component of an incident response system, not as an automated oracle.

Key Takeaways

Build Around A Specific Security Decision

A useful model answers a narrow operational question: should a transaction be blocked, delayed, reviewed, monitored, or allowed? “Fraud detection” is too broad for a production system. A wallet provider may need to identify suspicious approvals before a wallet drain. A bridge operator may need to score rapid cross chain transfers after an exploit. A marketplace may care more about wash trading than contract exploits.

I recommend maintaining separate transaction risk, wallet risk, contract risk, and campaign risk scores. A single transaction may look ordinary while the wallet’s recent behavior, its funding source, and its relationship to a newly deployed contract tell a very different story.

Treat Labels As Evidence, Not Permanent Truth

Confirmed exploit addresses, incident postmortems, sanctions or blocklists where applicable, and internal investigation outcomes can create high confidence labels. They do not create a complete picture of malicious activity. Many attacks are identified days or weeks after the first suspicious transaction, and some activity remains ambiguous.

Use confidence tiers instead of forcing every record into a clean malicious or benign class:

• Confirmed malicious: Publicly attributed exploit flows, verified scam infrastructure, or addresses validated through investigation.

• Strongly suspicious: Transactions that match a documented attack sequence but lack final attribution.

• Benign reference: Routine activity from known protocol operations, established users, and normal contract interactions.

• Unknown: Activity that should remain out of supervised training until additional evidence arrives.

Optimize For Queue Quality, Not Accuracy

Accuracy can look excellent when nearly all transactions are benign. It is often the wrong headline metric. A model that catches 90% of attacks but floods analysts with ten thousand low quality alerts can be operationally worse than a model that catches fewer events with actionable evidence.

The real output is not “malicious” or “safe.” It is a prioritized decision with reasons, confidence, and a clear next action.

Define The Threat Before Training

Create A Web3 Specific Label Taxonomy

The training set should represent the behaviors the organization can actually observe and respond to. I would not combine every malicious pattern into one generic fraud label at the beginning. That approach hides critical differences between an approval phishing sequence and bridge laundering.

A practical taxonomy can include the following categories:

Threat Pattern Observable Transaction Sequence Primary Response
Approval to drain Token approval followed by rapid transfer or transferFrom activity Warn user, delay execution, raise transaction score
Exploit cash out Abnormal contract interaction followed by swaps, bridges, or dispersal Freeze protocol controls where possible, investigate flows
Bridge abuse Large bridge transfer followed by rapid destination chain swaps or peel chains Escalate cross chain monitoring and liquidity controls
Wash trading Repeated circular trades among connected wallets at abnormal timing or prices Flag market integrity risk and review accounts
Phishing linked flow Funding from known risky infrastructure followed by approvals or transfers Increase wallet and transaction scrutiny
Mixer adjacent laundering Value fragmentation, intermediary hops, and reaggregation near obfuscation services Prioritize provenance analysis and compliance review

This taxonomy should map directly to labels, features, thresholds, and playbooks. For example, a smart contract exploit detector may weigh calldata patterns and liquidity movements heavily. A wash trading model needs graph relationships, trade timing, price behavior, and ownership signals where they are legally and operationally available.

Build A Dataset That Respects Time

Blockchain histories create a subtle training trap: future information can leak backward. Suppose a wallet is publicly identified as malicious on June 20. If that reputation label appears in features for transactions from June 1, the model learns from evidence that was unavailable at prediction time. Offline performance rises, but production performance collapses.

Use an event time design:

  1. Record the block time, ingestion time, and label confirmation time separately.
  2. Generate features only from data that existed before the transaction being scored.
  3. Split training, validation, and test data chronologically rather than randomly.
  4. Keep related transactions from a single incident or campaign in the same evaluation period where possible.
  5. Reconstruct historical address reputation as it existed at the time of each event.

This approach is slower than a random split, but it measures whether the system can detect emerging behavior rather than recognize a well documented incident after the fact.

The broader pipeline should include collection, preprocessing, class imbalance treatment, training, evaluation, and interpretability. That sequence is explicitly reflected in Wiley’s blockchain anomaly detection pipeline research. The operational implication is straightforward: interpretability should not be bolted on after deployment. It belongs in the design phase because analysts must understand why an alert reached their queue.

Combine On Chain And Contextual Signals Carefully

On chain data offers transaction values, gas behavior, logs, contract calls, token movements, traces, and wallet relationships. These should be the core of the system. Off chain inputs can improve context, but they create privacy, licensing, availability, and data freshness risks.

Useful contextual signals may include incident reports, verified address intelligence, contract audit status, phishing domain reports, or internal case outcomes. Keep a data provenance record for every source. If an external reputation feed goes stale or changes its methodology, the model needs a visible fallback behavior rather than silently trusting outdated context.

For organizations designing blockchain applications for transaction volume, this also means preserving event order, trace availability, and data retention early. A detection model cannot recover signals that the platform never collected.

Build Features That Describe Attacker Behavior

Use Sequences Instead Of Isolated Transaction Fields

A transaction amount, gas price, or token transfer alone rarely captures malicious intent. Attackers often reveal themselves through order and timing: a newly funded wallet grants an unlimited approval, interacts with an unfamiliar contract, transfers assets, then bridges value within minutes.

Useful temporal features include:

• Time since wallet creation or first funding.

• Number and value of transfers in rolling windows.

• Time between approval, swap, bridge, and withdrawal events.

• Burst intensity relative to the wallet’s own history.

• Contract call novelty and sudden changes in token counterparties.

A GRU can model ordered activity where sequence timing matters. A recent Springer study describes a GRU based detector that uses normalization and temporal encoding to score transaction streams before blockchain recording; see the GRU transaction stream scoring approach. In practice, a sequence model is most justified when the organization sees repeated behavioral chains, not merely independent single transactions.

Model The Transaction Graph

Web3 activity is naturally relational. Wallets fund wallets, contracts create contracts, tokens move through pools, and bridges connect chain specific representations of value. Graph features can reveal that an otherwise ordinary wallet is one hop from a suspicious deployer or part of a rapidly expanding cluster.

Start with features that are explainable to investigators:

• Inbound and outbound degree over several time windows.

• Proximity to confirmed malicious or high risk nodes.

• Shared funder, deployer, beneficiary, or contract creator relationships.

• Repeated circular transfer paths and unusually dense local clusters.

• Bridge entry and exit relationships across represented assets.

Graph neural networks are valuable when relationships carry more signal than individual transaction values. They require caution, however. A graph model can spread reputation too aggressively through legitimate shared infrastructure, such as exchanges, aggregators, or popular liquidity pools. Exclude or carefully represent high degree service nodes to avoid treating ordinary users as guilty by proximity.

Choose Models By Failure Mode

There is no universal best model. Use the simplest model that meets the response objective, then add complexity only when it corrects a demonstrated weakness.

Model Family Choose It When Avoid Or Limit It When
XGBoost or Random Forest You have structured features and confirmed labels Relationships and sequence order dominate the signal
Autoencoder Labels are scarce and normal behavior is reasonably stable “Normal” traffic is extremely diverse or already contaminated
Graph Neural Network Wallet and contract relationships are central Graph quality is poor or explanations are not operationally usable
GRU or Transformer Timing and transaction order define attacks Events are sparse and independent
Hybrid graph plus sequence model Cross wallet movement and temporal attack chains both matter The team cannot support higher data and monitoring complexity

Autoencoders can be a useful preprocessing layer because they compress raw transaction behavior into representations of an address or contract. Forta’s explanation of autoencoder based feature extraction specifically describes converting raw transaction data into address or contract features for malicious smart contract detection.

Unsupervised methods also have a place. ACM research on K means clustering shows that clustering can surface unusual blockchain patterns, including high volume and rapid wallet transfers. I would use that output as an investigation lead or candidate label source, not as proof that an event is malicious.

Diagram showing a suspicious Web3 transaction sequence from wallet funding through approval, asset transfer, bridge hop, and fragmented transfers.

Score Cross Chain Behavior As A Connected Event

Bridge abuse and cross chain laundering deserve their own treatment. A per chain model can miss the larger story: assets leave one chain after a suspicious event, appear on a destination chain, move through a swap, split into smaller values, and reach multiple wallets.

Link events using bridge message identifiers where available, asset mappings, temporal windows, transaction hashes, and destination recipient relationships. Be explicit about uncertainty. Wrapped assets, delayed finality, route aggregation, and centralized exchange deposits can break clean attribution. In those cases, score the chain of evidence rather than declaring a deterministic link.

Governance also matters because risk policies determine who can pause, review, or override a score. Clear blockchain governance frameworks help ensure that detection outputs lead to accountable decisions rather than inconsistent emergency actions.

Evaluate Models For Real Operational Decisions

Measure Performance At The Alert Threshold

Evaluate precision and recall at the actual alert volumes your team can process. If analysts can investigate 50 alerts per day, calculate precision among the top 50 ranked alerts, not only across a theoretical classification threshold.

A practical triage design uses bands:

Risk Band Operational Meaning Typical Action
Critical Strong multi signal evidence of imminent or active harm Block, pause, or escalate immediately where authority exists
High Material evidence requiring rapid human review Open priority case and monitor linked entities
Medium Suspicious behavior with incomplete context Queue for review or request additional signals
Low Weak or isolated anomaly Log for trend analysis without interrupting users

Thresholds should vary by asset, protocol action, and user impact. A low confidence alert for a small transfer may be tolerable. The same confidence level for a governance execution, unlimited approval, or major bridge withdrawal may justify friction.

Balance False Positives And False Negatives

False positives damage user trust, overload analysts, and can block legitimate market activity. False negatives can allow drains, exploit cash outs, or laundering flows to continue. The correct tradeoff depends on the intervention available.

Consider an approval warning system. A false positive may annoy a user but still allow them to continue after review. A false negative may expose the user to a wallet drain. That system can reasonably favor higher recall. In contrast, an automated protocol pause has serious availability consequences, so it needs a much higher evidence threshold and ideally multiple independent signals.

Adaptive thresholding may help when traffic patterns vary by time, chain, or market condition. Science TechAsia’s forensic framework reports that temporal graph transformers, adaptive thresholding, and multi modal fusion can improve fraud detection and explainability. That is directionally useful, but adaptive systems need guardrails. Cap how quickly thresholds can move, review changes, and preserve an audit trail of each threshold decision.

Operate A Feedback And Drift Loop

Attackers adapt after public reports, tool releases, and protocol changes. Monitor feature distributions, alert rates, investigation outcomes, and missed incidents. A sudden fall in positive labels may mean attacks declined, but it may also mean the model stopped recognizing a new technique.

Retraining should be triggered by evidence, not by calendar ritual alone. Useful triggers include:

• A meaningful shift in contract call distributions or bridge routes.

• Persistent decline in analyst confirmed precision.

• A major protocol upgrade, new chain integration, or token standard change.

• A postmortem that reveals a missed transaction pattern.

• Material changes in data coverage, trace availability, or labeling policy.

Human feedback is the corrective mechanism. Require analysts to record why an alert was confirmed, dismissed, or escalated. Those reasons become structured labels for the next training cycle. If the model repeatedly flags legitimate arbitrage because it resembles rapid multi hop movement, create an explicit benign arbitrage class or features that distinguish known execution infrastructure from exploit cash out behavior.

FAQ

What Is The Best Way To Train A Custom Model To Detect Malicious Web3 Transactions?

Start with one threat type, one intervention, and a time aware labeled dataset. Build a strong tabular baseline first, then add sequence or graph models only if testing shows that timing or relationships materially improve queue quality.

What Data Should Be Used To Label Malicious Blockchain Transactions?

Use confirmed incident postmortems, validated internal investigations, attributable exploit addresses, verified malicious contracts, and carefully time stamped reputation data. Keep unverified suspicions separate from confirmed labels so they do not silently corrupt the training set.

How Should Teams Handle Severe Class Imbalance?

Use class weighting, controlled resampling, anomaly detection, and precision focused evaluation at realistic alert volumes. Do not manufacture large volumes of synthetic malicious examples unless the synthetic behavior reflects a specific, validated attack mechanism.

When Does An Unsupervised Model Work Better Than A Supervised Classifier?

Use unsupervised detection when labels are scarce, attackers are changing tactics, or the immediate goal is finding unknown clusters for review. It works best as a complement to supervised models because anomalies include benign novelty, such as a legitimate protocol launch or market event.

How Can A Team Reduce False Positives Without Missing Exploits?

Require corroboration from independent signals: transaction sequence, wallet history, contract behavior, and graph context. Use risk bands rather than one hard cutoff, and reserve irreversible actions for high confidence evidence. Analyst feedback should be captured as labeled outcomes, not informal notes.

Which Features Matter Most For Bridge Abuse And Cross Chain Laundering?

Prioritize bridge timing, source and destination wallet relationships, asset mapping, value fragmentation, destination chain swaps, repeated routing, and exposure to previously confirmed risky infrastructure. Treat uncertain links as probabilistic evidence rather than certain attribution.

How Often Should A Web3 Threat Detection Model Be Retrained?

Retrain after meaningful drift, protocol upgrades, new attack intelligence, or declining investigation quality. A fixed schedule can support governance, but it should not replace event driven review. A model may need urgent recalibration after a bridge integration even if it was retrained recently.

Sources And References

  1. ACM Digital Library — Blockchain Fraud Detection Using Unsupervised Learning: Anomalous Transaction Patterns Detection Using K-Means Clustering https://dl.acm.org/doi/pdf/10.1145/3675888.3676080

  2. Forta — Three Ways Machine Learning Can Detect Web3 Security Threats https://www.forta.org/blog/three-ways-machine-learning-can-detect-web3-security-threats

  3. Wiley — Explainable AI With Imbalanced Learning Strategies for Blockchain ... https://onlinelibrary.wiley.com/doi/10.1002/eng2.70545

  4. Springer — A hybrid deep learning–blockchain framework for reliable ... https://link.springer.com/article/10.1186/s40537-026-01506-5

  5. Science/TechAsia — Design of an Integrated Modern Explainable Machine Learning Framework for Blockchain Forensic Analysis https://ph02.tci-thaijo.org/index.php/SciTechAsia/article/view/259081

NFT Demon Holdings helps enterprises scope, evaluate, and build blockchain programs — start with a free evaluation call.

Talk through your use case

Free evaluation call — objective, constraints, and fit, before any proposal.

Call 858-327-1144 Email jeremy@nftdemon.com