Skip to content
Lattice

ERC4337ValidationLib

Git Source

Title: ERC4337ValidationLib

Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from eth-infinitism account-abstraction (https://github.com/eth-infinitism/account-abstraction)

Logic + ERC-7201 storage for the ERC-4337 validation facet. validateUserOp is gated to the configured EntryPoint, validates the user op signature against the AccountSigner owner, and pays the EntryPoint its prefund.

The user op signature is checked over the EIP-191 (personal_sign) digest of userOpHash (SimpleAccount convention), routed through AccountSignerLib so the owner may be an EOA or an ERC-1271 contract. Per ERC-4337, a signature mismatch returns SIG_VALIDATION_FAILED (1) rather than reverting; only an unauthorized caller reverts. No validUntil/validAfter time-range in v1.

Functions

erc4337ValidationStorage

function erc4337ValidationStorage() internal pure returns (ERC4337ValidationStorage storage $);

Returns

NameTypeDescription
$ERC4337ValidationStorage

__ERC4337Validation_init

Seeds the trusted EntryPoint during diamond initialization.

function __ERC4337Validation_init(address entryPoint_) internal;

Parameters

NameTypeDescription
entryPoint_address

entryPoint

function entryPoint() internal view returns (address);

Returns

NameTypeDescription
<none>address

setEntryPoint

Sets the trusted EntryPoint. Admin only.

function setEntryPoint(address entryPoint_) internal;

Parameters

NameTypeDescription
entryPoint_address

validateUserOp

ERC-4337 account validation. Only the EntryPoint may call.

function validateUserOp(PackedUserOperation calldata userOp, bytes32 userOpHash, uint256 missingAccountFunds)
        internal
        returns (uint256 validationData);

Parameters

NameTypeDescription
userOpPackedUserOperation
userOpHashbytes32
missingAccountFundsuint256

Returns

NameTypeDescription
validationDatauint256

_setEntryPoint

function _setEntryPoint(address entryPoint_) private;

Parameters

NameTypeDescription
entryPoint_address

_payPrefund

Pays the EntryPoint (msg.sender) its prefund. Result is intentionally ignored: per ERC-4337 the EntryPoint validates its own balance change, and reverting here would block validation.

function _payPrefund(uint256 missingAccountFunds) private;

Parameters

NameTypeDescription
missingAccountFundsuint256