Skip to content
Business logic Audit finding Intermediate

fee can change without the consent of users

Fees are applied only when a user withdraws, so the contract owner could raise the fee after an order was agreed and filled, and users would then pay the higher rate on withdrawal. This could cause users to lose funds they expected to keep, since they would not have entered the order at the higher fee.

Picodes Follow

Originally disclosed on Code4rena

Submitted by Picodes, also found by 0xNineDec, 0xsanson, antonttc, berndartmueller, BowTiedWardens, catchup, dirky, Alex the Entreprenerd, horsefacts, Metatron, sseefried, and unforgiven_

https://github.com/code-423n4/2022-06-putty/blob/3b6b844bc39e897bd0bbb69897f2deff12dc3893/contracts/src/PuttyV2.sol#L240

https://github.com/code-423n4/2022-06-putty/blob/3b6b844bc39e897bd0bbb69897f2deff12dc3893/contracts/src/PuttyV2.sol#L497

Impact

Fees are applied during withdraw, but can change between the time the order is filled and its terms are agreed upon and the withdrawal time, leading to a loss of the expected funds for the concerned users.

Proof of Concept

The scenario would be:

  • Alice and Bob agrees to fill an order at a time fees are 0.1%
  • During the duration of the option, fees are increased to 3%
  • At withdrawal they’ll pay 3% of the strike, although they wouldn’t have created the order in the first place with such fees

Recommended Mitigation Steps

Mitigation could be:

  • Store the fees in Order and verify that they are correct when the order is filled, so they are hardcoded in the struct
  • Add a timestamp: this wouldn’t fully mitigate but would still be better than the current setup
  • Keep past fees and fee change timestamps in memory (for example in an array) to be able to retrieve the creation time fees at withdrawal

outdoteth (Putty Finance) confirmed and commented:

Report: Admin can change fee at any time for existing orders.

outdoteth (Putty Finance) 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 Picodes. 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. 4 min read.

Context

Putty is a peer-to-peer options protocol. The finding concerns PuttyV2, the main contract of the V2 codebase, and specifically the fee handling around order withdrawal. Fees are not fixed at the moment an order is created or filled: they are applied when funds are withdrawn. Fees are applied during withdraw, so a fee change between fill and withdrawal affects what the parties pay.

The report points at two places in the contract:

  • contracts/src/PuttyV2.sol#L240
  • contracts/src/PuttyV2.sol#L497

The report points at these two lines in the contract. The report's mitigations suggest the order does not record the fee in force when agreed.

Setup

No accounts, tools or versions are described in the report. The precondition is simply that the protocol admin can change the fee, and that an order can remain open (an option has a duration) across a fee change. The scenario involves two parties, Alice and Bob, who agree to fill an order.

Finding it

Fees are applied during withdraw rather than being fixed when the order is filled. Because an option lives for a duration, there is a window between the moment the parties agree to the terms and the moment they withdraw, and the fee can be changed inside that window.

Exploitation

Step 1: agree on terms at the current fee

Alice and Bob agree to fill an order at a time when fees are 0.1%.

Step 2: the fee changes during the option's life

During the duration of the option, fees are increased to 3%.

Step 3: withdraw at the new fee

At withdrawal they pay 3% of the strike, although they would not have created the order in the first place with such fees.

The loss falls on the users who agreed to the original terms: they receive the expected funds minus a fee they never consented to. The report frames this as a loss of expected funds for the concerned users.

Root cause

The fee is read and applied at withdrawal time, and the Order struct does not store the fee that applied when the order was agreed. The report's mitigation options make the design gap explicit: storing fees in Order and verifying them when the order is filled, adding a timestamp, or keeping past fees and fee change timestamps in memory (for example in an array) so the creation-time fee can be retrieved at withdrawal. The report proposes these mitigations, implying the current design does not bind the fee to the order.

Impact

Users who filled an order under one fee schedule can be charged a higher fee at withdrawal, losing part of the funds they expected. The report's example is a move from 0.1% to 3% of the strike. The condition is that the fee changes between the time the order is filled and the withdrawal. The report does not describe any other impact.

Fix

The Putty Finance team confirmed the issue, describing it as: "Admin can change fee at any time for existing orders." The team resolved the issue, linking a pull request with the fix:

Text
https://github.com/outdoteth/putty-v2/pull/4

A warden reviewing the mitigation noted that it is the same fix as in H-01. The report itself lists three possible mitigations:

  1. Store the fees in Order and verify that they are correct when the order is filled, so they are hardcoded in the struct.
  2. Add a timestamp: this would not fully mitigate but would still be better than the current setup.
  3. Keep past fees and fee change timestamps in memory (for example in an array) to be able to retrieve the creation time fees at withdrawal.

Variants to test

  • A positive result is a struct that lacks the field, plus a setter the admin can call while positions are open.
  • Check whether fee changes apply retroactively to already-filled orders. A positive result is a withdrawal whose payout differs from the terms agreed at fill time.
  • Check whether a timestamp is recorded but not used to select the historical fee. A positive result is a timestamp present in the struct while the payout still uses the current fee.
  • Check other admin-controlled parameters (fees, caps, thresholds) that are consumed at claim time. A positive result is a value change that alters the payout of an existing position.

Hunting notes

During review, the signal is a struct that records the parties and terms but not the fee, combined with an admin setter for that fee. The report illustrates the impact with a two-party scenario and a fee change inside the option's duration.

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. 10 min read.

What happened, in plain words

Putty is a service, built on a blockchain, where two people can make a deal about an "option". An option is a contract that gives someone the right to buy or sell something at a fixed price (called the "strike") within a set period of time. Putty lets two users, say Alice and Bob, agree on such a deal directly with each other, without a middleman. The software that runs the deal is a "smart contract": a program that lives on the blockchain and executes automatically according to its code.

Putty charges a fee on these deals. The problem this report describes is simple to state: the fee is not fixed at the moment Alice and Bob agree to their deal. It is taken later, when the money is withdrawn. In between those two moments, the person who runs Putty (the "admin") can change the fee. If the fee goes up, Alice and Bob end up paying the new, higher fee even though they agreed to the old one. The report calls this "fee can change without the consent of users".

This is a beginner's walkthrough of the finding. It explains every term as it comes up, follows the same steps as the technical write-up, and ends with a glossary.

Context: what Putty is and where the problem lives

Putty is described as a "peer-to-peer options protocol". Breaking that down:

  • Peer-to-peer means two users deal with each other directly. There is no central exchange holding the money in the middle.
  • Options are financial agreements about a future purchase or sale at a price fixed today.
  • Protocol here means the set of smart contracts (programs on the blockchain) that make the service work.

The finding concerns PuttyV2, the main contract of the second version of the codebase. A "contract" in this context is a program deployed on the blockchain. Its code is public and its rules are enforced by the network, not by a company's servers.

The specific area is "fee handling around order withdrawal". Two ideas need explaining:

  • An order is the record of the deal: who is involved, what the terms are, and so on. In the code it is stored in something called a struct, which is a way of grouping several pieces of data under one name, like a form with several fields.
  • Withdrawal is the step where the funds are taken out of the contract and sent to the users.

The key fact: fees are not fixed at the moment an order is created or filled. They are applied when funds are withdrawn. Fees are applied when funds are withdrawn, so a fee change before then affects what the parties pay.

Think of it like a restaurant where the menu price is not printed on your order slip. You order a meal at one price, and when you leave, the bill is calculated using whatever price the owner has set that evening. If the owner raised prices while you were eating, you pay the new price.

The report points at two places in the contract:

  • contracts/src/PuttyV2.sol#L240
  • contracts/src/PuttyV2.sol#L497

These are file locations: PuttyV2.sol is the source file, and #L240 and #L497 mean line 240 and line 497 of that file. The report points at these two lines in the contract. The report's mitigations suggest the order does not record the fee in force when agreed. In other words, the form that records the deal has fields for the parties and the terms, but no field for "the fee we agreed to".

Setup: what you need for this to happen

The report does not describe any accounts, tools or software versions. You do not need to install anything to understand it. The precondition is simply two facts about how the system works:

  1. The protocol admin can change the fee.
  2. An order can remain open across a fee change. This is possible because an option has a duration: it lives for a period of time, so there is a gap between the moment the deal is agreed and the moment the funds are withdrawn.

The scenario involves two parties, Alice and Bob, who agree to fill an order. "Filling" an order means accepting its terms and completing the deal.

Finding it: how the researcher spotted the problem

Fees are applied during withdraw rather than being fixed when the order is filled. Because an option lives for a duration, there is a window between the moment the parties agree to the terms and the moment they withdraw. The fee can be changed inside that window.

This is the core of the bug. It is not a broken lock or a stolen password. It is a design gap: a value that should be locked in at the time of agreement is instead read fresh at the time of payment.

Exploitation: the three steps

Step 1: agree on terms at the current fee

Alice and Bob agree to fill an order at a time when fees are 0.1%.

0.1% is one part in a thousand. On a strike of, say, 1,000 units, that would be 1 unit of fee. The exact numbers do not matter for understanding the bug; what matters is that Alice and Bob saw this fee and decided the deal was worth doing at that cost.

Step 2: the fee changes during the option's life

During the duration of the option, fees are increased to 3%.

3% is thirty times larger than 0.1%. The admin makes this change while the option is still running. Alice and Bob are not asked, and the order they already agreed to does not record the old fee anywhere, so nothing stops the new fee from applying to their deal.

Step 3: withdraw at the new fee

At withdrawal they pay 3% of the strike, although they would not have created the order in the first place with such fees.

The loss falls on the users who agreed to the original terms: they receive the expected funds minus a fee they never consented to. The report frames this as a loss of expected funds for the concerned users.

Going back to the restaurant comparison: you agreed to a meal at one price, the owner raised prices while you were eating, and the bill at the door uses the new price. You would not have sat down if you had known.

Root cause: why the bug exists

The fee is read and applied at withdrawal time, and the Order struct does not store the fee that applied when the order was agreed. Those two facts together are the root cause.

The report's mitigation options make the design gap explicit. It suggests three possible fixes:

  1. Store the fees in Order and verify that they are correct when the order is filled, so they are hardcoded in the struct.
  2. Add a timestamp: this would not fully mitigate but would still be better than the current setup.
  3. Keep past fees and fee change timestamps in memory (for example in an array) to be able to retrieve the creation time fees at withdrawal.

A "timestamp" is a record of when something happened, like the date and time printed on a receipt. An "array" is an ordered list of values held in the program's memory, like a column of numbers in a spreadsheet.

The report proposes these mitigations, implying the current design does not bind the fee to the order. "Silently" is the important word: no error is raised, no warning is shown, the payout is simply smaller than expected.

Impact: what users actually lose

Users who filled an order under one fee schedule can be charged a higher fee at withdrawal, losing part of the funds they expected. The report's example is a move from 0.1% to 3% of the strike. The condition is that the fee changes between the time the order is filled and the withdrawal. The report does not describe any other impact.

In a bug bounty or audit context, severity is a rough label for how much damage a bug can do and how likely it is to happen. Medium sits in the middle: not a total loss of funds for everyone, but a real financial loss for the users involved, caused by a design choice rather than a mistake by the users.

Fix: what the team did

The Putty Finance team confirmed the issue, describing it as: "Admin can change fee at any time for existing orders." That one sentence is a good summary: the admin's power to change the fee reaches back into orders that already exist.

The team resolved the issue, linking a pull request with the fix:

Text
https://github.com/outdoteth/putty-v2/pull/4

A "pull request" is a proposal to change code, stored on a code-hosting site so that others can review it before it is merged. The link above points to the proposed fix.

A warden reviewing the mitigation noted that it is the same fix as in H-01. A "warden" is the term this audit competition uses for a security researcher taking part. H-01 is the label of another finding in the same competition, and the reviewer is saying the code change made for this issue is the same one made for that issue.

The report itself lists three possible mitigations:

In plain terms: option 1 writes the agreed fee onto the order form itself, so it cannot drift. Option 2 records when the order was made, which helps but does not by itself tell you which fee was in force then. Option 3 keeps a history of fee changes, so at withdrawal the contract can look up the fee that applied when the order was created.

Variants to test: where else this pattern hides

  • Look for any fee, royalty or parameter read at settlement or withdrawal time rather than snapshotted into the order or position struct. A positive result is a struct that lacks the field, plus a setter the admin can call while positions are open. A "setter" is a function that changes a stored value. "Snapshotted" means copied and frozen at a point in time.
  • Check whether fee changes apply retroactively to already-filled orders. A positive result is a withdrawal whose payout differs from the terms agreed at fill time. "Retroactively" means applying to things that already happened.
  • Check whether a timestamp is recorded but not used to select the historical fee. A positive result is a timestamp present in the struct while the payout still uses the current fee.
  • Check other admin-controlled parameters (fees, caps, thresholds) that are consumed at claim time. A positive result is a value change that alters the payout of an existing position. A "cap" is an upper limit and a "threshold" is a cut-off point; both are examples of settings an admin might change.

Hunting notes: how to spot this yourself

"Global state" means settings that apply to the whole system rather than to one user's deal.

During review, the signal is a struct that records the parties and terms but not the fee, combined with an admin setter for that fee. If you see a form that lists who and what but not the price, and you see a function that lets an admin change the price, you have a candidate.

The report illustrates the impact with a two-party scenario and a fee change inside the option's duration. A clear story with named parties and a specific before-and-after number is often what turns a suspicion into an accepted finding.

Glossary

  • Admin: the account with special permission to change settings in the protocol, such as the fee.
  • Array: an ordered list of values held in a program, like a column in a spreadsheet.
  • Blockchain: a shared record of transactions maintained by many computers, where deployed programs run and cannot be quietly altered afterwards.
  • Cap: an upper limit on a value.
  • Contract (smart contract): a program deployed on a blockchain that executes automatically according to its code.
  • Duration: the length of time an option remains open.
  • Fee: the amount the protocol charges on a deal, here expressed as a percentage of the strike.
  • Fill (an order): to accept an order's terms and complete the deal.
  • Global state: settings that apply to the whole system rather than to a single user's position.
  • Option: an agreement giving one party the right to buy or sell at a fixed price within a set period.
  • Order: the record of a deal, including the parties and terms.
  • Peer-to-peer: two users dealing directly with each other, without a central intermediary.
  • Protocol: the set of smart contracts and rules that make a service work.
  • Pull request: a proposed code change hosted for review before it is merged.
  • Retroactively: applying to things that already happened.
  • Setter: a function that changes a stored value.
  • Severity: a label for how much damage a bug can cause and how likely it is.
  • Snapshot: a copy of a value frozen at a particular moment.
  • Strike: the fixed price at which an option can be exercised.
  • Struct: a way of grouping several related pieces of data under one name, like a form with fields.
  • Threshold: a cut-off point.
  • Timestamp: a record of when something happened.
  • Warden: the term this audit competition uses for a participating security researcher.
  • Withdrawal: the step where funds are taken out of the contract and sent to users.

More by Picodes

View all

17 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.