WhitelistPaymaster
Author: Lendefi Team
Sponsors gas for ERC-4337 UserOperations that target whitelisted contracts. Inherits from BasePaymaster (which provides Ownable and EntryPoint integration).
Overview
The WhitelistPaymaster is a permissioned gas sponsor for the Owl Smart Wallet system. It validates that a UserOperation's target contract is on the whitelist before agreeing to pay gas fees. This enables controlled gas sponsorship for AI agents interacting with approved protocols (e.g., DeFi lending, token swaps).
Key Features:
Whitelist-based target validation for
execute()andexecuteBatch()callsOptional wallet registry enforcement to ensure only valid wallets receive sponsorship
Gas tracking metrics for monitoring and analytics
Batch whitelist management for operational efficiency
Security Model:
Only owner can modify whitelist and registry settings
Critical: Only first-level call targets are validated. Do NOT whitelist contracts with arbitrary forwarding capabilities (multicall routers, generic proxies) as they would bypass target validation.
Agentic Context: AI agents submit UserOperations via the bundler relay. If the target contract (e.g., Morpho, Uniswap) is whitelisted, the paymaster sponsors gas, enabling gasless autonomous operation.
State Variables
whitelistedContracts
Mapping of approved target contracts that can receive sponsored transactions.
walletRegistry
Optional registry/factory contract used to validate that userOp.sender is a legitimate wallet.
enforceWalletRegistry
If true, requires userOp.sender to be validated against walletRegistry before sponsoring.
totalSponsoredTransactions
Counter of all sponsored transactions (for analytics).
totalGasSponsored
Cumulative gas cost sponsored (in wei).
EXECUTE_SELECTOR
Function selector for SmartWallet.execute(address,uint256,bytes).
EXECUTE_BATCH_SELECTOR
Function selector for SmartWallet.executeBatch((address,uint256,bytes)[]).
Functions
Constructor
Initializes the paymaster with the ERC-4337 EntryPoint and owner address.
_entryPoint
IEntryPoint
ERC-4337 EntryPoint contract
_owner
address
Owner address (receives admin privileges)
Admin Functions
setWhitelistedContract
Add or remove a contract from the whitelist.
Access Control: onlyOwner
Security Warning: Only whitelist contracts you trust as direct call targets. Do NOT whitelist generic forwarding contracts (multicall, proxies, routers), as they enable attackers to bypass target validation.
contractAddress
address
Contract address to whitelist/unwhitelist
whitelisted
bool
true to whitelist, false to remove
Emits: ContractWhitelisted
setWhitelistedContractsBatch
Batch whitelist multiple contracts in a single transaction.
Access Control: onlyOwner
contractAddresses
address[]
Array of contract addresses
whitelisted
bool
true to whitelist all, false to remove all
Emits: ContractWhitelisted (once per address)
setWalletRegistry
Set the wallet registry/factory contract used to validate userOp.sender.
Set to address(0) to disable registry validation (also disables enforcement automatically).
Access Control: onlyOwner
newRegistry
address
Registry contract address (or address(0) to disable)
Emits: WalletRegistryUpdated
setEnforceWalletRegistry
Enable or disable wallet registry enforcement.
When enabled, walletRegistry must be set and all userOp.sender addresses must pass registry validation.
Access Control: onlyOwner
enforced
bool
true to enable enforcement, false to disable
Emits: WalletRegistryEnforcementUpdated
View Functions
isWhitelisted
Check if a contract address is whitelisted.
contractAddress
address
Address to check
Returns:
bool
true if whitelisted, false otherwise
Internal Functions
_validatePaymasterUserOp
Internal validation logic called by EntryPoint.
Validates the UserOperation before agreeing to sponsor gas. Checks:
userOp.senderis valid (if registry enforcement enabled)Target contract (extracted from calldata) is whitelisted
Function selector is
executeorexecuteBatch
Returns:
context
bytes
ABI-encoded (address user, address target) for _postOp
validationData
uint256
0 for valid, non-zero for invalid/expired
Reverts:
InvalidWallet(wallet)if registry enforcement enabled and wallet not validWalletRegistryNotSet()if enforcement enabled but registry isaddress(0)InvalidUserOperation()if calldata too short or selector invalidTargetNotWhitelisted(target)if target not whitelisted
_postOp
Internal post-operation hook called by EntryPoint.
Tracks gas usage metrics and emits TransactionSponsored event.
context
bytes
ABI-encoded (address user, address target) from validation
actualGasCost
uint256
Actual gas cost in wei
Emits: TransactionSponsored
Events
ContractWhitelisted
Emitted when a contract is added to or removed from the whitelist.
contractAddress
address
Contract address being whitelisted/unwhitelisted
whitelisted
bool
true if whitelisted, false if removed
TransactionSponsored
Emitted when a transaction is successfully sponsored.
user
address
Wallet address whose transaction was sponsored
target
address
Target contract of the sponsored call
actualGasCost
uint256
Gas cost in wei
WalletRegistryUpdated
Emitted when the wallet registry address is changed.
oldRegistry
address
Previous registry address
newRegistry
address
New registry address
WalletRegistryEnforcementUpdated
Emitted when wallet registry enforcement is enabled or disabled.
enforced
bool
true if enforcement enabled, false if disabled
Errors
TargetNotWhitelisted
Thrown when the target contract is not whitelisted.
InvalidUserOperation
Thrown when the UserOperation has invalid calldata or function selector.
ZeroAddress
Thrown when a zero address is provided where not allowed.
InvalidWallet
Thrown when wallet registry enforcement is enabled and the wallet is not valid.
WalletRegistryNotSet
Thrown when wallet registry enforcement is enabled but walletRegistry is address(0).
Integration Guide
For AI Agent Developers:
When submitting UserOperations via the bundler relay, ensure:
The target contract is whitelisted (check via
isWhitelisted())The wallet is valid (if registry enforcement is enabled)
The function is
execute()orexecuteBatch()
For Protocol Integrators:
To enable gas sponsorship for your protocol:
Request whitelist approval from the paymaster owner
Ensure your contract does not forward arbitrary calls
Test with a UserOperation before production use
For Auditors:
Critical validation points:
_validatePaymasterUserOpextracts target from calldata at fixed offsetsOnly first-level targets are validated (nested calls not checked)
Registry enforcement is optional but recommended for production
Last updated