fillOrder() and exercise() may lock Ether sent to the contract, forever
The fillOrder() and exercise() functions are payable and accept Ether even when the code path does not require it, so any Ether sent is locked in the contract forever. An attacker could not directly exploit this, but a user could accidentally lose funds by sending Ether when it is not needed.
Submitted by IllIllI, also found by 0x29A, 0xc0ffEE, 0xDjango, AmitN, auditor0517, berndartmueller, BowTiedWardens, cccz, danb, dipp, dirky, hansfriese, horsefacts, hyh, joestakey, kirk-baird, oyc109, peritoflores, rfa, sashiketh, simon135, sseefried, StErMi, swit, xiaoming90, and zzzitron_
Impact
fillOrder() and exercise() have code paths that require Ether to be sent to them (e.g. using WETH as the base asset, or the provision of the exercise price), and therefore those two functions have the payable modifier. However, there are code paths within those functions that do not require Ether. Ether passed to the functions, when the non-Ether code paths are taken, is locked in the contract forever, and the sender gets nothing extra in return for it.
Proof of Concept
Ether can’t be pulled from the order.maker during the filling of a long order, so msg.value shouldn’t be provided here:
File: contracts/src/PuttyV2.sol #1
323 if (order.isLong) {
324 ERC20(order.baseAsset).safeTransferFrom(order.maker, msg.sender, order.premium);
325 } else {
If the baseAsset isn’t WETH during order fulfillment, msg.value is unused:
File: contracts/src/PuttyV2.sol #2
337 } else {
338 ERC20(order.baseAsset).safeTransferFrom(msg.sender, order.maker, order.premium);
339 }
Same for the exercise of call options:
File: contracts/src/PuttyV2.sol #3
435 } else {
436 ERC20(order.baseAsset).safeTransferFrom(msg.sender, address(this), order.strike);
437 }
Recommended Mitigation Steps
Add a require(0 == msg.value) for the above three conditions.
Alex the Entreprenerd (warden) commented:
Why would the caller send ETH when they don’t have to?
User error is one possibility.
outdoteth (Putty Finance) confirmed and commented:
Report: Native ETH can be lost if it’s not utilised in exercise and fillOrder.
outdoteth (Putty Finance) resolved:
PR with fix: https://github.com/outdoteth/putty-v2/pull/5.
hyh (warden) reviewed mitigation:
Fixed with native funds amount control added to strike transfer logic of
fillOrder. Zero strike and zero premium corner cases are yet unhandled as described in M.M-01 and M.M-02 in the Mitigation Review below.
Context
Putty is an on-chain options protocol. Its core contract, PuttyV2, lets a maker create an order for a long or short position, lets a taker fill that order, and lets the holder of an option exercise it. Two of the entry points, fillOrder() and exercise(), are marked payable because some of their code paths genuinely need native Ether: for example when WETH is used as the base asset, or when the exercise price (the strike) has to be paid in Ether.
The finding here is about the other paths, the ones that settle entirely in ERC20 tokens. Those paths never read msg.value, so any Ether a caller attaches to the call stays in the contract with no way to retrieve it. The report was filed by IllIllI and independently found by a long list of other wardens: 0x29A, 0xc0ffEE, 0xDjango, AmitN, auditor0517, berndartmueller, BowTiedWardens, cccz, danb, dipp, dirky, hansfriese, horsefacts, hyh, joestakey, kirk-baird, oyc109, peritoflores, rfa, sashik*eth, simon135, sseefried, StErMi, swit, xiaoming90 and zzzitron.
Setup
The report is a code review of the PuttyV2 contract at commit [redacted], in the contracts/src/PuttyV2.sol file. No accounts, tooling or deployment are described; the analysis is done by reading the source and following the branches that handle Ether versus ERC20 settlement. The precondition for the bug is simply that a caller sends a non-zero msg.value to fillOrder() or exercise() on a path that does not need native Ether.
Finding it
The starting observation is that both functions carry the payable modifier because some of their branches require Ether. The researcher then looked at the branches that do not require Ether and found that none of them check msg.value. Since the contract has no refund logic on those paths, Ether sent along with such a call is stranded.
The report points at three specific locations in the source: line 324, line 338 and line 436.
Exploitation
Step 1: filling a long order
When a long order is filled, the premium is pulled from the maker with an ERC20 transfer. Ether cannot be pulled from the maker in this branch, so there is no reason for the caller to supply msg.value:
File: contracts/src/PuttyV2.sol #1
323 if (order.isLong) {
324 ERC20(order.baseAsset).safeTransferFrom(order.maker, msg.sender, order.premium);
325 } else {
Step 2: filling a short order with a non-WETH base asset
On the short side, the premium moves from the caller to the maker, again as an ERC20 transfer. If the baseAsset is not WETH during order fulfilment, msg.value is never used:
File: contracts/src/PuttyV2.sol #2
337 } else {
338 ERC20(order.baseAsset).safeTransferFrom(msg.sender, order.maker, order.premium);
339 }
Step 3: exercising a call option with a non-WETH base asset
The same pattern appears when a call option is exercised. The strike is transferred from the caller to the contract as an ERC20 token, so a native Ether payment is not consumed:
File: contracts/src/PuttyV2.sol #3
435 } else {
436 ERC20(order.baseAsset).safeTransferFrom(msg.sender, address(this), order.strike);
437 }
In all three cases the call succeeds, the ERC20 settlement happens as normal, and the attached Ether remains in the contract. The sender receives nothing extra in return for it.
Root cause
The payable modifier is applied to the whole function, but only some branches of the function actually need native funds. The branches that settle in ERC20 have no guard on msg.value, so the contract accepts Ether it will never use and has no path to return it. The existing code does not defend against this because there is no check tying the presence of msg.value to the branch that consumes it.
Impact
The Ether is locked in the contract forever and the sender gets nothing in return. The report frames this as a caller-side loss rather than something an attacker extracts from a victim. During discussion, Alex the Entreprenerd asked why a caller would send ETH when they do not have to, and sseefried answered that user error is one possibility. Putty Finance confirmed the issue, describing it as native ETH being lost if it is not utilised in exercise and fillOrder.
Fix
The recommended mitigation in the report is to add a require(0 == msg.value) for the three conditions above, so that a call which does not need Ether rejects any attached value.
Putty Finance resolved the issue with a pull request: https://github.com/outdoteth/putty-v2/pull/5. In the mitigation review, hyh noted that the fix adds native funds amount control to the strike transfer logic of fillOrder, and that two corner cases remain unhandled: zero strike and zero premium, tracked as M.M-01 ("WETH zero strike call fillOrders msgvalue will be lost") and M.M-02 ("zero premium short fillOrders msgvalue will be lost") in the mitigation review.
Variants to test
- Any
payablefunction whose branches settle in ERC20 only: send a smallmsg.valueon the ERC20 branch and check whether the contract balance grows with no refund path. A positive result is a successful call that leaves the Ether in the contract. - Zero-value corner cases: a zero strike on a WETH call fill, or a zero premium on a short fill. A positive result is a call where the amount that should be consumed is zero, so the attached Ether is never used.
- Mixed-asset orders: base asset WETH on one side and an ERC20 on the other, to see whether the branch that consumes Ether is actually reached.
- Refund logic: look for any function that sweeps native balance, and check whether an unauthorised party can call it or whether it exists at all.
Hunting notes
This class of bug hides in payable functions with multiple settlement branches, especially in DeFi contracts that support both native Ether and WETH or other ERC20 tokens. During review, the signal is a payable modifier combined with safeTransferFrom calls and no msg.value check on the ERC20 path. The report showed impact by pointing at the exact source lines where the value is ignored and by noting that the contract has no way to return it; the program confirmed and fixed it, and the mitigation review noted that the zero strike and zero premium corner cases remain unhandled.
What happened, in plain words
Putty is a service that runs on a blockchain (a shared, publicly visible computer that many people use at once). It lets two people agree on a financial deal called an option: one person offers the deal, another accepts it, and later the holder can choose to use ("exercise") it. The program that runs these deals is a smart contract, which is code stored on the blockchain that anyone can call. It behaves like a vending machine: you send it a request, it does exactly what its code says, and nobody can change the code after it is deployed.
Some of the actions in Putty's contract are designed to accept two different kinds of money. One kind is native Ether (ETH), the blockchain's own currency, which you attach directly to a request. The other kind is an ERC20 token, a digital token implemented by a separate contract, which moves between accounts through a transfer instruction rather than being attached to a request. Because some actions might need native Ether, the developers marked those actions as payable, meaning the contract is willing to accept Ether attached to the call.
The problem is that each of those actions has several internal branches, and only some branches actually need Ether. On the branches that settle entirely in ERC20 tokens, the attached Ether is never looked at. The contract keeps it, and there is no way to get it back. The person who sent it gets nothing extra in return. The report frames this as a caller-side loss rather than something an attacker steals from a victim, but it is still money that disappears forever.
The finding was filed by IllIllI and independently found by a long list of other reviewers: 0x29A, 0xc0ffEE, 0xDjango, AmitN, auditor0517, berndartmueller, BowTiedWardens, cccz, danb, dipp, dirky, hansfriese, horsefacts, hyh, joestakey, kirk-baird, oyc109, peritoflores, rfa, sashik*eth, simon135, sseefried, StErMi, swit, xiaoming90 and zzzitron.
The product and the feature
Putty is described as an on-chain options protocol. An option is a contract between two parties that gives one of them the right (but not the obligation) to buy or sell something at a price agreed in advance. That agreed price is called the strike. The small fee one side pays the other for entering the deal is called the premium.
The core contract is called PuttyV2. It has three jobs:
- A maker creates an order describing a deal, either a long position (the maker is on the buying side) or a short position (the maker is on the selling side).
- A taker fills that order, meaning they accept the deal and the two sides exchange the premium.
- Whoever ends up holding the option can exercise it, meaning they use their right to buy or sell at the strike price.
Two of these entry points, fillOrder() and exercise(), are marked payable. A payable function is one that is allowed to receive native Ether along with the call. The developers marked them this way because some of their internal branches genuinely need Ether: for example when the base asset of the deal is WETH (a token that represents Ether one-to-one), or when the strike has to be paid in Ether.
The finding is about the other branches, the ones that settle entirely in ERC20 tokens. Those branches never read the amount of Ether attached to the call, so any Ether a caller attaches stays in the contract with no way to retrieve it.
Setup
The report is a code review of the PuttyV2 contract at a specific saved version of the source code, identified by the commit [redacted], in the file contracts/src/PuttyV2.sol. A commit is a labelled snapshot of a code repository, so this pins down exactly which lines were reviewed.
No accounts, tools or deployed instances are described. The analysis is done by reading the source code and following the branches that handle Ether versus ERC20 settlement. The only precondition for the bug is that a caller sends a non-zero amount of Ether (the msg.value, meaning the value attached to the call) to fillOrder() or exercise() on a path that does not need native Ether.
Finding it
The starting observation is that both functions carry the payable modifier because some of their branches require Ether. The researcher then looked at the branches that do not require Ether and found that none of them check msg.value. Since the contract has no refund logic on those paths, Ether sent along with such a call is stranded.
The report points at three specific locations in the source: line 324, line 338 and line 436.
Exploitation
Step 1: filling a long order
When a long order is filled, the premium is pulled from the maker with an ERC20 transfer. Ether cannot be pulled from the maker in this branch, so there is no reason for the caller to supply msg.value:
File: contracts/src/PuttyV2.sol #1
323 if (order.isLong) {
324 ERC20(order.baseAsset).safeTransferFrom(order.maker, msg.sender, order.premium);
325 } else {
Line by line:
if (order.isLong) {checks whether the order is a long order, that is, the maker is on the buying side.ERC20(order.baseAsset).safeTransferFrom(order.maker, msg.sender, order.premium);treats the order's base asset as an ERC20 token and moves the premium from the maker to the caller.safeTransferFromis a standard token instruction that moves tokens between two accounts and fails loudly if something goes wrong.msg.senderis the account that made the call.} else {starts the branch for short orders, which is shown in the next step.
Why this step was taken: it shows that on the long branch the money moves as a token transfer, not as attached Ether. Nothing in this branch reads the Ether attached to the call, so any Ether sent along with it has nowhere to go.
Step 2: filling a short order with a non-WETH base asset
On the short side, the premium moves from the caller to the maker, again as an ERC20 transfer. If the baseAsset is not WETH during order fulfilment, msg.value is never used:
File: contracts/src/PuttyV2.sol #2
337 } else {
338 ERC20(order.baseAsset).safeTransferFrom(msg.sender, order.maker, order.premium);
339 }
Line by line:
} else {is the short-order branch that follows the long-order check from step 1.ERC20(order.baseAsset).safeTransferFrom(msg.sender, order.maker, order.premium);moves the premium in the opposite direction: from the caller to the maker, again as an ERC20 token transfer.}closes the branch.
Why this step was taken: it shows the same pattern on the other side of the trade. The base asset is whatever token the deal is denominated in. When that token is not WETH, the branch never touches the attached Ether, so the Ether is accepted and then ignored.
Step 3: exercising a call option with a non-WETH base asset
The same pattern appears when a call option is exercised. The strike is transferred from the caller to the contract as an ERC20 token, so a native Ether payment is not consumed:
File: contracts/src/PuttyV2.sol #3
435 } else {
436 ERC20(order.baseAsset).safeTransferFrom(msg.sender, address(this), order.strike);
437 }
Line by line:
} else {opens the branch taken when the exercise is settled in an ERC20 token rather than in Ether.ERC20(order.baseAsset).safeTransferFrom(msg.sender, address(this), order.strike);moves the strike amount from the caller to the contract itself.address(this)means the contract's own account, so the tokens are held by the contract.}closes the branch.
Why this step was taken: exercising is the moment the option holder pays the strike. On this branch the payment is a token transfer, so again the attached Ether is never read.
In all three cases the call succeeds, the ERC20 settlement happens as normal, and the attached Ether remains in the contract. The sender receives nothing extra in return for it.
Root cause
The payable modifier is applied to the whole function, but only some branches of the function actually need native funds. The branches that settle in ERC20 have no guard on msg.value, so the contract accepts Ether it will never use and has no path to return it. The existing code does not defend against this because there is no check tying the presence of msg.value to the branch that consumes it.
A useful comparison: imagine a shop counter with one payment slot used for both cash and card. If you pay by card but also drop cash into the slot, the cash goes into the till and the shop has no procedure to hand it back. The slot is payable; the card branch is the ERC20 path; the missing refund procedure is the absent msg.value check.
Impact
The Ether is locked in the contract forever and the sender gets nothing in return. The report frames this as a caller-side loss rather than something an attacker extracts from a victim.
During discussion, Alex the Entreprenerd asked why a caller would send ETH when they do not have to, and sseefried answered that user error is one possibility. Putty Finance confirmed the issue, describing it as native ETH being lost if it is not utilised in exercise and fillOrder.
Fix
The recommended mitigation in the report is to add a require(0 == msg.value) for the three conditions above, so that a call which does not need Ether rejects any attached value. require is a check that aborts the whole call if its condition is false, so a caller who accidentally attaches Ether on an ERC20 branch would get an error instead of losing the money.
Putty Finance resolved the issue with a pull request: https://github.com/outdoteth/putty-v2/pull/5. A pull request is a proposed change to a code repository that can be reviewed before it is merged.
In the mitigation review, hyh noted that the fix adds native funds amount control to the strike transfer logic of fillOrder, and that two corner cases remain unhandled: zero strike and zero premium, tracked as M.M-01 ("WETH zero strike call fillOrders msgvalue will be lost") and M.M-02 ("zero premium short fillOrders msgvalue will be lost") in the mitigation review. A corner case is an unusual input at the edge of what the code expects, here an amount of zero, where the amount that should be consumed is nothing, so the attached Ether is still never used.
Variants to test
These are the follow-up checks a reviewer would run on this kind of code:
- Any
payablefunction whose branches settle in ERC20 only: send a smallmsg.valueon the ERC20 branch and check whether the contract balance grows with no refund path. A positive result is a successful call that leaves the Ether in the contract. - Zero-value corner cases: a zero strike on a WETH call fill, or a zero premium on a short fill. A positive result is a call where the amount that should be consumed is zero, so the attached Ether is never used.
- Mixed-asset orders: base asset WETH on one side and an ERC20 on the other, to see whether the branch that consumes Ether is actually reached.
- Refund logic: look for any function that sweeps native balance, and check whether an unauthorised party can call it or whether it exists at all. A sweep function is one that moves leftover funds out of a contract.
Hunting notes
This class of bug hides in payable functions with multiple settlement branches, especially in DeFi contracts (financial applications built on a blockchain) that support both native Ether and WETH or other ERC20 tokens. During review, the signal is a payable modifier combined with safeTransferFrom calls and no msg.value check on the ERC20 path.
The report showed impact by pointing at the exact source lines where the value is ignored and by noting that the contract has no way to return it. The program confirmed and fixed it, and the mitigation review noted that the zero strike and zero premium corner cases remain unhandled.
Glossary
- Blockchain: a shared, publicly visible record of transactions that many computers maintain together and that nobody can quietly rewrite.
- Smart contract: code stored on a blockchain that anyone can call and that runs exactly as written.
- Ether (ETH): the blockchain's own currency, sent directly with a call rather than as a token.
- ERC20 token: a digital token implemented by a separate contract, moved between accounts with a transfer instruction.
- WETH: a token that represents Ether one-to-one, so Ether can be handled like any other ERC20 token.
- Option: a deal giving one party the right, but not the obligation, to buy or sell at a price agreed in advance.
- Strike: the price agreed in advance at which an option can be exercised.
- Premium: the fee one side of an option pays the other for entering the deal.
- Maker: the party who creates an order describing the deal.
- Taker: the party who accepts and fills a maker's order.
- Long order: an order where the maker is on the buying side.
- Short order: an order where the maker is on the selling side.
- Exercise: the option holder using their right to buy or sell at the strike price.
- Call option: an option giving the right to buy.
- Base asset: the token a deal is denominated in.
payable: a marker on a function meaning it is allowed to receive native Ether along with the call.msg.value: the amount of native Ether attached to a call.msg.sender: the account that made the call.address(this): the contract's own account address.safeTransferFrom: a standard token instruction that moves tokens between two accounts and fails loudly if something goes wrong.require: a check that aborts the whole call if its condition is false.- Branch: one of several alternative paths through a function, chosen by conditions such as whether an order is long or short.
- Commit: a labelled snapshot of a code repository that pins down exactly which version was reviewed.
- Pull request: a proposed change to a code repository that can be reviewed before it is merged.
- Corner case: an unusual input at the edge of what the code expects, such as an amount of zero.
- Sweep function: a function that moves leftover funds out of a contract.
- DeFi: financial applications built on a blockchain.
- Modifier: a keyword attached to a function that changes how it behaves, such as allowing it to receive Ether.
- Warden: a security reviewer taking part in a code review contest.
- Mitigation review: a follow-up review that checks whether a fix actually closes the issue.