Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
LABS
Guides

Launching a Fraud Detection System for User Operations

This guide provides a technical blueprint for bundlers and paymasters to implement automated fraud detection for ERC-4337 UserOperations before they are included in a bundle.
Chainscore © 2026
introduction
INTRODUCTION

Launching a Fraud Detection System for User Operations

A guide to implementing a proactive security layer for ERC-4337 smart accounts and native account abstraction.

A fraud detection system (FDS) is a critical security component for any application handling UserOperations (UserOps). It acts as a pre-execution filter, analyzing the intent and risk profile of a transaction before it is submitted to the blockchain. In the context of ERC-4337 and account abstraction, this system is typically integrated with a Bundler or a Paymaster to screen for malicious patterns, such as transaction replay, phishing attempts, or interactions with known scam contracts. The primary goal is to protect end-users from financial loss and maintain the integrity of your application's transaction flow.

Implementing an FDS shifts security from a reactive to a proactive stance. Instead of relying solely on post-hoc analysis or hoping users verify every transaction detail, the system automatically evaluates risk based on configurable rules and threat intelligence. Key detection vectors include analyzing the sender address reputation, the callData for known malicious signatures, the target contract's history, and gas patterns indicative of drainer attacks. Services like Blockaid and Blowfish provide specialized APIs for this, while open-source projects offer a foundation for custom rule engines.

This guide will walk through the core architecture of a fraud detection system. We'll cover the essential components: the Risk Engine for applying detection rules, the Data Layer for accessing real-time threat feeds and historical data, and the Integration Points with Bundlers (via the eth_sendUserOperation RPC) or Paymaster validation logic. We'll also discuss the trade-offs between using a third-party service versus building an in-house solution, considering factors like latency, cost, coverage, and control over the rule-set.

To make this concrete, we'll provide a practical code example using a Node.js service that intercepts UserOperations. The example will show how to validate a UserOp against a simple rule—checking if the target contract is on a blocklist—and then return a standardized risk score. This foundational pattern can be extended with more sophisticated checks, such as simulating transaction outcomes, checking for address poisoning, or integrating machine learning models for anomaly detection.

By the end of this guide, you will understand how to design and launch a basic fraud detection system. This will enable you to significantly reduce the risk of successful attacks on your users, building trust and safety into the core of your application's interaction with smart accounts and the broader Ethereum Virtual Machine (EVM) ecosystem.

prerequisites
SETUP

Prerequisites

Before launching a fraud detection system for User Operations, ensure your environment and accounts are properly configured.

To build a fraud detection system for UserOperation validation, you need a foundational understanding of Account Abstraction (ERC-4337) and its core components. This includes the EntryPoint contract, which orchestrates the validation and execution of operations, and Bundlers, which package and submit these operations to the network. You should be familiar with the UserOperation data structure, which contains fields like sender, nonce, callData, and signature that your system will analyze. A working knowledge of Ethereum and smart contract development is essential, as the detection logic will interact directly with the blockchain.

Your development environment must be ready. You will need Node.js (v18 or later) and a package manager like npm or yarn. Essential tools include a TypeScript compiler for type safety and a testing framework such as Hardhat or Foundry for deploying and interacting with contracts. You must have access to an Ethereum RPC endpoint; you can use a service like Alchemy, Infura, or run a local node. For managing private keys and signing transactions securely, configure a wallet provider like ethers.js or viem.

You will need access to specific smart contracts and services. Deploy or connect to an ERC-4337 EntryPoint contract (the official version is recommended). Your system will also require a Paymaster to sponsor transaction gas if your detection logic involves simulating operations, and a Smart Contract Account factory to create test accounts. Ensure you have testnet ETH (on Sepolia or Goerli) for the accounts you control to pay for gas during development and testing phases.

Finally, set up the core monitoring infrastructure. This involves creating a service that can listen for pending UserOperation events emitted by mempools or bundlers. You will need to implement a JSON-RPC client to connect to a bundler's eth_sendUserOperation endpoint or monitor a P2P mempool. Your system should be able to fetch operation data, decode it, and apply your fraud detection rules before the operation is included in a bundle and executed on-chain.

key-concepts-text
CORE DETECTION MECHANISMS

Launching a Fraud Detection System for User Operations

A practical guide to implementing real-time detection for malicious or anomalous user operations in a Web3 application.

A fraud detection system for user operations (UserOps) acts as a security layer for applications using account abstraction, such as those built on ERC-4337. Its primary function is to analyze, score, and potentially block operations before they are submitted to the mempool. This is critical because once a malicious UserOperation is bundled and included in a block, its effects are irreversible. Effective systems typically operate as a RPC middleware, intercepting requests to your bundler or paymaster to apply security policies. The core architecture involves an ingestion service to receive operations, a rules engine to evaluate them, and a decision service to allow, reject, or flag them for review.

The detection logic is powered by a combination of static rules and dynamic analysis. Static rules check for clear violations: Is the sender address on a known blocklist? Does the callData attempt to interact with a sanctioned contract? Is the gas limit abnormally high, suggesting a potential griefing attack? Dynamic analysis involves simulating the operation. By using eth_call to a local node, you can pre-execute the transaction to see its outcome—checking if it would drain funds to a suspicious address or repeatedly call a known exploit contract. This simulation must account for state differences, often using a forked blockchain environment to ensure accuracy.

To build a robust system, you need to define and score risk indicators. Common signals include: - Velocity Checks: Frequency of operations from a single sender or associated addresses. - Behavioral Anomalies: Sudden changes in transaction patterns or value transfers. - Reputation Data: Leveraging on-chain intelligence from providers like Chainalysis or TRM Labs. - Smart Contract Interaction Risk: Analyzing the target contracts for known vulnerabilities or malicious code. Each signal is assigned a risk score, and an aggregate score determines the final action. For example, an operation interacting with a mixer and requesting high gas might be flagged, while one that simply swaps tokens on a reputable DEX would pass.

Implementing this requires integrating with your stack. If you're using a bundler like stackup, pimlico, or alchemy, you can deploy a JSON-RPC middleware that proxies requests. Here's a simplified Node.js example using Express that checks for a blocklisted sender:

javascript
app.post('/rpc', async (req, res) => {
  const { method, params } = req.body;
  if (method === 'eth_sendUserOperation') {
    const userOp = params[0];
    if (BLOCKLIST.has(userOp.sender)) {
      return res.json({ error: { code: -32600, message: 'Sender blocked' } });
    }
  }
  // Forward to actual bundler
  const bundlerResponse = await fetch(BUNDLER_URL, { method: 'POST', body: JSON.stringify(req.body) });
  res.json(await bundlerResponse.json());
});

For production systems, consider scalability and false positives. Processing must be low-latency to not bottleneck user experience. Use asynchronous scoring for complex checks and maintain an allowlist for trusted patterns. Continuously update your rule sets based on emerging threats and audit logs of blocked operations. Tools like OpenZeppelin Defender can help manage rule sets, while services like Chainscore provide pre-built risk APIs for UserOps. Ultimately, a layered approach combining immediate rule-based filtering, simulation, and external threat intelligence offers the best protection for your users and your application's financial logic.

detection-components
ARCHITECTURE

Key System Components

A robust fraud detection system for UserOperations requires specific, interoperable components. This section details the essential tools and concepts for building and monitoring your defense layer.

01

Bundler Integration & Validation

The bundler is the entry point for UserOperations. Integrate with it to access the raw operation data for analysis. Key actions include:

  • Pre-UserOpHook: Implement a hook to validate operations before they are included in a bundle. This can block malicious transactions at the source.
  • Post-UserOpHook: Analyze operations after simulation but before on-chain submission for more complex, state-dependent checks.
  • Use the eth_estimateUserOperationGas RPC method to simulate execution and detect gas-related anomalies or failed simulations indicative of fraud.
02

Paymaster Policy Engine

The paymaster sponsors transaction gas. Use it as a policy enforcement point by creating a custom paymaster contract with rule-based logic.

  • Rule Sets: Define conditions for sponsorship, such as allowed destinations, maximum value transfers, or frequency limits per account.
  • Real-time Analysis: Integrate off-chain risk signals (e.g., from a reputation service) into the paymaster's validatePaymasterUserOp function to approve or reject sponsorship.
  • This creates a financial gate that can stop fraudulent transactions before they cost the protocol or user funds.
03

Reputation & Threat Intelligence

Maintain and query a reputation system to score addresses and contracts based on historical behavior.

  • On-chain Data: Track factors like rapid account creation (factory contracts), association with known phishing domains from initCode, or involvement in past hacks.
  • Off-chain Feeds: Integrate with threat intelligence APIs (e.g., TRM Labs, Chainalysis) to flag addresses linked to sanctions or illicit activity.
  • Scoring: Assign risk scores to senders, beneficiaries, and involved smart contracts to inform automated decisions by the bundler or paymaster.
04

Anomaly Detection Models

Deploy statistical and machine learning models to identify deviations from normal user behavior.

  • Baseline Establishment: Model typical gas usage, transaction timing, and interaction patterns for legitimate accounts.
  • Real-time Detection: Flag anomalies such as sudden high-value transfers, interactions with newly deployed contracts, or transactions originating from atypical geographic nodes.
  • Model Types: Use clustering for segmentation, classification for binary fraud/legit decisions, and time-series analysis for detecting burst attacks.
05

Alerting & Dashboard (Mempool Monitor)

Build a real-time monitoring dashboard to visualize system health and fraud attempts.

  • Mempool Streaming: Subscribe to pending UserOperations via a bundler's mempool or a service like BloXroute or Blocknative to see transactions before they are mined.
  • Key Metrics: Display fraud attempt rate, blocked transaction volume, top threat patterns, and system false-positive rates.
  • Alert Channels: Integrate with PagerDuty, Slack, or Telegram to notify security teams of high-severity threats requiring manual intervention.
06

EntryPoint Security Wrappers

The EntryPoint contract is the singleton execution hub for all ERC-4337 operations. Enhance its security with additional layers.

  • Rate Limiting: Implement a wrapper that enforces global rate limits on operations per bundler or per paymaster to mitigate DDoS attacks.
  • Simulation Sandbox: Run a secondary, more rigorous simulation (e.g., using Tenderly or a forked node) for high-risk operations flagged by other components before allowing them to proceed to the canonical handleOps.
  • Upgrade Safety: Monitor for and validate any proposed upgrades to the official EntryPoint contract to ensure backward compatibility and no introduced vulnerabilities.
implementation-steps
IMPLEMENTATION STEPS

Launching a Fraud Detection System for User Operations

A practical guide to building a system that monitors and flags suspicious on-chain user interactions, focusing on modular design and real-time analysis.

The first step is to define the data ingestion layer. Your system must reliably collect raw transaction data from the blockchain. For Ethereum and EVM-compatible chains, you can use services like Alchemy or QuickNode to subscribe to new blocks via WebSocket streams. For a self-hosted solution, run an archive node and use the eth_subscribe JSON-RPC method. The goal is to parse each new block, extract all transactions, and filter for those involving your target smart contracts or wallet addresses. This creates a real-time feed of UserOperation events for analysis.

Next, implement the core detection engine. This component applies heuristic rules and, optionally, machine learning models to the ingested data. Start with simple, deterministic rules: flag transactions with - gas prices exceeding 200% of the network average, - interactions with known malicious addresses (using threat intelligence feeds), - complex call patterns to obscure or newly deployed contracts, and - rapid, high-frequency interactions from a single address. These rules should be configurable and stored outside the application code for easy updates. For advanced detection, you can integrate models trained on historical fraud data to identify anomalous behavior patterns.

The third step is to establish the alerting and action system. When a transaction is flagged, the system must take predefined actions. This typically involves - logging the event with high severity to a dedicated dashboard (e.g., Datadog, Grafana), - sending real-time notifications to a security channel via Slack or PagerDuty, and - optionally, initiating an automated response. For critical threats, an automated response could involve pausing a vulnerable contract function via a multisig timelock or submitting a transaction to blacklist an address. Ensure all actions are logged for auditability and that automated responses have manual override capabilities to prevent false-positive cascades.

Finally, integrate post-analysis and feedback loops. A detection system improves over time. Store all flagged and unflagged transactions in a queryable database (like PostgreSQL or TimescaleDB). Regularly review false positives and false negatives to refine your detection rules. Implement a simple UI for security analysts to label events, creating a labeled dataset for retraining ML models. This continuous feedback cycle is critical for reducing alert fatigue and adapting to evolving attack vectors, turning your system from a static filter into a learning defense mechanism.

SCORING MATRIX

UserOperation Risk Scoring Criteria

Key heuristics and thresholds for evaluating the risk level of a UserOperation before execution.

Risk FactorLow Risk (0-3)Medium Risk (4-7)High Risk (8-10)

Gas Price Premium

< 10% over base fee

10-50% over base fee

50% over base fee

Call Data Size

< 1 KB

1-5 KB

5 KB

Uncommon Opcode Usage

1-2 uncommon opcodes

2 uncommon opcodes

Destination Contract Reputation

Top 100 DeFi / Verified

Moderate volume / Unverified

New / Malicious history

Simulation Revert Reason

Gas estimation failure

State change / Blacklist

InitCode Length

Standard factory pattern

Extended initialization

Excessive or obfuscated

Paymaster Dependency

Trusted paymaster (e.g., Pimlico)

Unverified paymaster

New / Zero-balance paymaster

Time Since Sender Creation

30 days

7-30 days

< 24 hours

integrating-threat-feeds
LAUNCHING A FRAUD DETECTION SYSTEM

Integrating External Threat Intelligence

Enhance your user operation security by incorporating real-time threat data from external sources to preemptively block malicious transactions.

A robust fraud detection system for user operations (UserOps) requires more than just analyzing on-chain data. External threat intelligence provides critical context by aggregating data from honeypots, dark web monitoring, phishing feeds, and IP reputation services. Integrating this data allows you to flag addresses, IPs, and transaction patterns associated with known scams, malware, or Sybil attacks before they interact with your application. Services like Forta Network, TRM Labs, and Chainalysis offer APIs that deliver real-time alerts on malicious actors and suspicious behaviors, which can be consumed by your security middleware.

To integrate this intelligence, you need a modular detection pipeline. A common architecture involves a security validation layer that sits between the user's wallet and your smart contract or bundler. When a UserOp is submitted, your system can query threat intelligence APIs to check the sender's address, associated IP, and transaction history against known threat lists. For example, you might check an address against the Ethereum Phishing Detection list or query a service like Blockaid for simulation-based risk scores. This check should happen during the validateUserOp function or in a pre-validation hook to minimize gas costs for legitimate users.

Implementing the checks requires careful error handling and caching. You should implement asynchronous, non-blocking calls to external APIs to avoid introducing latency into the UserOp validation flow. Use a caching layer (like Redis) to store threat data for recently seen addresses, updating it periodically. Here's a simplified Node.js example using the Forta API:

javascript
async function checkThreatIntelligence(senderAddress) {
  const cacheKey = `threat:${senderAddress}`;
  let threatData = await cache.get(cacheKey);
  if (!threatData) {
    const response = await fetch(`https://api.forta.network/address/${senderAddress}/risk`);
    threatData = await response.json();
    await cache.set(cacheKey, threatData, { EX: 300 }); // Cache for 5 minutes
  }
  return threatData.riskScore > THRESHOLD;
}

The key is to define clear risk scoring thresholds and actions. Not every flagged address should result in a hard rejection; some may warrant additional scrutiny like requiring a higher paymaster stake or triggering a manual review. Your system should log all flagged operations with the reason (e.g., "address on phishing list", "high-risk IP region") for later analysis and tuning. Continuously monitor your false positive rate—blocking legitimate users is costly. Adjust thresholds based on the precision and recall of your intelligence sources, and consider using multiple providers to reduce reliance on a single point of failure.

Finally, integrate these detections with your alerting and response systems. When a high-confidence threat is detected, automatically trigger alerts in your security team's Slack or Discord channel. For systemic attacks, you may need to update your smart contract's blocklist or pause certain functionalities via a guardian multisig. By layering external threat intelligence with your on-chain heuristics, you create a proactive defense system that adapts to the evolving threat landscape, protecting your users' assets and maintaining the integrity of your application.

TROUBLESHOOTING AND OPTIMIZATION

Launching a Fraud Detection System for User Operations

Common issues and solutions for developers implementing fraud detection for ERC-4337 UserOperations, focusing on bundler configuration, simulation failures, and gas optimization.

A simulation failed error occurs when the bundler's validation logic or the EntryPoint contract's validateUserOp function reverts. Common causes include:

  • Insufficient prefund: The smart contract wallet's deposit on the EntryPoint is less than the requiredPrefund for the operation.
  • Invalid signature: The signature format is incorrect for the wallet's verification method, or the validUntil/validAfter timestamps are not satisfied.
  • Out-of-order nonce: The UserOperation uses a nonce that the wallet's internal state does not expect.
  • Paymaster issues: If a paymaster is used, its validatePaymasterUserOp may fail due to policy rules or insufficient stake/deposit.

Debugging Steps:

  1. Check the specific revert reason in your bundler logs (e.g., Bundler or Stackup).
  2. Use tools like eth_call to simulate the validateUserOp call directly against the EntryPoint.
  3. Verify the wallet's EntryPoint deposit balance matches the operation's max cost.
TROUBLESHOOTING

Frequently Asked Questions

Common questions and solutions for developers implementing a fraud detection system for ERC-4337 User Operations.

A User Operation is flagged when its on-chain execution pattern deviates from the expected behavior defined by your fraud detection rules. Common triggers include:

  • Anomalous Transaction Value: A transfer amount exceeding a user's historical average by a defined threshold (e.g., 500%).
  • Novel Destination Address: The to address has never been interacted with by this account before.
  • Unusual Function Selector: The calldata calls a sensitive function (like transferOwnership) that the account doesn't typically use.
  • Gas Abuse Patterns: The op uses an abnormally high callGasLimit for a simple operation, suggesting a potential gas griefing attack.

Check your rule engine logs to see which specific rule matched and adjust thresholds in your Policy Contract if needed.

conclusion
IMPLEMENTATION GUIDE

Conclusion and Next Steps

You have now built the core components of a fraud detection system for ERC-4337 User Operations. This guide covers the final steps for deployment, monitoring, and scaling your system.

To finalize your implementation, integrate the FraudDetector contract with your bundler's validation logic. The key step is to call validateUserOp within your bundler's _validatePrepayment function, reverting if fraud is detected. For example, in a TypeScript-based bundler like skandha, you would modify the validation module to query your on-chain detector. Simultaneously, ensure your off-chain monitor is actively listening for UserOperationEvent logs and feeding data into your risk engine. This creates a dual-layer defense: pre-execution validation and post-execution analysis for pattern detection.

Effective monitoring is critical for maintaining system integrity. Your dashboard should track key metrics: the rate of flagged operations, false positive rates, gas overhead of on-chain checks, and latency of off-chain analysis. Set up alerts for sudden spikes in high-risk patterns, such as a cluster of operations from new accounts targeting the same contract. Use tools like Tenderly for transaction simulation and Dune Analytics for aggregating on-chain reputation data. Continuously tune your risk scoring model based on this real-world data to reduce false positives that could degrade user experience.

The next evolution of your system involves scaling and advanced techniques. Consider implementing a decentralized reputation network where multiple bundlers share anonymized fraud signals, creating a stronger collective defense. Explore using zero-knowledge proofs for private, verifiable fraud checks that don't leak user data. As the ERC-4337 ecosystem matures, stay updated with new standards like RIP-7560 for native account abstraction, which may introduce different security paradigms. Continue your research by reviewing audits of major bundlers like Stackup and Alchemy, and contribute to the community by sharing your findings on forums like the Ethereum Magicians.

How to Build a Fraud Detection System for UserOperations | ChainScore Guides