Technical Dive: Gas Sponsorship
One innovation in the blockchain space is EIP-4337, a standard for account abstraction on the EVM ecosystem. In this document, we will delve into the Paymaster component of EIP-4337 and its functionality within the framework.
Understanding Gas Sponsorship: The Paymaster
Paymasters, or "gas sponsors," in EIP-4337 are smart contracts that enable transaction sponsorship through third-party-designed mechanisms. Often referred to as gasless transactions, paymasters eliminate the need for users to hold a blockchain's native token for transaction fees. This creates opportunities for transaction fee sponsorship or accepting network fees in ERC20 tokens.
The Gas Sponsorship concept in EIP-4337 empowers contracts to pay on users' behalf under any given conditions, unlocking a new realm of possibilities for transaction sponsorship mechanisms on EVM blockchains.
Let's explore the four major steps involved in this process.
Step 1: Deposit into the Entry Point
The paymaster deposits ETH (or the corresponding blockchain's native token) into the Entry Point, which is the contract responsible for validating and executing ERC-4337 operations.
Step 2: Verification of User Operation
When the Entry Point receives a user operation with a nonzero
paymasterAndData field, it calls the
verifyUserOp() function on the corresponding paymaster contract.
Step 3: Approval and Gas Fee Coverage
The paymaster contract returns approval along with validation data and context. The Entry Point then uses the paymaster's deposit to cover the gas fee for the transaction.
Step 4: Post-Execution Function
If the Paymaster returned information in the context object, a
postOp() function is executed after the transaction is completed.
The Power of Sponsoring Transactions
Paymasters can generally be categorized into two types: those with on-chain logic and those with off-chain logic (note that further combinations will be possible in the future).
- Off-Chain Paymasters: Verifying Paymasters
When the logic is off-chain, the paymaster is called a Verifying Paymaster. An off-chain service decides whether to sponsor the transaction and returns a signature. The paymaster trusts an external signer to sign the transaction. The calling user must pass the UserOp to that external signer first, which performs whatever off-chain verification before signing the UserOp. If the signature is valid, the paymaster will cover the transaction costs.
- On-Chain Paymasters: Deposit Paymasters
Can I enable my users to pay gas with the game token directly? YES!
Deposit Paymasters typically use an oracle to charge users ERC20 tokens for gas and pull tokens from the user's account. The user must make an initial token deposit (which requires gas) and can only send transactions to the whitelisted paymasters by the bundler. The Gas Sponsor contract checks for sufficient approved ERC20 balance in the
validatePaymasterUserOp() method and extracts it using
transferFrom() in the
If a user alters their behavior post-block confirmation, EIP-4337's inner
postOp() fails and reverts the execution, while the outer
postOp() extracts the payment. This mitigates the risk of malicious users.
If you have more questions/ideas/queries, join our Developer Discord and let us know there. Furthermore, you can follow us on Twitter for our updates as we keep shipping.