pzza.works

Understanding Paymasters: Building Gas Abstraction on zkSync

Berke (pzzaworks)Berke (pzzaworks)

March 30th, 2025

I've built several Paymasters and worked with zkSync's native account abstraction, and I've watched them change how a blockchain app feels to the person using it. In this post I'll go through what Paymasters are, how they work on zkSync, and why I think they matter so much for Web3 adoption.

What Are Paymasters?

At their core, Paymasters are smart contracts that enable gas abstraction: they let someone other than the transaction sender pay the fee. The idea was popularized by EIP-4337 (Account Abstraction via Entry Point Contract), and it goes after one of the biggest points of friction for new users, which is that they have to own the native token (like ETH) before they can touch any application at all.

Once someone else can pay, a lot of models open up. A Paymaster can sponsor a user's transactions completely. It can accept alternative tokens as payment for gas. It can sponsor conditionally, based on whatever logic you write into it. And it can turn gas into a subscription or a membership perk instead of a per-transaction cost.

Why zkSync's Native Account Abstraction Matters

EIP-4337 brings account abstraction to Ethereum as a smart contract implementation. zkSync instead built it directly into the protocol layer, and that changes a few things. Native AA is more gas-efficient than the contract-based alternatives, and the implementation is cleaner, with less boilerplate. Because it is part of the core protocol, there are fewer places for vulnerabilities to hide. And execution takes a direct path, without an extra verification layer sitting on top.

The Architecture of a zkSync Paymaster

On zkSync, Paymasters implement the IPaymaster interface, which includes these key methods:

Solidity
function validateAndPayForPaymasterTransaction( bytes32 _txHash, bytes32 _suggestedSignedHash, Transaction calldata _transaction ) external payable returns (bytes memory context); function postTransaction( bytes calldata _context, Transaction calldata _transaction, bytes32 _txHash, bytes32 _suggestedSignedHash, ExecutionResult _txResult, uint256 _maxRefundedGas ) external payable;

The first function validates the transaction and pays for it. The second runs after execution and handles the follow-up logic, including refunds.

Building My First zkSync Paymaster

My first Paymaster on zkSync used the ERC-20 payment model, which lets users pay for gas with any ERC-20 token instead of ETH. Simplified, the flow goes like this. The user starts a transaction with their preferred token. The Paymaster estimates the gas cost in ETH and works out the equivalent ERC-20 amount, plus a fee. The user approves the Paymaster to spend that many tokens, the Paymaster checks the approval and pays the ETH for gas, and once the transaction has executed, it transfers the tokens from the user.

What I like about this approach is that users never need to hold ETH. They can operate entirely in ERC-20 tokens.

Advanced Paymaster Patterns I've Implemented

Past the basic ERC-20 Paymaster, I've experimented with a couple of more involved designs.

Conditional Sponsorship Paymaster

This Paymaster only sponsors transactions that meet specific criteria. One I built pays for a user's first 5 interactions with a specific dApp, which works well for onboarding new users.

Solidity
function validateAndPayForPaymasterTransaction( bytes32 _txHash, bytes32 _suggestedSignedHash, Transaction calldata _transaction ) external payable returns (bytes memory context) { // Extract user address from transaction address user = _transaction.from; // Check if the user has performed fewer than 5 transactions uint256 userTransactionCount = transactionCounts[user]; require(userTransactionCount < 5, "Sponsorship limit reached"); // Increment the counter transactionCounts[user] = userTransactionCount + 1; // Return context for post-processing return abi.encode(user, userTransactionCount); }

Subscription-Based Paymaster

Another model I implemented was a subscription service: users pay a monthly fee and all their transactions are covered. Their costs become predictable, and they stop having to think about gas on every single transaction.

Challenges and Optimizations

Building Paymasters that hold up is not trivial, and I ran into a few problems along the way.

Gas estimation comes first. Getting the cost right is crucial and surprisingly tricky, and I found that adding a 10-15% buffer works well for most applications. Then there is denial of service: a contract that pays for other people's transactions is an obvious target, so I added rate limiting and per-user caps. Closely related is economic security. The Paymaster has to stay solvent and must not be drainable, which takes careful economic modeling, so I built a treasury monitoring system that pauses the Paymaster automatically when reserves get too low.

Finally, integration testing. You can't test a Paymaster properly in isolation; you have to simulate the whole transaction flow. I put together a full test suite for that using zkSync's testing libraries.

The Future of Paymasters and Account Abstraction

There are a few directions I expect the ecosystem to go. Cross-chain Paymasters would let users pay for a transaction on one chain with tokens from another. Intent-based Paymasters would pay based on what the user is trying to do rather than the specific function calls involved. Social recovery Paymasters would combine account recovery with gas abstraction into one user security model. And DAO-governed Paymasters would put the community in charge of which transactions get sponsored, decided by governance votes.

Conclusion

Paymasters on zkSync are a real step forward for blockchain UX. Taking gas fees out of the user's way removes a major barrier to adoption and makes room for new business models.

Having built and deployed these systems in production, I'm curious to see what the community builds on top of them. If you want to improve your dApp's user experience, implementing a Paymaster should be high on your list.

Feel free to reach out if you have questions about implementing Paymasters in your own projects. I'm always happy to share more technical details from my experience.

Keep reading

  • Broadcasters & The RAILGUN Ecosystem: Gasless Private Transactions

    We've covered how RAILGUN provides privacy through shielding, how zero-knowledge proofs make it possible, and how PPOI maintains compliance. But there's a practical problem we haven't addressed: how do you submit a private transaction to the blockchain without revealing who you are?

  • Ethereum 2025-2026 Privacy Roadmap: The Dawn of Private Infrastructure

    For years, privacy on Ethereum was an afterthought, something left to third-party protocols and layer-2 solutions. That changed in September 2025. The Ethereum Foundation made privacy an official part of the roadmap through the Privacy Stewards of Ethereum (PSE) initiative.

  • Titan: Building a DeFi Super App

    A technical deep dive into Titan - a complete DeFi protocol featuring token swaps, concentrated liquidity, liquid staking with sTITAN, overcollateralized lending with tUSD, and snapshot-based on-chain governance.