Fee is being deducted when Put is expired and not when it is exercised.
The fee logic in PuttyV2.sol incorrectly deducts a fee from the strike when a put option expires unexercised, and fails to deduct a fee when a put option is exercised. This causes a loss of assets for the put shorter and a loss of protocol revenue.
Originally disclosed on Code4rena
Submitted by zishansami, also found by 0x52, 0xsanson, auditor0517, berndartmueller, csanuragjain, and zzzitron
Impact
Fee is being deducted when Put is expired and not when it is exercised in PuttyV2.sol. Comment section of the setFee() function mentions "fee rate that is applied on exercise" which signifies that the fee amount is meant to be deducted from strike only when a position is being exercised (or has been exercised).
But, in function withdraw() at PuttyV2.solL#495-L503 the fee is being deducted even when the Put position is not exercised and has expired.
Also, in function exercise() there is no fee deduction from the order.strike when the Put position is exercised and the strike is being transferred to the caller (PuttyV2.solL#451).
This unintended deduction from assets of Put Shorter and the absence of fee deduction from strike when Put is exercised are directly impacting the assets and therefore marked as Medium Risk.
Proof of Concept
if condition present at PuttyV2.solL#495 passes if order.isCall is false and isExercised is false.
feeAmount becomes positive if fee > 0 and it gets deducted from the order.strike which gets transferred to msg.sender at line number PuttyV2.solL#503.
Recommended Mitigation Steps
- Update
ifcondition at PuttyV2.sol#L498 with(fee > 0 && order.isCall && isExercised) - Add feeAmount calculation and deduction after put is exercised and strike is transferred at PuttyV2.sol#L451 as follows:
uint256 feeAmount = 0;
if (fee > 0) {
feeAmount = (order.strike * fee) / 1000;
ERC20(order.baseAsset).safeTransfer(owner(), feeAmount);
}
ERC20(order.baseAsset).safeTransfer(msg.sender, order.strike - feeAmount);
outdoteth (Putty Finance) confirmed and commented:
Report: Fees are only applied on puts if they are expired.
HickupHH3 (judge) increased severity to High and commented:
Due to incorrect logic, there are 2 consequences of separate severities:
- Expired put option being charged the admin fee. As @berndartmueller mentioned in #380, the fee should be charged on the premium (actually this is another issue, see #373). Since it is possible for the fee amount to be greater than expected, I consider this to be a loss of assets and therefore given a high severity rating.
- Put option not being charged fee upon exercising it. This can be considered to the “protocol leaked value” and thus be given a medium severity rating.
Issues that mention (1) or both (1) and (2) will be given a high severity rating, those that mention only (2) will be given a medium.
outdoteth (Putty Finance) resolved:
PR with fix: https://github.com/outdoteth/putty-v2/pull/4.
hyh (warden) reviewed mitigation:
Fixed by changing the fee base to be
order.premiumPR#4, which is now paid uniformly for all option types on order filling. Utilizingorder.strikeas the fee base was the root cause for M-04, M-06, M-11, M-15, so the change toorder.premiumwas a shared mitigation for all of them.
Context
Putty is an on-chain options protocol. The contract in scope is PuttyV2.sol, which lets users write and exercise call and put options. Two order types matter here: calls (order.isCall == true) and puts (order.isCall == false).
The protocol charges an admin fee, configured through setFee(). The comment on that function describes it as the "fee rate that is applied on exercise", which tells us the intended behaviour: the fee should be taken from the strike when a position is exercised, and only then.
The report looks at two functions in PuttyV2.sol:
withdraw(), specifically the block at lines 495 to 503, which handles the path where a put option has expired and the writer withdraws the collateral.exercise(), specifically line 451, where the strike is transferred to the caller when a put is exercised.
Setup
This is a Code4rena audit finding against the Putty codebase, so there are no accounts, roles or live requests. The relevant preconditions are contract state:
- A put order exists (
order.isCall == false). - The protocol fee is greater than zero (
fee > 0). - The order is either expired and not exercised (the
withdraw()path) or being exercised (theexercise()path).
The finding was submitted by zishansami and independently found by 0x52, 0xsanson, auditor0517, berndartmueller, csanuragjain and zzzitron.
Finding it
The researcher started from the comment on setFee(), which says the fee rate is "applied on exercise". That is the stated intent. Reading the two code paths against that intent showed a mismatch in both directions:
- In
withdraw(), the fee is deducted even when the put position was never exercised and has simply expired. - In
exercise(), no fee is deducted fromorder.strikewhen the put is exercised and the strike is transferred to the caller.
So the fee is charged in the case where it should not be, and not charged in the case where it should be. The researcher framed this as an unintended deduction from the Put Shorter's assets plus a missing deduction on exercise, and rated it Medium because both directly affect assets.
Exploitation
Step 1: trace the expired-put withdrawal path
The if condition at line 495 passes when order.isCall is false and isExercised is false. In that branch, feeAmount becomes positive whenever fee > 0, and it is deducted from order.strike, which is then transferred to msg.sender at line 503.
The consequence is that a put writer who simply lets the option expire and withdraws collateral pays the admin fee, even though nothing was exercised. The fee is taken from the strike amount on the way out.
Step 2: trace the exercise path
In exercise(), the strike is transferred to the caller at line 451 with no fee deduction at all. A put that is actually exercised therefore pays no fee, which is the opposite of what the setFee() comment describes.
Step 3: confirm the two consequences are independent
The two behaviours are separate defects with separate severities, as the judge later set out. The expired-put charge is a loss of assets to the writer. The missing charge on exercise is value the protocol never collects. A submission that mentions only the second consequence is treated as Medium; one that mentions the first, or both, is treated as High.
Root cause
In withdraw(), the fee is applied on the expiry path instead of the exercise path, and it is computed against order.strike. In exercise(), the strike transfer happens without any fee calculation.
The condition at line 495 passes when order.isCall is false and isExercised is false, and in that branch the fee is deducted from order.strike. Nothing in exercise() performs the deduction the setFee() comment promises.
Impact
There are two distinct effects:
- Expired put charged the admin fee. The writer loses part of the strike on withdrawal. The judge noted that the fee amount can be greater than expected, treated this as a loss of assets and rated it High.
- Put not charged a fee on exercise. The protocol leaks the value it should have collected. The judge rated this Medium, describing it as "protocol leaked value".
The report's own rating was Medium, on the basis that both behaviours affect assets. The judge raised it to High because of the first consequence.
Fix
The report recommended two changes:
- Update the
ifcondition at line 498 to(fee > 0 && order.isCall && isExercised). - Add fee calculation and deduction after the put is exercised and the strike is transferred at line 451, as follows:
uint256 feeAmount = 0;
if (fee > 0) {
feeAmount = (order.strike * fee) / 1000;
ERC20(order.baseAsset).safeTransfer(owner(), feeAmount);
}
ERC20(order.baseAsset).safeTransfer(msg.sender, order.strike - feeAmount);
Putty Finance confirmed the report ("Fees are only applied on puts if they are expired") and resolved it with a pull request. The warden who reviewed the mitigation described the actual fix: the fee base was changed to order.premium, which is now paid uniformly for all option types on order filling. The warden noted that using order.strike as the fee base was the root cause of several other findings, so the change to order.premium was a shared mitigation for all of them.
Variants to test
- Fee applied on the wrong lifecycle event. Look for fee or royalty logic in expiry, cancellation or withdrawal paths where the documentation says it applies on exercise or settlement. A positive result is a fee charged to a user who took no action that should trigger it.
- Fee base mismatch. Check whether fees are computed against strike, premium, notional or collateral, and compare with the comment or specification. A positive result is a fee that scales with the wrong quantity, especially one that can exceed the intended amount.
- Missing fee on the settlement path. Trace the branch that actually transfers value to the exercising party and check whether any fee deduction exists there. A positive result is a settlement transfer with no fee taken while other paths do take one.
- Asymmetric handling of calls and puts. Compare the call and put branches of the same function. A positive result is a condition that checks
isCallin one branch but not the other, or a fee applied in one and not the other.
Hunting notes
This kind of bug hides in fee, royalty and accounting logic around lifecycle transitions: exercise, expiry, withdrawal and settlement. The strongest signal is a comment or specification that states when a fee applies, followed by code that applies it somewhere else. Reading the fee configuration function and its comments first, then tracing every place the fee variable is used, is a quick way to spot the mismatch.
The researcher showed impact by tying each behaviour to a concrete asset movement: a deduction from the writer's strike on expiry, and a missing deduction on exercise. The judge rated submissions High if they mentioned the expired-put charge, or both consequences, and Medium if they mentioned only the missing charge on exercise.
Difficulty
{"difficulty": "intermediate", "difficulty_reason": "The bug is a logic mismatch between documented fee intent and two code paths, requiring the reader to trace fee handling across withdraw and exercise but no exploit tooling or live target."}
What happened, in plain words
Putty is a service that runs on a blockchain (a shared, public record of transactions that many computers keep copies of). It lets people make deals about a thing called an option. An option is a contract between two people: one person pays a small amount now for the right to do a bigger trade later, and the other person agrees to that trade if it is asked for. Putty is written as a smart contract, which is a program that lives on the blockchain and runs by itself, with no company in the middle pressing buttons.
The program charges a small admin fee on some of these deals. The question in this report is simple: when exactly should that fee be taken, and from what amount? The code's own comment says the fee is "applied on exercise", meaning it should be charged when someone actually uses the option, not at other times. The report shows that the code does the opposite in two places. It charges the fee when an option quietly runs out unused, and it forgets to charge it when the option is actually used.
That is a logic bug: the program does something different from what it says it does. Nobody needs a password or a special tool to trigger it. It happens as part of normal use, which is why it matters.
The product and the two kinds of option
Putty is described as an on-chain options protocol. "On-chain" means everything happens in transactions recorded on the blockchain, and "protocol" here means a set of smart contracts that define the rules.
The contract examined is called PuttyV2.sol. A .sol file is source code written in Solidity, the language used for smart contracts on the Ethereum-style blockchains. This one contract lets users write options (create them and put up the collateral that backs them) and exercise options (use the right the option gives them).
Two order types matter:
- Calls, where
order.isCall == true. In everyday terms, a call gives someone the right to buy something at an agreed price. - Puts, where
order.isCall == false. A put gives someone the right to sell something at an agreed price.
order.isCall is just a true/false switch stored with each order. Reading it tells the contract which kind of deal it is looking at.
Two more words appear constantly in this report:
- Strike: the agreed price in the option deal. It is the amount of the underlying asset that changes hands when the option is exercised.
- Premium: the small amount one side pays up front for the option. It is mentioned later, in the fix discussion.
The fee and what its comment promises
The protocol charges an admin fee. It is configured through a function called setFee(). A function is a named block of code that can be called to do something; setFee() is the one an administrator uses to set the fee rate.
The comment on that function describes the fee as the "fee rate that is applied on exercise". This is the key sentence. It tells us the intended behaviour: the fee should be taken from the strike when a position is exercised, and only then. Think of a cloakroom that says "charge on collection": you pay when you pick up your coat, not when you drop it off and never come back.
The two code paths examined
The report looks at two functions in PuttyV2.sol:
withdraw(), specifically the block at lines 495 to 503. This handles the path where a put option has expired and the writer (the person who created the option and put up collateral) takes the collateral back.exercise(), specifically line 451, where the strike is transferred to the caller when a put is exercised.
A line number here is just a position in the source file, so anyone can jump straight to the code being discussed. The report links to the exact lines on GitHub, for example the block at lines 495 to 503 and the single line 451.
Setup: what has to be true for the bug to appear
This is an audit finding from Code4rena, a platform where independent researchers review code before or after it goes live. There are no accounts, roles or live web requests involved, so there is nothing to log into and no URL to call. The relevant preconditions are states inside the contract:
- A put order exists (
order.isCall == false). - The protocol fee is greater than zero (
fee > 0). - The order is either expired and not exercised (the
withdraw()path) or being exercised (theexercise()path).
The finding was submitted by zishansami and independently found by 0x52, 0xsanson, auditor0517, berndartmueller, csanuragjain and zzzitron. Several people finding the same thing separately is a normal sign that the issue is real and not a one-off misreading.
Finding it: how the researcher spotted the mismatch
The researcher started from the comment on setFee(), which says the fee rate is "applied on exercise". That is the stated intent, the promise the code makes to its users. Then they read the two code paths against that promise and found a mismatch in both directions:
- In
withdraw(), the fee is deducted even when the put position was never exercised and has simply expired. - In
exercise(), no fee is deducted fromorder.strikewhen the put is exercised and the strike is transferred to the caller.
So the fee is charged in the case where it should not be, and not charged in the case where it should be. It is as if a shop charged you for delivery on an order you cancelled, and gave you free delivery on the order you actually received.
The researcher framed this as an unintended deduction from the Put Shorter's assets (the writer, the person who put up the collateral) plus a missing deduction on exercise, and rated it Medium because both directly affect assets. "Assets" here means things of value held by the contract on behalf of users.
Exploitation: walking through each step
Step 1: trace the expired-put withdrawal path
The if condition at line 495 passes when order.isCall is false and isExercised is false. In plain words: this branch runs for puts that were never exercised. In that branch, feeAmount becomes positive whenever fee > 0, and it is deducted from order.strike, which is then transferred to msg.sender at line 503.
A few terms in that paragraph deserve unpacking:
- An
ifcondition is a test the program performs before running a block of code. If the test is true, the block runs; if not, it is skipped. isExercisedis a true/false flag recording whether the option was ever used.feeAmountis a variable, a named box in the program that holds a number. Here it holds how much fee to take.msg.senderis the blockchain address of whoever triggered the current call, in everyday terms the person making the request.
The consequence is that a put writer who simply lets the option expire and withdraws collateral pays the admin fee, even though nothing was exercised. The fee is taken from the strike amount on the way out. The writer did nothing that should trigger a fee, yet loses part of the amount they were withdrawing.
Step 2: trace the exercise path
In exercise(), the strike is transferred to the caller at line 451 with no fee deduction at all. A put that is actually exercised therefore pays no fee, which is the opposite of what the setFee() comment describes. The moment the fee was supposed to be collected, nothing is collected.
Step 3: confirm the two consequences are independent
The two behaviours are separate defects with separate severities, as the judge later set out. The judge is the person on the audit platform who decides how serious each finding is. The expired-put charge is a loss of assets to the writer. The missing charge on exercise is value the protocol never collects. A submission that mentions only the second consequence is treated as Medium; one that mentions the first, or both, is treated as High.
This is worth pausing on. The same piece of code produced two different problems, and the platform scored them differently because one takes money from a user while the other merely fails to collect money for the protocol. Severity is about who loses what, not just about whether the code is wrong.
Root cause: why the code does this
In withdraw(), the fee is applied on the expiry path instead of the exercise path, and it is computed against order.strike. Two ideas there:
- The event is the moment in an option's life when something happens: it is created, exercised, expires, or is withdrawn. The fee should hang off "exercised". Instead, in
withdraw(), it hangs off expiry. - The base is the quantity the fee is calculated from. Here it is
order.strike. If you charge 1% of the wrong number, you get the wrong fee even if the timing is right.
In exercise(), the strike transfer happens without any fee calculation.
The condition at line 495 passes when order.isCall is false and isExercised is false, and in that branch the fee is deducted from order.strike. Nothing in exercise() performs the deduction the setFee() comment promises. In other words, the guard that decides whether to charge checks the wrong question.
Impact: what actually goes wrong for users
There are two distinct effects:
- Expired put charged the admin fee. The writer loses part of the strike on withdrawal. The judge noted that the fee amount can be greater than expected, treated this as a loss of assets and rated it High.
- Put not charged a fee on exercise. The protocol leaks the value it should have collected. The judge rated this Medium, describing it as "protocol leaked value".
The report's own rating was Medium, on the basis that both behaviours affect assets. The judge raised it to High because of the first consequence. The lesson for a beginner: the severity of a bug is decided by its real-world effect, and a reviewer may reasonably disagree with the reporter's first estimate.
Fix: what the report recommended
The report recommended two changes:
- Update the
ifcondition at line 498 to(fee > 0 && order.isCall && isExercised). Read it as: charge only when there is a fee, the order is a call, and it has been exercised. The added checks stop the expiry path from charging anyone. - Add fee calculation and deduction after the put is exercised and the strike is transferred at line 451, as follows:
uint256 feeAmount = 0;
if (fee > 0) {
feeAmount = (order.strike * fee) / 1000;
ERC20(order.baseAsset).safeTransfer(owner(), feeAmount);
}
ERC20(order.baseAsset).safeTransfer(msg.sender, order.strike - feeAmount);
Line by line, in plain words:
uint256 feeAmount = 0;creates a number calledfeeAmountand starts it at zero.uint256is a whole number that cannot be negative, the standard number type in Solidity.if (fee > 0) {checks whether a fee is configured at all. If the fee is zero, there is nothing to take.feeAmount = (order.strike * fee) / 1000;works out the fee: multiply the strike by the fee rate, then divide by 1000.ERC20(order.baseAsset).safeTransfer(owner(), feeAmount);sends the fee amount to the owner, meaning the protocol's own address.ERC20is the standard for tokens on these blockchains, andsafeTransferis a transfer that checks the result instead of silently failing.ERC20(order.baseAsset).safeTransfer(msg.sender, order.strike - feeAmount);sends the rest of the strike to the caller, the person exercising the option.
Putty Finance confirmed the report with the comment "Fees are only applied on puts if they are expired" and resolved it with a pull request, which is a proposed set of code changes that gets reviewed and merged.
The warden who reviewed the mitigation described the actual fix: the fee base was changed to order.premium, which is now paid uniformly for all option types on order filling. A warden on these platforms is a reviewer who checks that the fix really addresses the problem. "Order filling" means the moment the order is matched and taken up, which is earlier than exercise. The warden noted that using order.strike as the fee base was the root cause of several other findings, so the change to order.premium was a shared mitigation for all of them. In plain terms: instead of charging a percentage of the big strike amount at an unpredictable moment, the protocol now charges a percentage of the small up-front premium, at one consistent moment, for every kind of option.
Variants to test: where else to look
These are patterns a beginner can learn to recognise and then look for in other code:
- Fee applied on the wrong lifecycle event. Look for fee or royalty logic in expiry, cancellation or withdrawal paths where the documentation says it applies on exercise or settlement. A positive result is a fee charged to a user who took no action that should trigger it. Royalties are payments to a creator, and settlement is the final exchange of value in a deal.
- Fee base mismatch. Check whether fees are computed against strike, premium, notional or collateral, and compare with the comment or specification. Notional is the headline size of a deal, and collateral is the asset set aside to back it. A positive result is a fee that scales with the wrong quantity, especially one that can exceed the intended amount.
- Missing fee on the settlement path. Trace the branch that actually transfers value to the exercising party and check whether any fee deduction exists there. A positive result is a settlement transfer with no fee taken while other paths do take one.
- Asymmetric handling of calls and puts. Compare the call and put branches of the same function. A positive result is a condition that checks
isCallin one branch but not the other, or a fee applied in one and not the other. Asymmetric means the two sides are treated differently without a reason.
Hunting notes: how to find this kind of bug yourself
This kind of bug hides in fee, royalty and accounting logic around lifecycle transitions: exercise, expiry, withdrawal and settlement. Accounting logic is the part of a program that keeps track of who owes what to whom.
The strongest signal is a comment or specification that states when a fee applies, followed by code that applies it somewhere else. Comments are written by humans and often record the original intention; when the code drifts away from the comment, that gap is where bugs live. Reading the fee configuration function and its comments first, then tracing every place the fee variable is used, is a quick way to spot the mismatch. Tracing means following a variable through the code, the way you would follow a parcel's tracking number through every depot.
The researcher showed impact by tying each behaviour to a concrete asset movement: a deduction from the writer's strike on expiry, and a missing deduction on exercise. The judge rated submissions High if they mentioned the expired-put charge, or both consequences, and Medium if they mentioned only the missing charge on exercise. A clear description of who loses what is often worth more than a clever exploit.
Difficulty
The platform rated this finding as intermediate. The reason given is that the bug is a logic mismatch between documented fee intent and two code paths, requiring the reader to trace fee handling across withdraw and exercise, but no exploit tooling or live target. In other words, you do not need to run anything or attack a real system: you need to read carefully and compare what the code says with what it does.
Glossary
- Blockchain: a shared, public record of transactions kept in copies by many computers.
- Smart contract: a program that lives on a blockchain and runs automatically according to its code.
- Solidity: the programming language used to write smart contracts on Ethereum-style blockchains.
.solfile: a source code file written in Solidity.- Protocol: here, the set of smart contracts that define the rules of the service.
- On-chain: happening inside blockchain transactions and recorded there.
- Option: a deal giving one side the right, but not the obligation, to do a trade later at an agreed price.
- Call: an option giving the right to buy at the agreed price;
order.isCall == true. - Put: an option giving the right to sell at the agreed price;
order.isCall == false. - Writer / Put Shorter: the person who creates the option and puts up the collateral that backs it.
- Strike: the agreed price in the option deal, and the amount transferred when the option is exercised.
- Premium: the small amount paid up front for the option.
- Collateral: the asset set aside to back a deal.
- Exercise: using the right the option gives you.
- Expiry: the moment an option runs out and can no longer be exercised.
- Settlement: the final exchange of value in a deal.
- Order filling: the moment an order is matched and taken up by another party.
- Function: a named block of code that can be called to perform an action.
setFee(): the function that configures the admin fee rate.withdraw(): the function that lets a writer take back collateral after expiry.exercise(): the function that lets a holder use the option.ifcondition: a test the program runs before executing a block of code.- Variable: a named box in a program that holds a value.
feeAmount: the variable holding how much fee to take.uint256: a whole number type in Solidity that cannot be negative.msg.sender: the blockchain address of whoever triggered the current call.isExercised: a true/false flag recording whether an option was used.order.isCall: a true/false flag recording whether an order is a call or a put.order.strike/order.premium: the strike and premium values stored with an order.order.baseAsset: the token that the order deals in.- ERC20: the standard interface for tokens on these blockchains.
safeTransfer: a token transfer that checks the result rather than failing silently.owner(): the function returning the protocol's own address, which receives the fee.- Fee base: the quantity a fee is calculated from, such as strike or premium.
- Lifecycle event: a moment in an option's life, such as creation, exercise, expiry or withdrawal.
- Logic bug: code that runs without crashing but does something different from what was intended.
- Root cause: the underlying reason a bug exists, as opposed to its visible symptoms.
- Severity: how serious a finding is, usually based on who loses what.
- Medium / High: severity ratings; High is more serious than Medium.
- Audit: a review of code by independent researchers looking for problems.
- Code4rena: the audit platform where this finding was submitted.
- Warden: a reviewer on the audit platform who checks findings and fixes.
- Judge: the person on the audit platform who decides the severity of each finding.
- Pull request: a proposed set of code changes that gets reviewed before being merged.
- Mitigation: a change that reduces or removes the impact of a bug.
- Notional: the headline size of a deal, used as a reference amount.
- Royalty: a payment made to a creator, often on each sale.
- Asymmetric: treating two comparable cases differently without a stated reason.
- Tracing: following a value or variable through the code step by step.