[web3] Zapper Arbitrary Call Data Bug Fix Postmortem. This is a postmortem of a vulnerability… | by Immunefi | Oct, 2021 | Medium
The Zapper 'zap out' contracts accepted arbitrary call data from users without validation, allowing an attacker to call transferFrom and steal LP tokens from any victim who had approved the contract. The attacker could steal LP tokens on an ongoing basis.
medium.com
Published on medium.com
Zapper
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
Zapper operates a set of smart contracts that let users enter and exit Uniswap and Sushiswap liquidity pools. The "zap in" contracts help a user obtain a position in an LP; the "zap out" contracts help a user withdraw liquidity from a pool. To do that work, the contracts must be approved by the user to transfer LP tokens on the user's behalf.
Two zap out contracts are named in the report, one for each exchange:
| Exchange | Contract address |
|---|---|
| Uniswap | [redacted] |
| Sushiswap | [redacted] |
Both contained functions, ZapOutWithPermit and ZapOut2PairTokenWithPermit, that let the caller specify an arbitrary call to any liquidity pool with arbitrary data. The purpose of that call was to obtain permission to transfer funds from the user.
Setup
The precondition for the attack is the normal operating state of the product: the victim has previously approved the Zapper contract to move their LP tokens. Because users are expected to approve the contract in order to use zap out, anyone submitting transactions to "Zap Out" was a potential victim. No other setup is described in the report.
The finder was Lucash-dev, a recipient of the Immunefi Whitehat Scholarship. The vulnerability was found on June 9.
Finding it
The weakness is in how the permit-style functions handle their input. The functions accept a target pool and calldata for a call made against it, and the contract performs that call in order to obtain the permission to transfer the user's funds. The report states plainly that there was no validation of the data provided by the user for that call. That absence is what made the arbitrary calldata dangerous: the contract would execute whatever call data it was handed, in the context of its own approvals.

Exploitation
Step 1: prepare the malicious calldata
An attacker could ABI-encode a call to transferFrom and supply it as the arbitrary call data to the vulnerable permit function. Because the data is not validated, the contract treats it as the call it should make against the pool.
Step 2: let the contract move the tokens
The contract executes the call. Since the victim has approved the Zapper contract, the transferFrom would succeed and move the victim's LP tokens to the attacker. The report describes the result as the contract being forced to transfer all LP tokens from any victim to the attacker.
Step 3: repeat
The report says the flaw would have allowed a malicious user to steal LP tokens on an ongoing basis, not just once.
The report refers to a proof of concept for this attack but does not reproduce its contents.
Root cause
The zap out contracts accepted user-supplied calldata for a call to an arbitrary liquidity pool and did not validate it. The call exists so the contract can obtain permission to transfer the user's funds, and the contract holds the user's approval, so any call data the user supplies is executed with that authority. Encoding transferFrom turns the permit step into a token transfer from the victim to the attacker. The approval the product depends on is exactly the authority the injected call abuses.
Impact
A malicious user could have stolen LP tokens from any victim who had approved the Zapper contract, on an ongoing basis. The only requirement is that prior approval. Because approval is the expected state for anyone using zap out, the pool of potential victims is every user submitting zap out transactions. The report rates the vulnerability critical.
Fix
Zapper paused its contracts using the toggleContractActive() function, which prevents the vulnerable function from being called, and issued a fix within 24 hours. The fix blocked the previously vulnerable function from accepting arbitrary calldata. According to Zapper's postmortem, parameters for the permit call will in future be computed on-chain. Zapper paid Lucash-dev a bounty of $25,000.
Variants to test
- Permit-style entry points that take a target address and calldata from the caller. A positive result is a call that reaches a token's
transferFromorapproveand moves value the caller does not own. - Functions that perform a call in order to obtain an approval, where the calldata is only checked for shape and not for the selector or arguments. A positive result is any selector other than the intended permit selector being executed.
- Contracts holding standing user approvals for LP or other tokens, where any user-controlled call is made against a pool. A positive result is a transfer out of a victim's balance using only the contract's existing allowance.
- Repeatability: after a first successful injected call, check whether the same path can be used again against other approvers. A positive result is a second victim drained without any new approval.
What happened, in plain words
Zapper is a website and set of programs that help people put money into and take money out of cryptocurrency trading pools. Those pools are called Uniswap and Sushiswap liquidity pools. To move a user's funds around, Zapper's programs need the user's permission in advance. That permission is a standing instruction: "you may move my pool tokens for me when I ask."
A security researcher who goes by the name Lucash-dev found a serious flaw in two of Zapper's programs. The flaw would have let anyone who had given Zapper that permission have their pool tokens taken by someone else. The attacker did not need a password or a stolen key. They only needed the victim to have used Zapper normally, which is exactly what the product asks people to do.
The researcher reported the problem on June 9, 2021. Zapper switched the affected programs off, fixed them within 24 hours, and paid the researcher a $25,000 reward. This article walks through what went wrong, step by step, for readers who have never studied security before.
Background: the pieces involved
Before the flaw makes sense, a few everyday ideas need explaining.
- Smart contract: a small program that lives on a blockchain (a shared, public record of transactions). Once deployed, it runs exactly as written and anyone can send it instructions. Think of it as a vending machine: it does one job, it is visible to everyone, and it does not care who presses the buttons.
- Token: a digital unit of value tracked by a smart contract. Here the tokens are LP tokens, which represent a share of a liquidity pool.
- Liquidity pool: a shared pot of two cryptocurrencies that people trade against. If you add money to the pot, you get LP tokens as a receipt for your share. If you take your money out, you hand the LP tokens back.
- Approve / allowance: a standard permission in this ecosystem. A user tells a token contract, "this other contract may move up to X of my tokens." The other contract can then move them without asking again. It is like a standing direct debit at a bank: you authorise it once, and afterwards the payee can take the money.
- Calldata: the raw instructions sent to a smart contract, encoded as bytes. It says which function to run and with which arguments. Think of it as the filled-in form you feed into the vending machine.
- ABI encoding: the standard way of packing a function name and its arguments into those bytes so the contract can read them.
transferFrom: a standard token function meaning "move tokens from address A to address B, using the allowance A gave me."- Permit: a pattern where a contract makes a call in order to obtain the user's permission to move funds, rather than relying on a separate approval step.
The product and the feature
Zapper runs two families of contracts. The zap in contracts help a user obtain a position in a Uniswap or Sushiswap liquidity pool. The zap out contracts help a user withdraw liquidity from a pool. To do that work, the contracts must be approved by the user to transfer LP tokens on the user's behalf.
Two zap out contracts are named in the report, one for each exchange:
| Exchange | Contract address |
|---|---|
| Uniswap | [redacted] |
| Sushiswap | [redacted] |
Both contained functions, ZapOutWithPermit and ZapOut2PairTokenWithPermit, that let the caller specify an arbitrary call to any liquidity pool with arbitrary data. The purpose of that call was to obtain permission to transfer funds from the user.
In plain words: when you use zap out, you hand the Zapper contract a little package of instructions. Zapper passes that package on to the pool, so the pool will grant Zapper the right to move your LP tokens. The contract does not check what is inside the package. It just forwards it.
Setup: what had to be true before the attack worked
The precondition for the attack is the normal operating state of the product: the victim has previously approved the Zapper contract to move their LP tokens. Because users are expected to approve the contract in order to use zap out, anyone submitting transactions to "Zap Out" was a potential victim. No other setup is described in the report.
The finder was Lucash-dev, a recipient of the Immunefi Whitehat Scholarship. The vulnerability was found on June 9.
Why this matters: the attack did not require the victim to make a mistake. Using the product as designed was enough. That is what makes a flaw like this severe.
Finding it: where the weakness lives
The weakness is in how the permit-style functions handle their input. The functions accept a target pool and calldata for a call made against it, and the contract performs that call in order to obtain the permission to transfer the user's funds. The report states plainly that there was no validation of the data provided by the user for that call. That absence is what made the arbitrary calldata dangerous: the contract would execute whatever call data it was handed, in the context of its own approvals.
Put simply: the contract is trusted by the token. It holds your permission. So anything it is told to do with that permission, it can do. If the instructions come from an attacker instead of from you, the attacker is effectively borrowing the contract's authority.

The image above is from the bugfix review, published on June 16, 2021.
Exploitation: how the theft worked
Step 1: prepare the malicious calldata
An attacker could ABI-encode a call to transferFrom and supply it as the arbitrary call data to the vulnerable permit function. Because the data is not validated, the contract treats it as the call it should make against the pool.
In everyday terms: the attacker fills in the form with "move tokens from the victim to me" instead of the harmless permission request the contract expected. The contract does not read the form, so it does not notice the swap.
Step 2: let the contract move the tokens
The contract executes the call. Since the victim has approved the Zapper contract, the transferFrom would succeed and move the victim's LP tokens to the attacker. The report describes the result as the contract being forced to transfer all LP tokens from any victim to the attacker.
Why it succeeds: the token contract sees a request coming from Zapper, which the victim has already authorised. From the token's point of view, nothing unusual has happened.
Step 3: repeat
The report says the flaw would have allowed a malicious user to steal LP tokens on an ongoing basis, not just once.
Why repeatability matters: a one-off theft is bad, but a method that works against every user who has approved the contract, again and again, is far worse. The report refers to a proof of concept for this attack but does not reproduce its contents.
Root cause: the one-line version
The zap out contracts accepted user-supplied calldata for a call to an arbitrary liquidity pool and did not validate it. The call exists so the contract can obtain permission to transfer the user's funds, and the contract holds the user's approval, so any call data the user supplies is executed with that authority. Encoding transferFrom turns the permit step into a token transfer from the victim to the attacker. The approval the product depends on is exactly the authority the injected call abuses.
A useful comparison: a hotel receptionist has a master key and is told to open whichever room a guest names. If the guest names someone else's room, the receptionist opens it, because the instruction was never checked against the guest's identity.
Impact: who could be hurt
A malicious user could have stolen LP tokens from any victim who had approved the Zapper contract, on an ongoing basis. The only requirement is that prior approval. Because approval is the expected state for anyone using zap out, the pool of potential victims is every user submitting zap out transactions. The report rates the vulnerability critical.
Fix: what Zapper did
Zapper paused its contracts using the toggleContractActive() function, which prevents the vulnerable function from being called, and issued a fix within 24 hours. The fix blocked the previously vulnerable function from accepting arbitrary calldata. According to Zapper's postmortem, parameters for the permit call will in future be computed on-chain. Zapper paid Lucash-dev a bounty of $25,000.
In plain words: the emergency switch was flipped so nobody could use the broken function while it was being repaired. The repair removed the ability to hand the contract free-form instructions. In future, the contract will work out those instructions itself rather than trusting the caller to supply them.
Variants to test: where else this pattern might appear
If you are learning to look for this kind of bug, these are the places to check. Each is a variation on the same theme: a contract that holds a user's permission and then runs instructions supplied by someone else.
- Permit-style entry points that take a target address and calldata from the caller. A positive result is a call that reaches a token's
transferFromorapproveand moves value the caller does not own. - Functions that perform a call in order to obtain an approval, where the calldata is only checked for shape and not for the selector or arguments. A positive result is any selector other than the intended permit selector being executed.
- Contracts holding standing user approvals for LP or other tokens, where any user-controlled call is made against a pool. A positive result is a transfer out of a victim's balance using only the contract's existing allowance.
- Repeatability: after a first successful injected call, check whether the same path can be used again against other approvers. A positive result is a second victim drained without any new approval.
Glossary
- ABI encoding: the standard way of packing a function name and its arguments into raw bytes that a smart contract can read.
- Allowance: a standing permission a token holder gives to another contract to move a set amount of their tokens.
- Approve: the token function that creates an allowance.
- Blockchain: a shared, public record of transactions that many computers maintain together.
- Bounty: a reward paid to a researcher who reports a security flaw responsibly.
- Calldata: the raw bytes sent to a smart contract, saying which function to run and with which arguments.
- Critical: the highest severity rating, meaning the flaw can cause serious loss and should be fixed immediately.
- Immunefi: the bug bounty platform where the report was handled and the reward was arranged.
- LP token: a token representing a share of a liquidity pool.
- Permit: a pattern where a contract makes a call in order to obtain the user's permission to move funds.
- Proof of concept: a demonstration, usually code, showing that an attack actually works.
- Selector: the short identifier at the start of calldata that says which function is being called.
- Smart contract: a program on a blockchain that runs exactly as written and can be called by anyone.
toggleContractActive(): the function Zapper used to pause its contracts.transferFrom: a standard token function that moves tokens from one address to another using an existing allowance.- Validation: checking that input is what it is supposed to be before acting on it.
- Whitehat: a security researcher who finds flaws and reports them to the owner rather than exploiting them.
- Whitehat Scholarship: an Immunefi programme that supports researchers starting out in this field.
- Zap in: Zapper's feature for obtaining a position in a liquidity pool.
- Zap out: Zapper's feature for withdrawing liquidity from a pool.