Put option sellers can prevent exercise by specifying zero amounts, or non-existant tokens
A put option seller could include a zero amount or a non-existent token in the order's ERC20 asset list, causing the buyer's exercise transaction to revert. The buyer would then be unable to exercise the option and would lose the premium paid.
Submitted by IllIllI, also found by 0xNineDec, exd0tpy, and zzzitron
Put option buyers pay an option premium to the seller for the privilege of being able to ‘put’ assets to the seller and get the strike price for it rather than the current market price. If they’re unable to perform the ‘put’, they’ve paid the premium for nothing, and essentially have had funds stolen from them.
Proof of Concept
If the put option seller includes in order.erc20Assets, an amount of zero for any of the assets, or specifies an asset that doesn’t currently have any code at its address, the put buyer will be unable to exercise the option, and will have paid the premium for nothing:
File: contracts/src/PuttyV2.sol #1
453 // transfer assets from exerciser to putty
454 _transferERC20sIn(order.erc20Assets, msg.sender);
The function reverts if any amount is equal to zero, or the asset doesn’t exist:
File: contracts/src/PuttyV2.sol #2
593 function _transferERC20sIn(ERC20Asset[] memory assets, address from) internal {
594 for (uint256 i = 0; i < assets.length; i++) {
595 address token = assets[i].token;
596 uint256 tokenAmount = assets[i].tokenAmount;
597
598 require(token.code.length > 0, "ERC20: Token is not contract");
599 require(tokenAmount > 0, "ERC20: Amount too small");
600
601 ERC20(token).safeTransferFrom(from, address(this), tokenAmount);
602 }
603 }
Recommended Mitigation Steps
Verify the asset amounts and addresses during fillOrder(), and allow exercise if the token no longer exists at that point in time.
outdoteth (Putty Finance) confirmed and commented:
At the contract level there exists 2 possible mitigations;
- Remove the zero amount check (not feasible because it will cause another DOS issue for tokens that revert on 0 transfer).
- Check all erc20 assets are valid in
fillOrder(gas tradeoff because it requires an O(n) loop to check).Instead, the best mitigation imo is to add a check on the frontend/db level to ensure that all erc20 assets have a token amount greater than 0 and that it exists as a contract.
If users want to go lower level than the db/frontend then they must exercise their own diligence.
edit: decided to go with a 3rd option instead.
Simply skip the ERC20 transfer if the amount is 0.
Report: Setting an erc20Asset with a zero amount or with no code at the address will result in a revert when exercising a put option.
outdoteth (Putty Finance) resolved:
PR with fix: https://github.com/outdoteth/putty-v2/pull/8.
hyh (warden) reviewed mitigation:
Fixed zero amount part by introducing the noop for zero amount transfers in both
_transferERC20sInand_transferERC20sOutERC20 transfer functions. The second part of the issue, fake tokens, is similar to M-01, M-02.
Context
Putty is an on-chain options protocol. A put option buyer pays a premium to the seller for the right to "put" assets to the seller and receive the strike price instead of the current market price. The exercise path is what makes the premium worth paying: if the buyer cannot perform the put, the premium has bought nothing.
This finding concerns the exercise flow in PuttyV2.sol, specifically the step where the exerciser's ERC20 assets are pulled into the contract. The report was submitted to the Code4rena audit contest for Putty and rated medium.
Setup
The issue is a logic flaw in the contract, so no special accounts, tooling or configuration are needed to reason about it. The relevant preconditions are on the order itself:
- The order is a put option, so the buyer (exerciser) transfers
order.erc20Assetsto the contract when exercising. - The seller can include an entry in
order.erc20Assetswhose amount is zero, or whose token address has no code at the time of exercise. - The seller can include an entry whose amount is zero, or whose token address has no code at the time of exercise.
Finding it
The researcher looked at the exercise path and at the helper that moves the exerciser's ERC20s in. The exercise code calls that helper directly:
File: contracts/src/PuttyV2.sol #1
453 // transfer assets from exerciser to putty
454 _transferERC20sIn(order.erc20Assets, msg.sender);
The helper enforces two conditions per asset, and either one reverts the whole exercise:
File: contracts/src/PuttyV2.sol #2
593 function _transferERC20sIn(ERC20Asset[] memory assets, address from) internal {
594 for (uint256 i = 0; i < assets.length; i++) {
595 address token = assets[i].token;
596 uint256 tokenAmount = assets[i].tokenAmount;
597
598 require(token.code.length > 0, "ERC20: Token is not contract");
599 require(tokenAmount > 0, "ERC20: Amount too small");
600
601 ERC20(token).safeTransferFrom(from, address(this), tokenAmount);
602 }
603 }
Because the loop runs over every entry in order.erc20Assets, a single bad entry is enough. A zero amount trips require(tokenAmount > 0, "ERC20: Amount too small"), and an address with no code trips require(token.code.length > 0, "ERC20: Token is not contract"). In both cases the exercise reverts, and the buyer has already paid the premium.
Exploitation
Step 1: the seller creates a put order with a poisoned asset entry
The seller includes in order.erc20Assets either an amount of zero for one of the assets, or an asset address that currently has no code.
Step 2: the buyer pays the premium
The buyer purchases the put option in the normal way. The premium is now with the seller.
Step 3: the buyer tries to exercise
Exercise reaches line 454 and calls _transferERC20sIn(order.erc20Assets, msg.sender). The loop hits the poisoned entry and reverts on one of the two require statements shown above. The buyer cannot put the assets and cannot obtain the strike price.
Step 4: the seller keeps the premium
The buyer cannot exercise and the premium paid in step 2 is not recovered. The report frames this as the buyer having "paid the premium for nothing", and says they essentially have had funds stolen from them.
Root cause
The validation that protects the transfer helper is applied at exercise time, on data the seller chose at order creation time. The two require statements in _transferERC20sIn are reasonable guards for a transfer, but here they turn seller-controlled order data into a denial of service against the buyer: any entry that fails either check blocks the entire exercise, including all the legitimate entries in the same array.
The report's recommended mitigation points at the gap directly: the asset amounts and addresses are not verified during fillOrder(), so an invalid entry survives into the order that the buyer later relies on.
Impact
A put option seller can take the premium and make exercise impossible, so the buyer loses the premium. The condition is that the seller controls the order contents and includes a zero amount or a code-less token address in order.erc20Assets. The report does not describe any other impact, such as theft of the underlying assets or of the strike amount.
Fix
The Putty team confirmed the issue. In their comment they weighed two contract-level mitigations:
- Remove the zero amount check. They rejected this because it would cause another DoS issue for tokens that revert on a zero transfer.
- Check all ERC20 assets are valid in
fillOrder. They noted the gas tradeoff, since it requires an O(n) loop.
Their initial preference was a check at the frontend/database level to ensure every ERC20 asset has an amount greater than zero and exists as a contract, leaving lower-level users to their own diligence. They then changed course and chose a third option: simply skip the ERC20 transfer if the amount is zero.
The team resolved the issue with a pull request: https://github.com/outdoteth/putty-v2/pull/8.
A warden review of the mitigation records that the zero amount part was fixed by introducing a no-op for zero amount transfers in both _transferERC20sIn and _transferERC20sOut. The reviewer notes that the second part, fake tokens, is similar to M-01 and M-02 in the same contest, The reviewer notes that the second part, fake tokens, is similar to M-01 and M-02 in the same contest.
Variants to test
- Zero-amount entries in any asset array the counterparty controls. Look for loops that
require(amount > 0)over user-supplied arrays on a path the other party depends on. A positive result is a revert that blocks the whole operation, not just the offending entry. - Addresses with no code. Try token addresses that are EOAs or not yet deployed. A positive result is a
code.lengthstyle check reverting the operation for the honest party. - Tokens that revert on zero transfers. If a fix simply removes the zero check, test whether a zero transfer to such a token now reverts the flow, which is the DoS the team cited when rejecting that option.
- Mixed arrays. Include one valid entry and one invalid entry. A positive result is that the valid entry does not get processed because the loop reverts on the invalid one.
- Both directions of the transfer helper. The review mentions
_transferERC20sInand_transferERC20sOut; test the outbound path with the same poisoned data.
Hunting notes
This kind of bug hides where one party supplies an array or list that the other party's transaction later iterates over, and where per-element validation reverts the entire call. During review, follow order or request creation data into the execution path and ask who controls each field and when it is validated. The signal is a require inside a loop over counterparty-controlled data: it protects the transfer but also hands a veto to whoever filled the array.
On impact, the report is explicit about the economics: the premium is paid up front and the exercise is the only way to realise value, so blocking exercise converts the premium into a loss. The team confirmed the issue and resolved it with a pull request.
What happened, in plain words
Putty is a service that runs on a blockchain (a shared, public computer network that records transactions). It is an on-chain options protocol. This report is about one kind of option, a put option, and about a flaw that lets the person selling the option take the buyer's money and then make it impossible for the buyer to use what they paid for.
To follow the story you only need three ideas.
- A put option is a contract that gives its buyer the right to sell something (for example, some digital tokens) to the seller at a fixed price, called the strike price, instead of at whatever the market price happens to be. The buyer pays a fee up front for this right. That fee is called the premium.
- Exercising the option means the buyer actually uses that right: they hand the assets over and receive the strike price. This is the moment the option becomes worth anything to the buyer.
- A smart contract is a small program that lives on the blockchain. It runs automatically and cannot be changed once deployed. Putty's rules are written in such a contract, and the contract decides whether a transaction succeeds or fails.
The flaw is simple to state. When the seller creates the option, they write a list of the digital tokens the buyer will have to hand over when exercising. The contract checks that list only at the moment the buyer tries to exercise. If the seller puts one bad entry in the list, the check fails and the whole exercise is refused. The buyer has already paid the premium, cannot exercise, and gets nothing. The report describes this as the buyer having "paid the premium for nothing", with funds effectively stolen.
This was found during a public audit contest run by Code4rena, where several independent researchers review the same code. The finding was rated medium severity. The Putty team confirmed it and shipped a fix.
Background: what the contract does when you exercise
When a buyer exercises a put option, the contract has to move tokens from the buyer into the contract. The list of tokens and amounts to move is stored on the order itself, in a field called order.erc20Assets. "ERC20" is just the standard format for tokens on this blockchain, so erc20Assets means "the list of tokens involved".
The important detail is who writes that list. The seller can include entries in that list when creating the order. The buyer simply relies on it when they later exercise.
So the question the researcher asked was: what happens if the seller writes something into that list that the contract cannot process? The answer is the whole finding.
Finding it
The researcher read the part of the contract that runs when someone exercises, and the helper function it calls to move the buyer's tokens in. The exercise code calls that helper directly:
File: contracts/src/PuttyV2.sol #1
453 // transfer assets from exerciser to putty
454 _transferERC20sIn(order.erc20Assets, msg.sender);
Line by line:
File: contracts/src/PuttyV2.sol #1tells you which file and roughly where in it this snippet sits.PuttyV2.solis the main contract file.453and454are line numbers in that file, so a reader can jump straight to the code.// transfer assets from exerciser to puttyis a comment, a note for humans. It says the next line moves assets from the person exercising (the "exerciser", i.e. the buyer) into Putty._transferERC20sIn(order.erc20Assets, msg.sender);is the actual instruction._transferERC20sInis the name of a helper function. It is given two things:order.erc20Assets, which is the seller-written list of tokens and amounts, andmsg.sender, which is the address of whoever is currently calling the contract, here the buyer exercising the option.
The helper itself is where the trouble lives:
File: contracts/src/PuttyV2.sol #2
593 function _transferERC20sIn(ERC20Asset[] memory assets, address from) internal {
594 for (uint256 i = 0; i < assets.length; i++) {
595 address token = assets[i].token;
596 uint256 tokenAmount = assets[i].tokenAmount;
597
598 require(token.code.length > 0, "ERC20: Token is not contract");
599 require(tokenAmount > 0, "ERC20: Amount too small");
600
601 ERC20(token).safeTransferFrom(from, address(this), tokenAmount);
602 }
603 }
Line by line, in plain words:
function _transferERC20sIn(ERC20Asset[] memory assets, address from) internal {declares the helper. It takes a list calledassets(each item holds a token address and an amount) and an address calledfrom(the person the tokens come from).internalmeans this function can only be called from inside the contract, not directly by an outside user.for (uint256 i = 0; i < assets.length; i++) {starts a loop that walks through the list one entry at a time, from the first to the last.iis the position counter.address token = assets[i].token;picks out the token address of the current entry.uint256 tokenAmount = assets[i].tokenAmount;picks out the amount for that same entry.require(token.code.length > 0, "ERC20: Token is not contract");is a check.requiremeans "if this is not true, stop everything and undo the transaction".token.code.lengthis the amount of program code stored at that address. A real token has code; a plain user address, or an address where nothing has been deployed, has none. So this line says: the address must actually be a token contract, otherwise abort with the message shown.require(tokenAmount > 0, "ERC20: Amount too small");is a second check: the amount must be greater than zero, otherwise abort.ERC20(token).safeTransferFrom(from, address(this), tokenAmount);is the actual movement: taketokenAmountof the token fromfromand send it to the contract's own address.- The closing braces end the loop and the function.
Now connect the two snippets. The loop visits every entry in the seller's list. If even one entry has an amount of zero, line 599 aborts. If even one entry points at an address with no code, line 598 aborts. When a require fails, the entire transaction is cancelled and reversed, not just the bad entry. So one poisoned entry blocks the whole exercise, including all the perfectly good entries sitting next to it in the same list.
How the abuse plays out
Step 1: the seller creates a put order with a poisoned asset entry
The seller writes the order and, inside order.erc20Assets, includes either an amount of zero for one of the assets, or an asset address that currently has no code at it.
Why this matters: the seller is the one who benefits from the order being impossible to exercise, and they are also the one who controls the list. That combination is the heart of the bug.
Step 2: the buyer pays the premium
The buyer purchases the put option in the normal way. The premium is now with the seller. From this point the buyer has already parted with money and is relying on being able to exercise later.
Step 3: the buyer tries to exercise
Exercise reaches line 454 and calls _transferERC20sIn(order.erc20Assets, msg.sender). The loop reaches the poisoned entry and aborts on one of the two require statements shown above. The buyer cannot hand over the assets and therefore cannot obtain the strike price. The option is useless to them.
Step 4: the seller keeps the premium
The buyer cannot exercise, and the premium paid in step 2 is not recovered. The report frames this as the buyer having "paid the premium for nothing", and says they essentially have had funds stolen from them.
Why the code allows it
The two checks in _transferERC20sIn are not silly. Before moving tokens, it is sensible to confirm the address really is a token and the amount really is positive. The problem is when and on whose data those checks run.
The data was written by the seller at order creation. The check runs at exercise time, when the buyer is the one calling. So a guard meant to protect a transfer ends up giving the seller a veto over the buyer's transaction. Any single entry that fails either check blocks the entire exercise, including every legitimate entry in the same array.
The report's recommended mitigation points straight at the gap: the asset amounts and addresses are not verified during fillOrder() (the step where an order is filled or matched), so an invalid entry survives into the order that the buyer later depends on.
What the impact is
A put option seller can take the premium and make exercise impossible, so the buyer loses the premium. The condition is that the seller controls the order contents and includes a zero amount or a code-less token address in order.erc20Assets. The report does not describe any other impact, such as theft of the underlying assets or of the strike amount.
The fix
The Putty team confirmed the issue. In their comment they weighed two possible fixes inside the contract:
- Remove the zero amount check. They rejected this because it would cause another denial-of-service issue for tokens that revert on a zero transfer. (Some tokens refuse to process a transfer of zero, so simply deleting the check would move the problem rather than solve it.)
- Check all ERC20 assets are valid in
fillOrder. They noted the gas tradeoff, since it requires an O(n) loop. ("Gas" is the fee paid to run code on the blockchain; an O(n) loop means the cost grows with the number of entries, so checking every entry costs more.)
Their initial preference was a check at the frontend/database level to ensure every ERC20 asset has an amount greater than zero and exists as a contract, leaving lower-level users to their own diligence. (The "frontend" is the website people use; the "database" is where the service stores order data. A check there is cheaper than on the blockchain, but it only protects people using that website, not people interacting with the contract directly.)
They then changed course and chose a third option: simply skip the ERC20 transfer if the amount is zero.
The team resolved the issue with a pull request: https://github.com/outdoteth/putty-v2/pull/8.
A warden review of the mitigation records that the zero amount part was fixed by introducing a no-op for zero amount transfers in both _transferERC20sIn and _transferERC20sOut. (A "no-op" is a step that deliberately does nothing; here, a zero transfer is skipped instead of aborting.) The reviewer notes that the second part, fake tokens, is similar to M-01 and M-02 in the same contest, The reviewer notes that the second part, fake tokens, is similar to M-01 and M-02 in the same contest.
Variants worth testing
These are the same patterns to look for elsewhere, written so you can follow the reasoning even without a security background.
- Zero-amount entries in any asset array the counterparty controls. Look for loops that
require(amount > 0)over user-supplied arrays on a path the other party depends on. A positive result is a revert that blocks the whole operation, not just the offending entry. In everyday terms: one person fills in a form, another person's request later reads that form, and one blank field cancels the whole request. - Addresses with no code. Try token addresses that are EOAs or not yet deployed. (An "EOA" is an ordinary user wallet address, which has no program code attached.) A positive result is a
code.lengthstyle check reverting the operation for the honest party. - Tokens that revert on zero transfers. If a fix simply removes the zero check, test whether a zero transfer to such a token now reverts the flow, which is the DoS the team cited when rejecting that option.
- Mixed arrays. Include one valid entry and one invalid entry. A positive result is that the valid entry does not get processed because the loop reverts on the invalid one.
- Both directions of the transfer helper. The review mentions
_transferERC20sInand_transferERC20sOut; test the outbound path with the same poisoned data.
How to spot this kind of bug yourself
This kind of bug hides where one party supplies an array or list that the other party's transaction later iterates over, and where per-element validation reverts the entire call. During review, follow order or request creation data into the execution path and ask who controls each field and when it is validated. The signal is a require inside a loop over counterparty-controlled data: it protects the transfer but also hands a veto to whoever filled the array.
On impact, the report is explicit about the economics: the premium is paid up front and the exercise is the only way to realise value, so blocking exercise converts the premium into a loss. The team confirmed the issue and resolved it with a pull request.
Glossary
- Blockchain: a shared, public record of transactions kept by many computers at once, which nobody can quietly rewrite.
- Smart contract: a program stored on a blockchain that runs automatically when someone calls it and cannot be changed after deployment.
- Put option: a deal giving its buyer the right to sell assets to the seller at a fixed price instead of the market price.
- Premium: the fee the option buyer pays up front for the right the option gives them.
- Strike price: the fixed price at which the option lets the buyer sell the assets.
- Exercise: the act of the buyer actually using the option, handing over the assets and receiving the strike price.
- ERC20: the common standard format for tokens on this blockchain.
order.erc20Assets: the list of tokens and amounts stored on an order, written by the seller, that the buyer must transfer when exercising.require: a check in a smart contract that cancels and reverses the whole transaction if its condition is not true.- Revert: the cancellation of a transaction, undoing any changes it made.
- Denial of service (DoS): making a legitimate action impossible for the person entitled to do it.
msg.sender: the address of whoever is currently calling the contract.- Address: an identifier on the blockchain, either a user wallet or a deployed contract.
- EOA: an ordinary user wallet address, which has no program code attached.
code.length: the amount of program code stored at an address; zero means nothing is deployed there.fillOrder(): the step in the contract where an order is filled or matched.- Gas: the fee paid to run code on the blockchain; longer or repeated work costs more.
- O(n) loop: a loop whose cost grows with the number of items it processes.
- No-op: a step that deliberately does nothing.
- Frontend: the website people use to interact with the service.
- Warden: a reviewer in an audit contest who checks findings and fixes.
- Code4rena: the platform that ran the public audit contest where this finding was submitted.
- Medium severity: a rating meaning the issue is real and harmful but not the most severe category.