Account

Smart contract account utilities and implementations

This directory includes contracts to build accounts for ERC-4337. These include:

Modules

Executors

ERC7579Executor

ERC7579DelayedExecutor

ERC7579SelectorExecutor

Validators

ERC7579Validator

ERC7579Signature

ERC7579Multisig

ERC7579MultisigWeighted

ERC7579MultisigConfirmation

ERC7579MultisigStorage

Paymaster

PaymasterCore

PaymasterERC20

PaymasterERC20Guarantor

PaymasterERC721Owner

PaymasterSigner

import "@openzeppelin/contracts/account/modules/ERC7579DelayedExecutor.sol";

Extension of ERC7579Executor that allows scheduling and executing delayed operations with expiration. This module enables time-delayed execution patterns for smart accounts.

==== Operation Lifecycle

  1. Scheduling: Operations are scheduled via ERC7579DelayedExecutor.schedule with a specified delay period. The delay period is set during ERC7579DelayedExecutor.onInstall and can be customized via ERC7579DelayedExecutor.setDelay. Each operation enters a Scheduled state and must wait for its delay period to elapse.

  2. Security Window: During the delay period, operations remain in Scheduled state but cannot be executed. Through this period, suspicious operations can be monitored and canceled via ERC7579DelayedExecutor.cancel if appropriate.

  3. Execution & Expiration: Once the delay period elapses, operations transition to Ready state. Operations can be executed via ERC7579Executor.execute and have an expiration period after becoming executable. If an operation is not executed within the expiration period, it becomes Expired and can't be executed. Expired operations must be rescheduled with a different salt.

==== Delay Management

Accounts can set their own delay periods during installation or via ERC7579DelayedExecutor.setDelay. The delay period is enforced even between installas and uninstalls to prevent immediate downgrades. When setting a new delay period, the new delay takes effect after a transition period defined by the current delay or ERC7579DelayedExecutor.minSetback, whichever is longer.

==== Authorization

Authorization for scheduling and canceling operations is controlled through the ERC7579DelayedExecutor._validateSchedule and ERC7579DelayedExecutor._validateCancel functions. These functions can be overridden to implement custom authorization logic, such as requiring specific signers or roles.

TIP: Use ERC7579DelayedExecutor._scheduleAt to schedule operations at a specific points in time. This is useful to pre-schedule operations for non-deployed accounts (e.g. subscriptions).

state(address account, bytes32 salt, bytes32 mode, bytes executionCalldata) → enum ERC7579DelayedExecutor.OperationState

public

#

Current state of an operation.

state(bytes32 operationId) → enum ERC7579DelayedExecutor.OperationState

public

#

Same as ERC7579DelayedExecutor.state, but for a specific operation id.

minSetback() → uint32

public

#

Minimum delay after which ERC7579DelayedExecutor.setDelay takes effect. Set as default delay if not provided during ERC7579DelayedExecutor.onInstall.

getDelay(address account) → uint32 delay, uint32 pendingDelay, uint48 effectTime

public

#

Delay for a specific account.

getExpiration(address account) → uint32 expiration

public

#

Expiration delay for account operations.

getSchedule(address account, bytes32 salt, bytes32 mode, bytes executionCalldata) → uint48 scheduledAt, uint48 executableAt, uint48 expiresAt

public

#

Schedule for an operation. Returns default values if not set (i.e. uint48(0), uint48(0), uint48(0)).

getSchedule(bytes32 operationId) → uint48 scheduledAt, uint48 executableAt, uint48 expiresAt

public

#

Same as ERC7579DelayedExecutor.getSchedule but with the operation id.

hashOperation(address account, bytes32 salt, bytes32 mode, bytes executionCalldata) → bytes32

public

#

Returns the operation id.

defaultExpiration() → uint32

public

#

Default expiration for account operations. Set if not provided during ERC7579DelayedExecutor.onInstall.

onInstall(bytes initData)

public

#

Sets up the module's initial configuration when installed by an account. The account calling this function becomes registered with the module.

The initData may be abi.encode(uint32(initialDelay), uint32(initialExpiration)). The delay will be set to the maximum of this value and the minimum delay if provided. Otherwise, the delay will be set to ERC7579DelayedExecutor.minSetback and ERC7579DelayedExecutor.defaultExpiration respectively.

Behaves as a no-op if the module is already installed.

Requirements:

  • The account (i.e msg.sender) must implement the IERC7579ModuleConfig interface.
  • initData must be empty or decode correctly to (uint32, uint32).

setDelay(uint32 newDelay)

public

#

Allows an account to update its execution delay (see ERC7579DelayedExecutor.getDelay).

The new delay will take effect after a transition period defined by the current delay or ERC7579DelayedExecutor.minSetback, whichever is longer. This prevents immediate security downgrades. Can only be called by the account itself.

setExpiration(uint32 newExpiration)

public

#

Allows an account to update its execution expiration (see ERC7579DelayedExecutor.getExpiration).

schedule(address account, bytes32 salt, bytes32 mode, bytes data)

public

#

Schedules an operation to be executed after the account's delay period (see ERC7579DelayedExecutor.getDelay). Operations are uniquely identified by the combination of salt, mode, and data. See ERC7579DelayedExecutor._validateSchedule for authorization checks.

cancel(address account, bytes32 salt, bytes32 mode, bytes data)

public

#

Cancels a previously scheduled operation. Can only be called by the account that scheduled the operation. See ERC7579DelayedExecutor._cancel.

onUninstall(bytes)

public

#

Cleans up the ERC7579DelayedExecutor.getDelay and ERC7579DelayedExecutor.getExpiration values by scheduling them to 0 and respecting the previous delay and expiration values.

This function does not clean up scheduled operations. This means operations

could potentially be re-executed if the module is reinstalled later. This is a deliberate design choice for efficiency, but module implementations may want to override this behavior to clear scheduled operations during uninstallation for their specific use cases.

NOTE: Calling this function directly will remove the expiration (ERC7579DelayedExecutor.getExpiration) value and will schedule a reset of the delay (ERC7579DelayedExecutor.getDelay) to 0 for the account. Reinstalling the module will not immediately reset the delay if the delay reset hasn't taken effect yet.

_validateExecution(address, bytes32, bytes32, bytes data) → bytes

internal

#

Returns data as the execution calldata. See ERC7579Executor._execute.

NOTE: This function relies on the operation state validation in ERC7579DelayedExecutor._execute for authorization. Extensions of this module should override this function to implement additional validation logic if needed.

_validateCancel(address account, bytes32, bytes32, bytes)

internal

#

Validates whether an operation can be canceled.

Example extension:

 function _validateCancel(address account, bytes32 salt, bytes32 mode, bytes calldata data) internal override {
   // e.g. require(msg.sender == account);
 }

_validateSchedule(address account, bytes32, bytes32, bytes)

internal

#

Validates whether an operation can be scheduled.

Example extension:

 function _validateSchedule(address account, bytes32 salt, bytes32 mode, bytes calldata data) internal override {
   // e.g. require(msg.sender == account);
 }

_setDelay(address account, uint32 newDelay, uint32 minimumSetback)

internal

#

Internal implementation for setting an account's delay. See ERC7579DelayedExecutor.getDelay.

Emits an ERC7579DelayedExecutor.ERC7579ExecutorDelayUpdated event.

_setExpiration(address account, uint32 newExpiration)

internal

#

Internal implementation for setting an account's expiration. See ERC7579DelayedExecutor.getExpiration.

Emits an ERC7579DelayedExecutor.ERC7579ExecutorExpirationUpdated event.

scheduleAt(address account, bytes32 salt, bytes32 mode, bytes executionCalldata, uint48 timepoint, uint32 delay) → bytes32 operationId, struct ERC7579DelayedExecutor.Schedule schedule

internal

#

Internal version of ERC7579DelayedExecutor.schedule that takes an account address to schedule an operation that starts its security window at at and expires after delay.

Requirements:

  • The operation must be Unknown.

Emits an ERC7579DelayedExecutor.ERC7579ExecutorOperationScheduled event.

_execute(address account, bytes32 salt, bytes32 mode, bytes executionCalldata) → bytes[] returnData

internal

#

See ERC7579Executor._execute.

Requirements:

  • The operation must be Ready.

_cancel(address account, bytes32 mode, bytes executionCalldata, bytes32 salt)

internal

#

Internal version of ERC7579DelayedExecutor.cancel that takes an account address as an argument.

Requirements:

  • The operation must be Scheduled or Ready.

Canceled operations can't be rescheduled. Emits an ERC7579DelayedExecutor.ERC7579ExecutorOperationCanceled event.

_validateStateBitmap(bytes32 operationId, bytes32 allowedStates) → enum ERC7579DelayedExecutor.OperationState

internal

#

Check that the current state of a operation matches the requirements described by the allowedStates bitmap. This bitmap should be built using ERC7579DelayedExecutor._encodeStateBitmap.

If requirements are not met, reverts with a ERC7579DelayedExecutor.ERC7579ExecutorUnexpectedOperationState error.

_encodeStateBitmap(enum ERC7579DelayedExecutor.OperationState operationState) → bytes32

internal

#

Encodes a OperationState into a bytes32 representation where each bit enabled corresponds to the underlying position in the OperationState enum. For example:

0x000...10000
  ^^^^^^------ ...
        ^----- Canceled
         ^---- Executed
          ^--- Ready
           ^-- Scheduled
            ^- Unknown

ERC7579ExecutorOperationScheduled(address indexed account, bytes32 indexed operationId, bytes32 salt, bytes32 mode, bytes executionCalldata, uint48 schedule)

event

#

Emitted when a new operation is scheduled.

ERC7579ExecutorOperationCanceled(address indexed account, bytes32 indexed operationId)

event

#

Emitted when a new operation is canceled.

ERC7579ExecutorDelayUpdated(address indexed account, uint32 newDelay, uint48 effectTime)

event

#

Emitted when the execution delay is updated.

ERC7579ExecutorExpirationUpdated(address indexed account, uint32 newExpiration)

event

#

Emitted when the expiration delay is updated.

ERC7579ExecutorUnexpectedOperationState(bytes32 operationId, enum ERC7579DelayedExecutor.OperationState currentState, bytes32 allowedStates)

error

#

The current state of a operation is not the expected. The expectedStates is a bitmap with the bits enabled for each OperationState enum position counting from right to left. See ERC7579DelayedExecutor._encodeStateBitmap.

NOTE: If expectedState is bytes32(0), the operation is expected to not be in any state (i.e. not exist).

ERC7579ExecutorModuleNotInstalled()

error

#

The module is not installed on the account.

import "@openzeppelin/contracts/account/modules/ERC7579Executor.sol";

Basic implementation for ERC-7579 executor modules that provides execution functionality for smart accounts.

The module enables accounts to execute arbitrary operations, leveraging the execution capabilities defined in the ERC-7579 standard. Developers can customize whether an operation can be executed with custom rules by implementing the ERC7579DelayedExecutor._validateExecution function in derived contracts.

TIP: This is a simplified executor that directly executes operations without delay or expiration mechanisms. For a more advanced implementation with time-delayed execution patterns and security features, see ERC7579DelayedExecutor.

isModuleType(uint256 moduleTypeId) → bool

public

#

Returns boolean value if module is a certain type

execute(address account, bytes32 salt, bytes32 mode, bytes data) → bytes[] returnData

public

#

Executes an operation and returns the result data from the executed operation. Restricted to the account itself by default. See ERC7579DelayedExecutor._execute for requirements and ERC7579DelayedExecutor._validateExecution for authorization checks.

_validateExecution(address account, bytes32 salt, bytes32 mode, bytes data) → bytes

internal

#

Validates whether the execution can proceed. This function is called before executing the operation and returns the execution calldata to be used.

Example extension:

 function _validateExecution(address account, bytes32 salt, bytes32 mode, bytes calldata data)
     internal
     override
     returns (bytes calldata)
 {
     // custom logic
     return data;
 }

TIP: Pack extra data in the data arguments (e.g. a signature) to be used in the validation process. Calldata can be sliced to extract it and return only the execution calldata.

_execute(address account, bytes32 mode, bytes32 salt, bytes executionCalldata) → bytes[] returnData

internal

#

Internal version of ERC7579Executor.execute. Emits ERC7579Executor.ERC7579ExecutorOperationExecuted event.

Requirements:

  • The account must implement the IERC7579Execution-executeFromExecutor function.

ERC7579ExecutorOperationExecuted(address indexed account, bytes32 salt, bytes32 mode, bytes executionCalldata)

event

#

Emitted when an operation is executed.

import "@openzeppelin/contracts/account/modules/ERC7579Multisig.sol";

Implementation of an ERC7579Validator that uses ERC-7913 signers for multisignature validation.

This module provides a base implementation for multisignature validation that can be attached to any function through the ERC7579Multisig._rawERC7579Validation internal function. The signers are represented using the ERC-7913 format, which concatenates a verifier address and a key: verifier || key.

A smart account with this module installed can require multiple signers to approve operations before they are executed, such as requiring 3-of-5 guardians to approve a social recovery operation.

onInstall(bytes initData)

public

#

Sets up the module's initial configuration when installed by an account. See ERC7579DelayedExecutor.onInstall. Besides the delay setup, the initdata can include signers and threshold.

The initData should be encoded as: abi.encode(bytes[] signers, uint64 threshold)

If no signers or threshold are provided, the multisignature functionality will be disabled until they are added later.

NOTE: An account can only call onInstall once. If called directly by the account, the signer will be set to the provided data. Future installations will behave as a no-op.

onUninstall(bytes)

public

#

Cleans up module's configuration when uninstalled from an account. Clears all signers and resets the threshold.

See ERC7579DelayedExecutor.onUninstall.

This function has unbounded gas costs and may become uncallable if the set grows too large.

See EnumerableSet-clear.

getSigners(address account, uint64 start, uint64 end) → bytes[]

public

#

Returns a slice of the set of authorized signers for the specified account.

Using start = 0 and end = type(uint64).max will return the entire set of signers.

Depending on the start and end, this operation can copy a large amount of data to memory, which

can be expensive. This is designed for view accessors queried without gas fees. Using it in state-changing functions may become uncallable if the slice grows too large.

getSignerCount(address account) → uint256

public

#

Returns the number of authorized signers for the specified account.

isSigner(address account, bytes signer) → bool

public

#

Returns whether the signer is an authorized signer for the specified account.

threshold(address account) → uint64

public

#

Returns the minimum number of signers required to approve a multisignature operation for the specified account.

addSigners(bytes[] newSigners)

public

#

Adds new signers to the authorized set for the calling account. Can only be called by the account itself.

Requirements:

  • Each of newSigners must be at least 20 bytes long.
  • Each of newSigners must not be already authorized.

removeSigners(bytes[] oldSigners)

public

#

Removes signers from the authorized set for the calling account. Can only be called by the account itself.

Requirements:

  • Each of oldSigners must be authorized.
  • After removal, the threshold must still be reachable.

setThreshold(uint64 newThreshold)

public

#

Sets the threshold for the calling account. Can only be called by the account itself.

Requirements:

  • The threshold must be reachable with the current number of signers.

_rawERC7579Validation(address account, bytes32 hash, bytes signature) → bool

internal

#

Returns whether the number of valid signatures meets or exceeds the threshold set for the target account.

The signature should be encoded as: abi.encode(bytes[] signingSigners, bytes[] signatures)

Where signingSigners are the authorized signers and signatures are their corresponding signatures of the operation hash.

_addSigners(address account, bytes[] newSigners)

internal

#

Adds the newSigners to those allowed to sign on behalf of the account.

Requirements:

_removeSigners(address account, bytes[] oldSigners)

internal

#

Removes the oldSigners from the authorized signers for the account.

Requirements:

_setThreshold(address account, uint64 newThreshold)

internal

#

Sets the signatures threshold required to approve a multisignature operation.

Requirements:

_validateReachableThreshold(address account)

internal

#

Validates the current threshold is reachable with the number of ERC7579Multisig._signersSetByAccount.

Requirements:

_validateSignatures(address account, bytes32 hash, bytes[] signingSigners, bytes[] signatures) → bool valid

internal

#

Validates the signatures using the signers and their corresponding signatures. Returns whether the signers are authorized and the signatures are valid for the given hash.

The signers must be ordered by their keccak256 hash to prevent duplications and to optimize the verification process. The function will return false if any signer is not authorized or if the signatures are invalid for the given hash.

Requirements:

  • The signatures array must be at least the signers array's length.

_validateThreshold(address account, bytes[] validatingSigners) → bool

internal

#

Validates that the number of signers meets the ERC7579Multisig.threshold requirement. Assumes the signers were already validated. See ERC7579Multisig._validateSignatures for more details.

ERC7913SignerAdded(address indexed account, bytes signer)

event

#

Emitted when signers are added.

ERC7913SignerRemoved(address indexed account, bytes signer)

event

#

Emitted when signers are removed.

ERC7913ThresholdSet(address indexed account, uint64 threshold)

event

#

Emitted when the threshold is updated.

ERC7579MultisigAlreadyExists(bytes signer)

error

#

The signer already exists.

ERC7579MultisigNonexistentSigner(bytes signer)

error

#

The signer does not exist.

ERC7579MultisigInvalidSigner(bytes signer)

error

#

The signer is less than 20 bytes long.

ERC7579MultisigZeroThreshold()

error

#

The threshold is zero.

ERC7579MultisigUnreachableThreshold(uint64 signers, uint64 threshold)

error

#

The threshold is unreachable given the number of signers.

import "@openzeppelin/contracts/account/modules/ERC7579MultisigConfirmation.sol";

Extension of ERC7579Multisig that requires explicit confirmation signatures from new signers when they are being added to the multisig.

This module ensures that only willing participants can be added as signers to a multisig by requiring each new signer to provide a valid signature confirming their consent to be added. Each signer must sign an EIP-712 message to confirm their addition.

TIP: Use this module to ensure that all guardians in a social recovery or multisig setup have explicitly agreed to their roles.

_signableConfirmationHash(address account, uint256 deadline) → bytes32

internal

#

Generates a hash that signers must sign to confirm their addition to the multisig of account.

_addSigners(address account, bytes[] newSigners)

internal

#

Extends ERC7579Multisig._addSigners _addSigners to require confirmation signatures Each entry in newSigners must be ABI-encoded as:

abi.encode(deadline,signer,signature); // uint256, bytes, bytes
  • signer: The ERC-7913 signer to add
  • signature: The signature from this signer confirming their addition

The function verifies each signature before adding the signer. If any signature is invalid, the function reverts with ERC7579MultisigConfirmation.ERC7579MultisigInvalidConfirmationSignature.

ERC7579MultisigInvalidConfirmationSignature(bytes signer)

error

#

Error thrown when a signer's confirmation signature is invalid

ERC7579MultisigExpiredConfirmation(uint256 deadline)

error

#

Error thrown when a confirmation signature has expired

import "@openzeppelin/contracts/account/modules/ERC7579MultisigStorage.sol";

Extension of ERC7579Multisig that allows storing presigned approvals in storage.

This module extends the multisignature module to allow signers to presign operations, which are then stored in a mapping and can be used during validation. This enables more flexible multisignature workflows where signatures can be collected over time without requiring all signers to be online simultaneously.

When validating signatures, if a signature is empty, it indicates a presignature and the validation will check the storage mapping instead of cryptographic verification.

presigned(address account, bytes signer, bytes32 hash) → bool

public

#

Returns whether a signer has presigned a specific hash for the account

presign(address account, bytes signer, bytes32 hash, bytes signature)

public

#

Allows a signer to presign a hash by providing a valid signature. The signature will be verified and if valid, the presignature will be stored.

Emits ERC7579MultisigStorage.ERC7579MultisigStoragePresigned if the signature is valid and the hash is not already signed, otherwise acts as a no-op.

NOTE: Does not check if the signer is authorized for the account. Valid signatures from invalid signers won't be executable. See ERC7579Multisig._validateSignatures for more details.

_validateSignatures(address account, bytes32 hash, bytes[] signingSigners, bytes[] signatures) → bool valid

internal

#

See ERC7579Multisig._validateSignatures.

If a signature is empty, it indicates a presignature and the validation will check the storage mapping instead of cryptographic verification. See ERC7579Multisig._signersSetByAccount for more details.

ERC7579MultisigStoragePresigned(address indexed account, bytes32 indexed hash, bytes signer)

event

#

Emitted when a signer signs a hash

import "@openzeppelin/contracts/account/modules/ERC7579MultisigWeighted.sol";

Extension of ERC7579Multisig that supports weighted signatures.

This module extends the multisignature module to allow assigning different weights to each signer, enabling more flexible governance schemes. For example, some guardians could have higher weight than others, allowing for weighted voting or prioritized authorization.

Example use case:

A smart account with this module installed can schedule social recovery operations after obtaining approval from guardians with sufficient total weight (e.g., requiring a total weight of 10, with 3 guardians weighted as 5, 3, and 2), and then execute them after the time delay has passed.

When setting a threshold value, ensure it matches the scale used for signer weights.

For example, if signers have weights like 1, 2, or 3, then a threshold of 4 would require signatures with a total weight of at least 4 (e.g., one with weight 1 and one with weight 3).

onInstall(bytes initData)

public

#

Sets up the module's initial configuration when installed by an account. Besides the standard delay and signer configuration, this can also include signer weights.

The initData should be encoded as: abi.encode(bytes[] signers, uint64 threshold, uint64[] weights)

If weights are not provided but signers are, all signers default to weight 1.

NOTE: An account can only call onInstall once. If called directly by the account, the signer will be set to the provided data. Future installations will behave as a no-op.

onUninstall(bytes data)

public

#

Cleans up module's configuration when uninstalled from an account. Clears all signers, weights, and total weights.

See ERC7579Multisig.onUninstall.

signerWeight(address account, bytes signer) → uint64

public

#

Gets the weight of a signer for a specific account. Returns 0 if the signer is not authorized.

totalWeight(address account) → uint64

public

#

Gets the total weight of all signers for a specific account.

setSignerWeights(bytes[] signers, uint64[] weights)

public

#

Sets weights for signers for the calling account. Can only be called by the account itself.

_setSignerWeights(address account, bytes[] signers, uint64[] weights)

internal

#

Sets weights for multiple signers at once. Internal version without access control.

Requirements:

Emits ERC7579MultisigWeighted.ERC7579MultisigWeightChanged for each signer.

_addSigners(address account, bytes[] newSigners)

internal

#

Override to add weight tracking. See ERC7579Multisig._addSigners. Each new signer has a default weight of 1.

In cases where ERC7579MultisigWeighted.totalWeight is almost type(uint64).max (due to a large _totalExtraWeight), adding new signers could cause the ERC7579MultisigWeighted.totalWeight computation to overflow. Adding a ERC7579MultisigWeighted.totalWeight call after the new signers are added ensures no such overflow happens.

_removeSigners(address account, bytes[] oldSigners)

internal

#

Override to handle weight tracking during removal. See ERC7579Multisig._removeSigners.

Just like ERC7579Multisig._addSigners, this function does not emit ERC7579MultisigWeighted.ERC7579MultisigWeightChanged events. The ERC7579Multisig.ERC7913SignerRemoved event emitted by ERC7579Multisig._removeSigners is enough to track weights here.

_validateReachableThreshold(address account)

internal

#

Override to validate threshold against total weight instead of signer count.

NOTE: This function intentionally does not call super._validateReachableThreshold because the base implementation assumes each signer has a weight of 1, which is a subset of this weighted implementation. Consider that multiple implementations of this function may exist in the contract, so important side effects may be missed depending on the linearization order.

_validateThreshold(address account, bytes[] validatingSigners) → bool

internal

#

Validates that the total weight of signers meets the ERC7579Multisig.threshold requirement. Overrides the base implementation to use weights instead of count.

NOTE: This function intentionally does not call super._validateThreshold because the base implementation assumes each signer has a weight of 1, which is incompatible with this weighted implementation.

ERC7579MultisigWeightChanged(address indexed account, bytes indexed signer, uint64 weight)

event

#

Emitted when a signer's weight is changed.

NOTE: Not emitted in ERC7579Multisig._addSigners or ERC7579Multisig._removeSigners. Indexers must rely on ERC7579Multisig.ERC7913SignerAdded and ERC7579Multisig.ERC7913SignerRemoved to index a default weight of 1. See ERC7579MultisigWeighted.signerWeight.

ERC7579MultisigInvalidWeight(bytes signer, uint64 weight)

error

#

Thrown when a signer's weight is invalid.

ERC7579MultisigMismatchedLength()

error

#

Thrown when the arrays lengths don't match.

import "@openzeppelin/contracts/account/modules/ERC7579SelectorExecutor.sol";

Implementation of an ERC7579Executor that allows authorizing specific function selectors that can be executed on the account.

This module provides a way to restrict which functions can be executed on the account by maintaining a set of allowed function selectors. Only calls to functions with selectors in the set will be allowed to execute.

isAuthorized(address account, bytes4 selector) → bool

public

#

selectors(address account) → bytes4[]

public

#

Returns the set of authorized selectors for the specified account.

This operation copies the entire selectors set to memory, which

can be expensive or may result in unbounded computation.

onInstall(bytes initData)

public

#

Sets up the module's initial configuration when installed by an account. The initData should be encoded as: abi.encode(bytes4[] selectors)

onUninstall(bytes)

public

#

Cleans up module's configuration when uninstalled from an account. Clears all selectors.

This function has unbounded gas costs and may become uncallable if the set grows too large.

See EnumerableSetExtended.clear.

addSelectors(bytes4[] newSelectors)

public

#

Adds selectors to the set for the calling account

removeSelectors(bytes4[] oldSelectors)

public

#

Removes a selector from the set for the calling account

_addSelectors(address account, bytes4[] newSelectors)

internal

#

Internal version of ERC7579SelectorExecutor.addSelectors that takes an account as argument

_removeSelectors(address account, bytes4[] oldSelectors)

internal

#

Internal version of ERC7579SelectorExecutor.removeSelectors that takes an account as argument

_validateExecution(address account, bytes32, bytes32, bytes data) → bytes

internal

#

See ERC7579Executor._validateExecution. Validates that the selector (first 4 bytes of the actual callData) is authorized before execution.

ERC7579ExecutorSelectorAuthorized(address indexed account, bytes4 selector)

event

#

Emitted when a selector is added to the set

ERC7579ExecutorSelectorRemoved(address indexed account, bytes4 selector)

event

#

Emitted when a selector is removed from the set

ERC7579ExecutorSelectorNotAuthorized(bytes4 selector)

error

#

Error thrown when attempting to execute a non-authorized selector

import "@openzeppelin/contracts/account/modules/ERC7579Signature.sol";

Implementation of ERC7579Validator module using ERC-7913 signature verification.

This validator allows ERC-7579 accounts to integrate with address-less cryptographic keys and account signatures through the ERC-7913 signature verification system. Each account can store its own ERC-7913 formatted signer (a concatenation of a verifier address and a key: verifier || key).

This enables accounts to use signature schemes without requiring each key to have its own Ethereum address.A smart account with this module installed can keep an emergency key as a backup.

signer(address account) → bytes

public

#

Return the ERC-7913 signer (i.e. verifier || key).

onInstall(bytes data)

public

#

See IERC7579Module-onInstall.

NOTE: An account can only call onInstall once. If called directly by the account, the signer will be set to the provided data. Future installations will behave as a no-op.

onUninstall(bytes)

public

#

See IERC7579Module-onUninstall.

The signer's key will be removed if the account calls this function, potentially

making the account unusable. As an account operator, make sure to uninstall to a predefined path in your account that properly handles side effects of uninstallation. See AccountERC7579-uninstallModule.

setSigner(bytes signer_)

public

#

Sets the ERC-7913 signer (i.e. verifier || key) for the calling account.

setSigner(address account, bytes signer)

internal

#

Internal version of ERC7579Signature.setSigner that takes an account as argument without validating signer_.

_rawERC7579Validation(address account, bytes32 hash, bytes signature) → bool

internal

#

See ERC7579Validator._rawERC7579Validation.

Validates a signature using ERC-7913 verification.

This base implementation ignores the sender parameter and validates using the account's stored signer. Derived contracts can override this to implement custom validation logic based on the sender.

ERC7579SignatureSignerSet(address indexed account, bytes signer)

event

#

Emitted when the signer is set.

ERC7579SignatureInvalidSignerLength()

error

#

Thrown when the signer length is less than 20 bytes.

import "@openzeppelin/contracts/account/modules/ERC7579Validator.sol";

Abstract validator module for ERC-7579 accounts.

This contract provides the base implementation for signature validation in ERC-7579 accounts. Developers must implement the onInstall, onUninstall, and ERC7579Multisig._rawERC7579Validation functions in derived contracts to define the specific signature validation logic.

Example usage:

contract MyValidatorModule is ERC7579Validator {
    function onInstall(bytes calldata data) public {
        // Install logic here
    }

    function onUninstall(bytes calldata data) public {
        // Uninstall logic here
    }

    function _rawERC7579Validation(
        address account,
        bytes32 hash,
        bytes calldata signature
    ) internal view override returns (bool) {
        // Signature validation logic here
    }
}

Developers can restrict other operations by using the internal ERC7579Multisig._rawERC7579Validation. Example usage:

function execute(
    address account,
    Mode mode,
    bytes calldata executionCalldata,
    bytes32 salt,
    bytes calldata signature
) public virtual {
    require(_rawERC7579Validation(account, hash, signature));
    // ... rest of execute logic
}

isModuleType(uint256 moduleTypeId) → bool

public

#

Returns boolean value if module is a certain type

validateUserOp(struct PackedUserOperation userOp, bytes32 userOpHash) → uint256

public

#

Validates a UserOperation

isValidSignatureWithSender(address, bytes32 hash, bytes signature) → bytes4

public

#

See IERC7579Validator-isValidSignatureWithSender.

Ignores the sender parameter and validates using ERC7579Multisig._rawERC7579Validation. Consider overriding this function to implement custom validation logic based on the original sender.

_rawERC7579Validation(address account, bytes32 hash, bytes signature) → bool

internal

#

Validation algorithm.

Validation is a critical security function. Implementations must carefully

handle cryptographic verification to prevent unauthorized access.

import "@openzeppelin/contracts/account/paymaster/PaymasterCore.sol";

A simple ERC4337 paymaster implementation. This base implementation only includes the minimal logic to validate and pay for user operations.

Developers must implement the PaymasterCore._validatePaymasterUserOp function to define the paymaster's validation and payment logic. The context parameter is used to pass data between the validation and execution phases.

The paymaster includes support to call the IEntryPointStake interface to manage the paymaster's deposits and stakes through the internal functions PaymasterCore.deposit, PaymasterCore.withdraw, PaymasterCore.addStake, PaymasterCore.unlockStake and PaymasterCore.withdrawStake.

  • Deposits are used to pay for user operations.
  • Stakes are used to guarantee the paymaster's reputation and obtain more flexibility in accessing storage.

NOTE: See Paymaster's unstaked reputation rules  for more details on the paymaster's storage access limitations.

onlyEntryPoint()

internal

#

Revert if the caller is not the entry point.

onlyWithdrawer()

internal

#

entryPoint() → contract IEntryPoint

public

#

Canonical entry point for the account that forwards and validates user operations.

validatePaymasterUserOp(struct PackedUserOperation userOp, bytes32 userOpHash, uint256 maxCost) → bytes context, uint256 validationData

public

#

Validates whether the paymaster is willing to pay for the user operation. See IAccount-validateUserOp for additional information on the return value.

NOTE: Bundlers will reject this method if it modifies the state, unless it's whitelisted.

postOp(enum IPaymaster.PostOpMode mode, bytes context, uint256 actualGasCost, uint256 actualUserOpFeePerGas)

public

#

Verifies the sender is the entrypoint.

_validatePaymasterUserOp(struct PackedUserOperation userOp, bytes32 userOpHash, uint256 requiredPreFund) → bytes context, uint256 validationData

internal

#

Internal validation of whether the paymaster is willing to pay for the user operation. Returns the context to be passed to postOp and the validation data.

The requiredPreFund is the amount the paymaster has to pay (in native tokens). It's calculated as requiredGas * userOp.maxFeePerGas, where required gas can be calculated from the user operation as verificationGasLimit + callGasLimit + paymasterVerificationGasLimit + paymasterPostOpGasLimit + preVerificationGas

_postOp(enum IPaymaster.PostOpMode, bytes, uint256, uint256)

internal

#

Handles post user operation execution logic. The caller must be the entry point.

It receives the context returned by _validatePaymasterUserOp. Function is not called if no context is returned by PaymasterCore.validatePaymasterUserOp.

NOTE: The actualUserOpFeePerGas is not tx.gasprice. A user operation can be bundled with other transactions making the gas price of the user operation to differ.

deposit()

public

#

Calls IEntryPointStake-depositTo.

withdraw(address payable to, uint256 value)

public

#

Calls IEntryPointStake-withdrawTo.

addStake(uint32 unstakeDelaySec)

public

#

Calls IEntryPointStake-addStake.

unlockStake()

public

#

Calls IEntryPointStake-unlockStake.

withdrawStake(address payable to)

public

#

Calls IEntryPointStake-withdrawStake.

_checkEntryPoint()

internal

#

Ensures the caller is the entrypoint.

_authorizeWithdraw()

internal

#

Checks whether msg.sender withdraw funds stake or deposit from the entrypoint on paymaster's behalf.

Use of an access control modifier such as Ownable-onlyOwner is recommended.

function _authorizeUpgrade() internal onlyOwner {}

PaymasterUnauthorized(address sender)

error

#

Unauthorized call to the paymaster.

import "@openzeppelin/contracts/account/paymaster/PaymasterERC20.sol";

Extension of PaymasterCore that enables users to pay gas with ERC-20 tokens.

To enable this feature, developers must implement the PaymasterERC20._fetchDetails function:

function _fetchDetails(
    PackedUserOperation calldata userOp,
    bytes32 userOpHash
) internal view override returns (uint256 validationData, IERC20 token, uint256 tokenPrice) {
    // Implement logic to fetch the token, and token price from the userOp
}

The contract follows a pre-charge and refund model:

  1. During validation, it pre-charges the maximum possible gas cost
  2. After execution, it refunds any unused gas back to the user

_validatePaymasterUserOp(struct PackedUserOperation userOp, bytes32 userOpHash, uint256 maxCost) → bytes context, uint256 validationData

internal

#

See PaymasterCore._validatePaymasterUserOp.

Attempts to retrieve the token and tokenPrice from the user operation (see PaymasterERC20._fetchDetails) and prefund the user operation using these values and the maxCost argument (see PaymasterERC20._prefund).

Returns abi.encodePacked(userOpHash, token, tokenPrice, prefundAmount, prefunder, prefundContext) in context if the prefund is successful. Otherwise, it returns empty bytes.

prefund(struct PackedUserOperation userOp, bytes32, contract IERC20 token, uint256 tokenPrice, address prefunder, uint256 maxCost) → bool prefunded, uint256 prefundAmount, address prefunder, bytes prefundContext

internal

#

Prefunds the userOp by charging the maximum possible gas cost (maxCost) in ERC-20 token.

The token and tokenPrice is obtained from the PaymasterERC20._fetchDetails function and are funded by the prefunder_, which is the user operation sender by default. The prefundAmount is calculated using PaymasterERC20._erc20Cost.

Returns a prefundContext that's passed to the PaymasterCore._postOp function through its context return value.

NOTE: Consider not reverting if the prefund fails when overriding this function. This is to avoid reverting during the validation phase of the user operation, which may penalize the paymaster's reputation according to ERC-7562 validation rules.

_postOp(enum IPaymaster.PostOpMode, bytes context, uint256 actualGasCost, uint256 actualUserOpFeePerGas)

internal

#

Attempts to refund the user operation after execution. See PaymasterERC20._refund.

Reverts with PaymasterERC20.PaymasterERC20FailedRefund if the refund fails.

This function may revert after the user operation has been executed without

reverting the user operation itself. Consider implementing a mechanism to handle this case gracefully.

_refund(contract IERC20 token, uint256 tokenPrice, uint256 actualGasCost, uint256 actualUserOpFeePerGas, address prefunder, uint256 prefundAmount, bytes) → bool refunded, uint256 actualAmount

internal

#

Refunds any unused gas back to the user (i.e. prefundAmount - actualAmount) in token.

The actualAmount is calculated using PaymasterERC20._erc20Cost and the actualGasCost, actualUserOpFeePerGas, prefundContext and the tokenPrice from the PaymasterCore._postOp's context.

_fetchDetails(struct PackedUserOperation userOp, bytes32 userOpHash) → uint256 validationData, contract IERC20 token, uint256 tokenPrice

internal

#

Retrieves payment details for a user operation.

The values returned by this internal function are:

  • validationData: ERC-4337 validation data, indicating success/failure and optional time validity (validAfter, validUntil).
  • token: Address of the ERC-20 token used for payment to the paymaster.
  • tokenPrice: Price of the token in native currency, scaled by _tokenPriceDenominator().

==== Calculating the token price

Given gas fees are paid in native currency, developers can use the ERC20 price unit / native price unit ratio to calculate the price of an ERC20 token price in native currency. However, the token may have a different number of decimals than the native currency. For a a generalized formula considering prices in USD and decimals, consider using:

(<ERC-20 token price in $> / 10**<ERC-20 decimals>) / (<Native token price in $> / 1e18) * _tokenPriceDenominator()

For example, suppose token is USDC (1with6decimals)andnativecurrencyisETH(assuming1 with 6 decimals) and native currency is ETH (assuming 2524.86 with 18 decimals), then each unit (1e-6) of USDC is worth (1 / 1e6) / ((252486 / 1e2) / 1e18) = 396061563.8094785 wei. The _tokenPriceDenominator() ensures precision by avoiding fractional value loss. (i.e. the 0.8094785 part).

_postOpCost() → uint256

internal

#

Over-estimates the cost of the post-operation logic.

_tokenPriceDenominator() → uint256

internal

#

Denominator used for interpreting the tokenPrice returned by PaymasterERC20._fetchDetails as "fixed point" in PaymasterERC20._erc20Cost.

_erc20Cost(uint256 cost, uint256 feePerGas, uint256 tokenPrice) → uint256

internal

#

Calculates the cost of the user operation in ERC-20 tokens.

withdrawTokens(contract IERC20 token, address recipient, uint256 amount)

public

#

Public function that allows the withdrawer to extract ERC-20 tokens resulting from gas payments.

UserOperationSponsored(bytes32 indexed userOpHash, address indexed token, uint256 tokenAmount, uint256 tokenPrice)

event

#

Emitted when a user operation identified by userOpHash is sponsored by this paymaster using the specified ERC-20 token. The tokenAmount is the amount charged for the operation, and tokenPrice is the price of the token in native currency (e.g., ETH).

PaymasterERC20FailedRefund(contract IERC20 token, uint256 prefundAmount, uint256 actualAmount, bytes prefundContext)

error

#

Throws when the paymaster fails to refund the difference between the prefundAmount and the actualAmount of token.

import "@openzeppelin/contracts/account/paymaster/PaymasterERC20Guarantor.sol";

Extension of PaymasterERC20 that enables third parties to guarantee user operations.

This contract allows a guarantor to pre-fund user operations on behalf of users. The guarantor pays the maximum possible gas cost upfront, and after execution:

  1. If the user repays the guarantor, the guarantor gets their funds back
  2. If the user fails to repay, the guarantor absorbs the cost

A common use case is for guarantors to pay for the operations of users claiming airdrops. In this scenario:

  • The guarantor pays the gas fees upfront
  • The user claims their airdrop tokens
  • The user repays the guarantor from the claimed tokens
  • If the user fails to repay, the guarantor absorbs the cost

The guarantor is identified through the PaymasterERC20Guarantor._fetchGuarantor function, which must be implemented by developers to determine who can guarantee operations. This allows for flexible guarantor selection logic based on the specific requirements of the application.

prefund(struct PackedUserOperation userOp, bytes32 userOpHash, contract IERC20 token, uint256 tokenPrice, address prefunder, uint256 maxCost) → bool prefunded, uint256 prefundAmount, address prefunder, bytes prefundContext

internal

#

Prefunds the user operation using either the guarantor or the default prefunder. See PaymasterERC20._prefund.

Returns abi.encodePacked(..., userOp.sender) in prefundContext to allow the refund process to identify the user operation sender.

_refund(contract IERC20 token, uint256 tokenPrice, uint256 actualGasCost, uint256 actualUserOpFeePerGas, address prefunder, uint256 prefundAmount, bytes prefundContext) → bool refunded, uint256 actualAmount

internal

#

Handles the refund process for guaranteed operations.

If the operation was guaranteed, it attempts to get repayment from the user first and then refunds the guarantor. Otherwise, fallback to PaymasterERC20._refund.

NOTE: For guaranteed user operations where the user paid the actualGasCost back, this function doesn't call super._refund. Consider whether there are side effects in the parent contract that need to be executed.

_fetchGuarantor(struct PackedUserOperation userOp) → address guarantor

internal

#

Fetches the guarantor address and validation data from the user operation.

NOTE: Return address(0) to disable the guarantor feature. If supported, ensure explicit consent (e.g., signature verification) to prevent unauthorized use.

_guaranteedPostOpCost() → uint256

internal

#

Over-estimates the cost of the post-operation logic. Added on top of guaranteed userOps post-operation cost.

UserOperationGuaranteed(bytes32 indexed userOpHash, address indexed guarantor, uint256 prefundAmount)

event

#

Emitted when a user operation identified by userOpHash is guaranteed by a guarantor for prefundAmount.

import "@openzeppelin/contracts/account/paymaster/PaymasterERC721Owner.sol";

Extension of PaymasterCore that supports account based on ownership of an ERC-721 token.

This paymaster will sponsor user operations if the user has at least 1 token of the token specified during construction (or via PaymasterERC721Owner._setToken).

constructor(contract IERC721 token_)

internal

#

token() → contract IERC721

public

#

ERC-721 token used to validate the user operation.

setToken(contract IERC721 token)

internal

#

Sets the ERC-721 token used to validate the user operation.

_validatePaymasterUserOp(struct PackedUserOperation userOp, bytes32, uint256) → bytes context, uint256 validationData

internal

#

Internal validation of whether the paymaster is willing to pay for the user operation. Returns the context to be passed to postOp and the validation data.

NOTE: The default context is bytes(0). Developers that add a context when overriding this function MUST also override PaymasterCore._postOp to process the context passed along.

PaymasterERC721OwnerTokenSet(contract IERC721 token)

event

#

Emitted when the paymaster token is set.

import "@openzeppelin/contracts/account/paymaster/PaymasterSigner.sol";

Extension of PaymasterCore that adds signature validation. See SignerECDSA, SignerP256 or SignerRSA.

Example of usage:

contract MyPaymasterECDSASigner is PaymasterSigner, SignerECDSA {
    constructor(address signerAddr) EIP712("MyPaymasterECDSASigner", "1") SignerECDSA(signerAddr) {}
}

_signableUserOpHash(struct PackedUserOperation userOp, uint48 validAfter, uint48 validUntil) → bytes32

internal

#

Virtual function that returns the signable hash for a user operations. Given the userOpHash contains the paymasterAndData itself, it's not possible to sign that value directly. Instead, this function must be used to provide a custom mechanism to authorize an user operation.

_validatePaymasterUserOp(struct PackedUserOperation userOp, bytes32, uint256) → bytes context, uint256 validationData

internal

#

Internal validation of whether the paymaster is willing to pay for the user operation. Returns the context to be passed to postOp and the validation data.

NOTE: The context returned is bytes(0). Developers overriding this function MUST override PaymasterCore._postOp to process the context passed along.

_decodePaymasterUserOp(struct PackedUserOperation userOp) → uint48 validAfter, uint48 validUntil, bytes signature

internal

#

Decodes the user operation's data from paymasterAndData.

On this page

ModulesExecutorsValidatorsPaymasterERC7579DelayedExecutorERC7579ExecutorIERC7579ModuleERC7579ExecutorIERC7579ModuleERC7579ExecutorIERC7579ModuleERC7579ExecutorIERC7579ModuleIERC7579ModuleERC7579MultisigERC7579ValidatorIERC7579ValidatorIERC7579ModuleERC7579ValidatorIERC7579ValidatorIERC7579ModuleERC7579ValidatorIERC7579ValidatorIERC7579ModuleERC7579MultisigConfirmationEIP712IERC5267ERC7579MultisigERC7579ValidatorIERC7579ValidatorIERC7579ModuleEIP712IERC5267ERC7579MultisigERC7579ValidatorIERC7579ValidatorIERC7579ModuleEIP712IERC5267ERC7579MultisigERC7579ValidatorIERC7579ValidatorIERC7579ModuleERC7579MultisigStorageERC7579MultisigERC7579ValidatorIERC7579ValidatorIERC7579ModuleERC7579MultisigERC7579ValidatorIERC7579ValidatorIERC7579ModuleERC7579MultisigERC7579ValidatorIERC7579ValidatorIERC7579ModuleERC7579MultisigWeightedERC7579MultisigERC7579ValidatorIERC7579ValidatorIERC7579ModuleERC7579MultisigERC7579ValidatorIERC7579ValidatorIERC7579ModuleERC7579MultisigERC7579ValidatorIERC7579ValidatorIERC7579ModuleERC7579SelectorExecutorERC7579ExecutorIERC7579ModuleERC7579ExecutorIERC7579ModuleERC7579ExecutorIERC7579ModuleERC7579SignatureERC7579ValidatorIERC7579ValidatorIERC7579ModuleERC7579ValidatorIERC7579ValidatorIERC7579ModuleERC7579ValidatorIERC7579ValidatorIERC7579ModuleERC7579ValidatorIERC7579ValidatorIERC7579ModulePaymasterCoreIPaymasterIPaymasterPaymasterERC20PaymasterCoreIPaymasterPaymasterCoreIPaymasterPaymasterCoreIPaymasterPaymasterERC20GuarantorPaymasterERC20PaymasterCoreIPaymasterPaymasterERC20PaymasterCoreIPaymasterPaymasterERC20PaymasterCoreIPaymasterPaymasterERC721OwnerPaymasterCoreIPaymasterPaymasterCoreIPaymasterPaymasterCoreIPaymasterPaymasterSignerPaymasterCoreIPaymasterEIP712IERC5267AbstractSignerPaymasterCoreIPaymasterEIP712IERC5267AbstractSignerPaymasterCoreIPaymasterEIP712IERC5267AbstractSigner