Skip to content
Business logic Audit finding Intermediate

Put options are free of any fees

The protocol failed to deduct fees when a put option was exercised, so put options were free of fees. An attacker could exercise put options without paying the protocol fee, causing the protocol to leak value.

berndartmueller Follow

Originally disclosed on Code4rena

Submitted by berndartmueller, also found by 0xsanson, hubble, Lambda, Metatron, and swit

Fees are expected to be paid whenever an option is exercised (as per the function comment on L235).

Put options

If a put option is exercised, the exerciser receives the strike price (initially deposited by the short position holder) denominated in order.baseAsset.

Call options

If a call option is exercised, the exerciser sends the strike price to Putty and the short position holder is able to withdraw the strike amount.

However, the current protocol implementation is missing to deduct fees for exercised put options. Put options are free of any fees.

Proof of Concept

The protocol fee is correctly charged for exercised calls:

PuttyV2.withdraw

// transfer strike to owner if put is expired or call is exercised
if ((order.isCall && isExercised) || (!order.isCall && !isExercised)) {
    // send the fee to the admin/DAO if fee is greater than 0%
    uint256 feeAmount = 0;
    if (fee > 0) {
        feeAmount = (order.strike * fee) / 1000;
        ERC20(order.baseAsset).safeTransfer(owner(), feeAmount); // @audit DoS due to reverting erc20 token transfer (weird erc20 tokens, blacklisted or paused owner; erc777 hook on owner receiver side can prevent transfer hence reverting and preventing withdrawal) - use pull pattern @high  // @audit zero value token transfers can revert. Small strike prices and low fee can lead to rounding down to 0 - check feeAmount > 0 @high  // @audit should not take fees if renounced owner (zero address) as fees can not be withdrawn @medium
    }

    ERC20(order.baseAsset).safeTransfer(msg.sender, order.strike - feeAmount); // @audit fee should not be paid if strike is simply returned to short owner for expired put @high

    return;
}

Contrary, put options are free of any fees:

PuttyV2.sol#L450-L451

// transfer strike from putty to exerciser
ERC20(order.baseAsset).safeTransfer(msg.sender, order.strike);

Recommended Mitigation Steps

Charge fees also for exercised put options.

outdoteth (Putty Finance) commented:

Fees are only applied on puts if they are expired.

HickupHH3 (judge) commented:

Making this the primary issue for the med severity issue, as per my comment in #269:

“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.”

outdoteth (Putty Finance) confirmed and resolved:

PR with fix: https://github.com/outdoteth/putty-v2/pull/4.

hyh (warden) reviewed mitigation:

The same fix as in H-01.


The original report as published on Code4rena, by berndartmueller. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 5 min read.

Context

Putty is an on-chain options protocol. The audited code is PuttyV2.sol, and the feature in scope here is the fee handling around option exercise and withdrawal. The protocol charges a fee, expressed in per-mille (fee divided by 1000), on the strike amount in the withdrawal path. The function comment on PuttyV2.sol line 235 states that fees are expected to be paid whenever an option is exercised.

The two option types behave differently in terms of asset flow:

  • Put options: when exercised, the exerciser receives the strike price, which was initially deposited by the short position holder, denominated in order.baseAsset.
  • Call options: when exercised, the exerciser sends the strike price to Putty, and the short position holder is able to withdraw the strike amount.

The finding is that the implementation deducts the fee for exercised calls but not for exercised puts. Put options are free of any fees.

Setup

This is a Code4rena audit finding against the Putty codebase, so there are no accounts, roles or live endpoints to configure. The relevant preconditions are simply the state of an order at exercise and withdrawal time:

  • an order with a fee value greater than zero, so that a fee is expected to be charged;
  • an exercised put option, where the strike is transferred from Putty to the exerciser;
  • an exercised call option, where the strike is transferred to the short position holder after the fee is deducted.

The report references the source at commit [redacted].

Finding it

The researcher compared the documented expectation (fees are paid whenever an option is exercised) with the two code paths that move the strike. The call path charges the fee; the put path does not. The discrepancy is visible by reading the two transfers side by side.

Exploitation

Step 1: confirm the fee is charged for exercised calls

The withdrawal function handles the transfer of the strike to the owner when a put is expired or a call is exercised. The fee is computed there and sent to the admin/DAO before the remainder goes to the caller.

PuttyV2.withdraw:

Text
// transfer strike to owner if put is expired or call is exercised
if ((order.isCall && isExercised) || (!order.isCall && !isExercised)) {
    // send the fee to the admin/DAO if fee is greater than 0%
    uint256 feeAmount = 0;
    if (fee > 0) {
        feeAmount = (order.strike * fee) / 1000;
        ERC20(order.baseAsset).safeTransfer(owner(), feeAmount); // @audit DoS due to reverting erc20 token transfer (weird erc20 tokens, blacklisted or paused owner; erc777 hook on owner receiver side can prevent transfer hence reverting and preventing withdrawal) - use pull pattern @high  // @audit zero value token transfers can revert. Small strike prices and low fee can lead to rounding down to 0 - check feeAmount > 0 @high  // @audit should not take fees if renounced owner (zero address) as fees can not be withdrawn @medium
    }

    ERC20(order.baseAsset).safeTransfer(msg.sender, order.strike - feeAmount); // @audit fee should not be paid if strike is simply returned to short owner for expired put @high

    return;
}

The important parts for this finding are the fee calculation feeAmount = (order.strike * fee) / 1000 and the transfer of order.strike - feeAmount to msg.sender. The inline audit comments in the snippet concern separate issues (reverting token transfers, zero-value transfers, a renounced owner, and fees on expired puts) and are not part of this finding.

Step 2: compare with the exercised put path

The put exercise path transfers the full strike to the exerciser with no fee deduction at all:

PuttyV2.sol#L450-L451:

Text
// transfer strike from putty to exerciser
ERC20(order.baseAsset).safeTransfer(msg.sender, order.strike);

There is no feeAmount computation and no transfer to owner(). The exerciser receives order.strike in full, so the protocol collects nothing on an exercised put.

Root cause

The fee logic lives only in the withdrawal branch that covers exercised calls and expired puts. The branch that pays out an exercised put transfers order.strike directly and never applies the fee per-mille calculation. The existing fee code therefore does not cover every exercise path, contrary to the documented expectation on line 235.

Impact

The protocol leaks the fee it should collect on every exercised put option. The value at stake is the fee amount, (order.strike * fee) / 1000, per exercised put, which the protocol does not collect. The judge treated this as "protocol leaked value" and rated it medium severity, making this report the primary issue for that severity.

Fix

Putty Finance confirmed and resolved the issue with a pull request: https://github.com/outdoteth/putty-v2/pull/4. The recommended mitigation in the report is to charge fees also for exercised put options. A warden reviewing the mitigation noted that it is the same fix as in H-01. The report does not include the diff.

Variants to test

  • Other exercise paths that bypass the shared fee code. Look for any branch that transfers the strike or collateral directly rather than going through the function that computes feeAmount. A positive result is a transfer of the full amount with no corresponding transfer to owner().
  • Fee applied on the wrong event. The inline comments in the snippet flag that a fee should not be paid when the strike is simply returned to the short owner for an expired put. Check whether the fee condition matches the economic event. A positive result is a fee charged or omitted on an event the documentation does not describe.
  • Rounding to zero. With small strike prices and a low fee, (order.strike * fee) / 1000 can round down to zero. A positive result is a fee-bearing order where the computed fee is zero.
  • Fee recipient edge cases. Check behaviour when owner() is the zero address (renounced ownership) or a contract that rejects the transfer. A positive result is a fee that cannot be withdrawn or a withdrawal that reverts.

Hunting notes

Fee and royalty logic is a good place to look in any protocol that has more than one payout path: exercise versus expiry, call versus put, direct claim versus pull pattern. The signal during review is a documented invariant (here, a function comment stating fees are paid on exercise) that is enforced in one branch but not its sibling. Comparing every transfer of the same asset against the fee calculation quickly shows which paths skip it. To show impact, quantify the leaked amount per action and point to the documented expectation that is violated; in this case the judge accepted it as leaked protocol value at medium severity.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 11 min read.

What happened, in plain words

Putty is a protocol whose smart contracts run on a blockchain (a shared, public record of transactions that many computers keep in sync). It lets two people make a deal about an "option". An option is a contract that gives one side the right to do something later, at a price agreed now. Putty handles two kinds of option, called a put and a call, and it is supposed to take a small cut, a fee, whenever an option is used ("exercised").

The bug is simple to state: when someone exercises a put option, Putty pays out the full amount and forgets to take its fee. When someone exercises a call option, the fee is taken correctly. So one of the two paths does not collect the fee the protocol expects. The person who found it read the code, compared the two paths side by side, and showed that the documented rule ("fees are paid whenever an option is exercised") is only half implemented.

This was found during a Code4rena audit, which is a public contest where many independent reviewers read a project's code and report problems, and the best reports are rewarded. The finding was rated medium severity, and the Putty team confirmed it and shipped a fix.

Background you need first

A few ideas come up again and again, so here they are from zero.

  • Smart contract: a program that lives on a blockchain. Once deployed, anyone can call its functions, and the code runs exactly as written. Think of a vending machine bolted to the pavement: anyone can press buttons, and the machine follows its own rules.
  • Token: a digital asset tracked by a smart contract. An ERC20 token is the common standard for such assets, so a contract can move tokens between addresses with a call like ERC20(asset).safeTransfer(who, amount). Think of it as a standardised way of saying "move this many units of this currency to this account".
  • Address: an account identifier on the blockchain, like an account number. msg.sender means "the address that called this function right now". owner() is a function that returns the address in charge of the contract, here the admin or DAO (a decentralised autonomous organisation, a group that governs by on-chain vote).
  • Strike price: the amount of money agreed in the option deal. In the code it is order.strike.
  • Base asset: the token the deal is denominated in, here order.baseAsset.
  • Short position holder: the person who sold or wrote the option. They put up the money or asset that backs the deal.
  • Exerciser: the person on the other side who chooses to use (exercise) the option.
  • Fee: the protocol's cut. Here it is expressed in per-mille, meaning "parts per thousand". A fee of 5 means 5/1000, or 0.5 percent. That is why the code divides by 1000.
  • Put option: the exerciser receives the strike price. The money was deposited up front by the short position holder, in order.baseAsset.
  • Call option: the exerciser pays the strike price into Putty, and the short position holder can then withdraw that amount.
  • Audit finding: a written report of one problem, with evidence and a suggested fix.

The setup

Because this is a code review and not a live attack, there are no accounts to create, no logins and no web addresses to visit. The "setup" is just the situation in which the bug appears:

  1. An order exists with a fee value greater than zero, so a fee is genuinely expected.
  2. A put option on that order is exercised, so the strike is paid out from Putty to the exerciser.
  3. A call option on a similar order is exercised, so the strike goes to the short position holder after the fee is removed.

The report points at a specific version of the source code, identified by the commit [redacted]. A commit is a saved snapshot of a codebase, so this pins down exactly which lines were reviewed.

Finding it

The reviewer did something any careful reader can do: they took the written promise in the code and checked every place that moves money against it. The promise is a comment on line 235 of PuttyV2.sol, which says fees are expected to be paid whenever an option is exercised. A comment is text in the source that the computer ignores but humans read, so it acts as documentation of intent.

Then they looked at the two code paths that pay out the strike. The call path subtracts the fee. The put path does not. The mismatch is visible just by reading the two transfers next to each other, which is why this kind of review is often called "reading for invariants": an invariant is a rule that should always hold, and here the rule is broken in one branch.

Walking through the code

Step 1: the call path does charge the fee

The withdrawal function handles paying the strike to the owner when a put has expired or a call has been exercised. It works out the fee there, sends it to the admin/DAO, and sends the rest to the caller.

PuttyV2.withdraw:

Text
// transfer strike to owner if put is expired or call is exercised
if ((order.isCall && isExercised) || (!order.isCall && !isExercised)) {
    // send the fee to the admin/DAO if fee is greater than 0%
    uint256 feeAmount = 0;
    if (fee > 0) {
        feeAmount = (order.strike * fee) / 1000;
        ERC20(order.baseAsset).safeTransfer(owner(), feeAmount); // @audit DoS due to reverting erc20 token transfer (weird erc20 tokens, blacklisted or paused owner; erc777 hook on owner receiver side can prevent transfer hence reverting and preventing withdrawal) - use pull pattern @high  // @audit zero value token transfers can revert. Small strike prices and low fee can lead to rounding down to 0 - check feeAmount > 0 @high  // @audit should not take fees if renounced owner (zero address) as fees can not be withdrawn @medium
    }

    ERC20(order.baseAsset).safeTransfer(msg.sender, order.strike - feeAmount); // @audit fee should not be paid if strike is simply returned to short owner for expired put @high

    return;
}

Line by line, in plain words:

  1. The first comment says what this block is for: moving the strike to the owner when a put has expired or a call has been exercised.
  2. The if line is the gate. It opens when the order is a call and it was exercised, or when the order is not a call (so a put) and it was not exercised (so it expired). Only those two situations reach the code below.
  3. uint256 feeAmount = 0; creates a number called feeAmount, starting at zero. uint256 just means a whole number that cannot be negative.
  4. if (fee > 0) checks whether a fee is configured at all. If the fee is zero, there is nothing to take.
  5. feeAmount = (order.strike * fee) / 1000; is the actual calculation: multiply the strike by the fee, then divide by 1000 to convert per-mille into an amount. With a strike of 1000 and a fee of 5, the fee is 5.
  6. ERC20(order.baseAsset).safeTransfer(owner(), feeAmount); moves that fee amount of the base asset to the contract owner, the admin/DAO. This is the line that actually collects the protocol's cut.
  7. The long // @audit ... text after it is a note left by a reviewer about other, separate concerns: token transfers that can fail and block withdrawals, transfers of zero that some tokens reject, and fees when ownership has been renounced. Those are different findings and not the subject here.
  8. ERC20(order.baseAsset).safeTransfer(msg.sender, order.strike - feeAmount); sends the strike minus the fee to whoever called the function. The subtraction is the key detail: the fee has already been carved out.
  9. The trailing // @audit note here flags that a fee should not be charged when the strike is simply returned to the short owner for an expired put. Again, a separate point.
  10. return; ends the function, so nothing after this block runs for these cases.

The two lines that matter for this finding are the fee calculation and the transfer of order.strike - feeAmount. Together they show the fee being taken on the call path.

Step 2: the put path takes nothing

The path that pays out an exercised put transfers the whole strike to the exerciser, with no fee deducted at all:

PuttyV2.sol#L450-L451:

Text
// transfer strike from putty to exerciser
ERC20(order.baseAsset).safeTransfer(msg.sender, order.strike);

Line by line:

  1. The comment states the intent: move the strike from Putty to the exerciser.
  2. The single transfer sends order.strike in full to msg.sender. There is no feeAmount, no multiplication, no division by 1000, and no transfer to owner().

So the exerciser receives the entire strike and the protocol receives nothing. That is the bug in one sentence.

Why it happens

The fee logic sits only in the withdrawal branch that covers exercised calls and expired puts. The branch that pays out an exercised put sends order.strike directly and never runs the per-mille calculation. The fee code therefore does not cover every exercise path, which contradicts the documented expectation on line 235.

A useful comparison: imagine a shop with two tills. One till automatically adds the service charge to every bill, the other just hands over the goods. Both tills look fine on their own, but only one of them follows the shop's stated policy.

What it costs

The protocol loses the fee it should collect on every exercised put option. The amount at stake is (order.strike * fee) / 1000 per exercised put, which the protocol does not collect. The judge on the audit treated this as "protocol leaked value" and rated it medium severity, and made this report the primary issue for that severity level.

The fix

Putty Finance confirmed and resolved the issue with a pull request at https://github.com/outdoteth/putty-v2/pull/4. A pull request is a proposed change to a codebase that can be reviewed before it is merged. The recommendation in the report is straightforward: charge fees also for exercised put options. A reviewer checking the mitigation noted that it is the same fix as in another finding, H-01. The report does not include the actual code change.

Other places to look

These are follow-up checks for anyone reviewing similar fee logic:

  1. Other payout paths that skip the shared fee code. Look for any branch that sends the strike or collateral directly instead of going through the function that computes feeAmount. A positive result is a transfer of the full amount with no matching transfer to owner().
  2. Fee charged on the wrong event. The inline comments note that a fee should not be paid when the strike is simply returned to the short owner for an expired put. Check whether the fee condition matches the economic event. A positive result is a fee charged, or omitted, on an event the documentation does not describe.
  3. Rounding down to zero. With small strike prices and a low fee, (order.strike * fee) / 1000 can round down to zero. A positive result is a fee-bearing order where the computed fee is zero.
  4. Fee recipient edge cases. Check what happens when owner() is the zero address (ownership renounced) or a contract that rejects the transfer. A positive result is a fee that cannot be withdrawn, or a withdrawal that fails.

Notes for anyone hunting similar bugs

Fee and royalty logic is a good place to look in any protocol with more than one payout path: exercise versus expiry, call versus put, direct claim versus a pull pattern (where the recipient later comes to collect rather than being sent funds immediately). The signal during review is a documented invariant, here a function comment saying fees are paid on exercise, that is enforced in one branch but not its sibling. Comparing every transfer of the same asset against the fee calculation quickly shows which paths skip it. To show impact, quantify the leaked amount per action and point to the documented expectation that is violated. In this case the judge accepted it as leaked protocol value at medium severity.

Glossary

  • Address: an account identifier on a blockchain, like an account number.
  • Audit finding: a written report of one problem in code, with evidence and a suggested fix.
  • Base asset: the token a deal is denominated in, here order.baseAsset.
  • Blockchain: a shared, public record of transactions kept in sync by many computers.
  • Call option: an option where the exerciser pays the strike price into the protocol and the short position holder can withdraw it.
  • Code4rena: a public contest platform where reviewers audit code and the best reports are rewarded.
  • Comment: text in source code that the computer ignores but humans read, often documenting intent.
  • Commit: a saved snapshot of a codebase, identified by a hash, pinning down exactly which version was reviewed.
  • DAO: a decentralised autonomous organisation, a group that governs by on-chain vote.
  • ERC20: the common standard for tokens on a blockchain, allowing standard transfers between addresses.
  • Exerciser: the person who chooses to use (exercise) an option.
  • Fee: the protocol's cut of an amount, here expressed in per-mille.
  • Invariant: a rule that should always hold true, which code must enforce everywhere it applies.
  • Medium severity: a rating for a bug that leaks value or causes limited harm, below critical but worth fixing.
  • Option: a deal giving one side the right to do something later at a price agreed now.
  • Owner: the address in charge of a contract, here the admin or DAO, returned by owner().
  • Per-mille: parts per thousand, so a fee of 5 means 5/1000, or 0.5 percent.
  • Pull pattern: a design where recipients collect funds themselves later, rather than being sent funds immediately.
  • Pull request: a proposed change to a codebase that can be reviewed before merging.
  • Put option: an option where the exerciser receives the strike price, deposited up front by the short position holder.
  • Short position holder: the person who sold or wrote the option and put up the backing funds or asset.
  • Smart contract: a program on a blockchain that anyone can call and that runs exactly as written.
  • Strike price: the amount of money agreed in the option deal, here order.strike.
  • msg.sender: the address that called the current function.
  • uint256: a whole number type in the code that cannot be negative.

More by berndartmueller

View all

97 more disclosed reports, best first.

More from Putty

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.