ERC4337 Validation
Getting Started

Getting started

CheckNSignatures is a Solidity library that can be installed in different ways. Below, you will find instructions for using it together with Foundry.

Installation

Using a package manager

npm i @rhinestone/erc4337-validation

Using git submodules

forge install rhinestonewtf/erc4337-validation

Quick Start

To use this library, simply import the Simulator and set it up as follows:

import {Simulator} from "@rhinestone/erc4337-validation/Simulator.sol";
 
contract Example {
    using Simulator for PackedUserOperation; // or UserOperation
 
   function verify(PackedUserOperation memory userOp) external view {
        // Verify the ERC-4337 rules
        userOp.simulateUserOp(entryPointAddress);
    }
}

If the userOp breaks any of the rules, the function will revert with a message indicating which rule was broken.

Note that the entryPointAddress needs to be the address of the EntryPointSimulations contract if you are using v0.7 of ERC-4337. For an example see the Simulator test (opens in a new tab), the Simulator test v0.6 (opens in a new tab) and the relevant test bases (opens in a new tab).