Order cancellation is prone to frontrunning and is dependent on a centralized database
Order cancellation requires calling a function with the full order parameters, which are stored in a centralised database. If that database goes offline, makers cannot cancel, and an attacker with a copy of the orders could fill them on favourable terms.
Submitted by shung, also found by unforgiven
Order cancellation requires makers to call cancel(), inputting the order as a function parameter. This is the only cancellation method, and it can cause two issues.
This first issue is that it is an on-chain signal for MEV users to frontrun the cancellation and fill the order.
The second issue is the dependency to a centralized service for cancelling the order. As orders are signed off chain, they would be stored in a centralized database. It is unlikely that an end user would locally record all the orders they make. This means that when cancelling an order, maker needs to request the order parameters from the centralized service. If the centralized service goes offline, it could allow malicious parties who have a copy of the order database to fill orders that would have been cancelled otherwise.
Proof of Concept
- Bob signs an order which gets recorded in Putty servers.
- Alice mirrors all the orders using Putty APIs.
- Putty servers go offline.
- Bob wants to cancel his order because changing token prices makes his order less favourable to him.
- Bob cannot cancel his order because Putty servers are down and he does not remember the exact amounts of tokens he used.
- Alice goes through all the orders in her local mirror and fulfills the non-cancelled orders, including Bob’s, with extremely favourable terms for herself.
Recommended Mitigation Steps
Aside from the standard order cancellation method, have an extra method to cancel all orders of a caller. This can be achieved using a “minimum valid nonce” state variable, as a mapping from user address to nonce.
mapping(address => uint256) minimumValidNonce;
Allow users to increment their minimumValidNonce. Make sure the incrementation function do not allow incrementing more than 2**64 such that callers cannot lock themselves out of creating orders by increasing minimumValidNonce to 2**256-1 by mistake. Then, prevent filling orders if order.nonce < minimumValidNonce.
Another method to achieve bulk cancelling is using counters. For example, Seaport uses counters, which is an extra order parameter that has to match the corresponding counter state variable. It allows maker to cancel all his orders by incrementing the counter state variable by one.
Either of these extra cancellation methods would enable cancelling orders without signalling to MEV bots, and without a dependency to a centralized database.
outdoteth (Putty Finance) confirmed and commented:
Should this be tagged as Med or Low? Funds are not directly at risk unless the centralised order book server goes down and loses all the data. Perhaps there is a non-negligible chance that this could happen. But even then, orders have an “expiration” field attached to them which will render them useless after some set time period. There are also easy fixes on the frontend, such as allowing users to download a txt file with their order/orderHash so that they don’t have to rely on the centralised DB for data availability.
But will defer to judges.
Report: Cannot cancel orders without reliance on centralised database.
The sponsor’s point is valid: there is an expiration param that the maker signs as part of the order that marks its validity.
However, the warden(s) concerns are valid too. While it is an edge case that is very unlikely to happen, there would arguably be a “loss” of assets of the maker because of the protocol’s loss of functionality, as per the scenario described above. Hence, the medium severity rating is justified.
I recommend implementing the warden’s recommended fix; having a
minimumValidNoncewould be great in allowing easy on-chain cancellation of an order. It makes the system a little more trust-less and provides a “red button” option for makers to use if necessary.
outdoteth (Putty Finance) resolved:
PR with fix: https://github.com/outdoteth/putty-v2/pull/10.
hyh (warden) reviewed mitigation:
Fixed by the introduction of
setMinimumValidNoncefunction and the corresponding control on order filling. See M.M-04 in the Mitigation Review below.
Context
Putty is an order-based trading protocol. Makers sign orders off chain, and those signed orders are recorded and served by Putty's centralised servers. A maker who wants to withdraw an order before it is filled has to cancel it on chain by calling cancel() and passing the order itself as a function parameter. That is the only cancellation path described in the report.
The finding, submitted by shung (and also found by unforgiven) against the Putty codebase in the Code4rena audit, argues that this single cancellation mechanism creates two separate problems: it broadcasts an on-chain signal that MEV searchers can frontrun, and it makes cancellation depend on a centralised database staying available.
Setup
The report does not describe a specific deployment, toolchain or set of accounts used to reproduce the issue. The reasoning is about the design of the cancellation flow rather than a live exploit against a running instance. The actors in the proof of concept are Bob, a maker who signs orders, and Alice, a party who mirrors the order book through Putty's APIs.
Finding it
The researcher started from the observation that cancel() takes the order as a parameter. To cancel, the maker must therefore supply the exact order parameters. Because orders are signed off chain and stored in a centralised database, an end user is unlikely to keep a local record of every order they create. In practice the maker has to fetch the order parameters back from the centralised service before they can build the cancellation call.
Two consequences follow from that design:
- The cancellation transaction is visible on chain before it is mined, so MEV users can frontrun it and fill the order first.
- Cancellation depends on the centralised service. If that service goes offline, a maker who does not remember the exact token amounts cannot reconstruct the order and cannot cancel it. Anyone holding a copy of the order database can then fill orders that would otherwise have been cancelled.
Exploitation
Step 1: Bob signs an order
Bob signs an order, which gets recorded in Putty servers.
Step 2: Alice mirrors the order book
Alice mirrors all the orders using Putty APIs. She now holds a local copy of the order data, including Bob's order.
Step 3: The servers go offline
Putty servers go offline.
Step 4: Bob wants to cancel
Changing token prices make Bob's order less favourable to him, so he wants to cancel it.
Step 5: Bob cannot cancel
Bob cannot cancel his order because Putty servers are down and he does not remember the exact amounts of tokens he used. Without those parameters he cannot call cancel().
Step 6: Alice fills the order
Alice goes through all the orders in her local mirror and fulfils the non-cancelled orders, including Bob's, with extremely favourable terms for herself.
Root cause
Cancellation is bound to the full order parameters and to a single on-chain call. Because the parameters live in a centralised database rather than with the maker, availability of that database becomes a precondition for cancellation. The report describes cancel() as the only cancellation method, so once the service is unavailable there is nothing to stop the scenario above. The report describes the cancellation as an on-chain signal for MEV users to frontrun and fill the order.
Impact
The judge held that there would arguably be a loss of assets for the maker when the server goes down and the maker can no longer cancel. A party who has mirrored the order database can then fill the affected orders on terms that are extremely favourable to themselves. The report frames this as conditional: it requires the centralised service to be unavailable at the moment the maker wants to cancel.
The sponsor's response questioned the severity. They argued that funds are not directly at risk unless the centralised order book server goes down and loses all the data, and that even then orders carry an expiration field that renders them useless after some set time period. They also noted easy frontend fixes, such as letting users download a txt file with their order or orderHash so they do not have to rely on the centralised database for data availability.
The judge accepted the medium rating. They agreed the expiration parameter limits validity, but held that the scenario, while an edge case that is very unlikely to happen, would arguably cause a loss of assets for the maker because of the protocol's loss of functionality.
Fix
The recommended mitigation is to add a bulk cancellation method alongside the standard one, so a maker can invalidate all their orders without revealing each order on chain and without depending on the centralised database. The report offers two ways to do it.
The first is a minimum valid nonce held as a mapping from user address to nonce:
mapping(address => uint256) minimumValidNonce;
Users can increment their minimumValidNonce. The increment function must not allow incrementing by more than 2**64, so callers cannot lock themselves out of creating orders by mistakenly raising minimumValidNonce to 2**256-1. Order filling is then blocked when order.nonce < minimumValidNonce.
The second is a counter, as Seaport does: an extra order parameter that has to match the corresponding counter state variable, so a maker cancels all their orders by incrementing the counter by one.
Either method enables cancelling orders without signalling to MEV bots and without a dependency on a centralised database.
The sponsor resolved the issue with a pull request, and the mitigation review raised a follow-up finding, M.M-04. A warden who reviewed the mitigation confirmed it was fixed by the introduction of a setMinimumValidNonce function and the corresponding control on order filling, and pointed to a follow-up finding in the mitigation review, M.M-04, where minimumValidNonce can be reduced due to an operational mistake, enabling old orders.
Variants to test
- Look for any protocol where cancellation requires the full order or intent as a parameter and the parameters are only stored off chain. A positive result is a maker who cannot reconstruct an order without the backend, combined with no bulk invalidation primitive.
- Check whether a nonce or counter exists but is only checked at signing time rather than at fill time. A positive result is an old order that still fills after the maker believed it was invalidated.
- Check the bounds on any increment function for a minimum valid nonce or counter. A positive result is the ability to set the value so high that the maker can no longer create valid orders.
- Watch for cancellation transactions that reveal the order before they are mined. A positive result is a fill that lands ahead of the cancellation in the same block.
Hunting notes
This class of bug tends to sit in the gap between off-chain order storage and on-chain settlement: anywhere the maker's ability to withdraw depends on data held by a server. During recon, look for order books served by APIs, signed orders with an expiration field, and a cancellation function that takes the order struct as an argument. Those signals point to a design where availability of the backend is part of the security model.
The report made its case through a concrete six-step scenario with two named actors, showing exactly how a mirrored order book plus an outage turns into a fill on favourable terms. The sponsor pushed back on severity, citing expiration and frontend workarounds, and the judge still accepted medium because the protocol's loss of functionality would arguably cause a loss of maker assets. The lesson for reporting is to spell out the precondition (backend unavailability), the attacker's preparation (mirroring via the public APIs) and the maker's loss, rather than relying on the frontrunning angle alone.
What happened, in plain words
Putty is a trading protocol built around orders. A trader, called a maker, creates an order and signs it. Signing is like writing your name at the bottom of a document: it proves the order came from you, but it does not by itself move any money. The signed order is then stored in Putty's centralised database.
This report is about what happens when a maker changes their mind and wants to take an order back before anyone fills it. The only way to do that, according to the report, is to call a function named cancel() and to pass the whole order to it as an argument. An argument is a piece of information you hand to a function so it knows what to work on; here it is the order itself, with all its details such as the amounts of tokens.
The researcher, shung, who was joined by unforgiven in finding the same thing, argues that this single way of cancelling causes two problems. First, the cancellation is a public on-chain action, so anyone watching the blockchain sees it coming and can rush to fill the order before the cancellation lands. Second, to cancel you need the exact order details, and those details live on Putty's central servers. If those servers are down, a maker who does not remember the exact numbers cannot cancel at all, while somebody who copied the order list earlier can still fill the order.
Background you need first
A few ideas come up again and again, so here they are from zero.
- Blockchain and on chain. A blockchain is a public ledger that many computers keep copies of. Anything written "on chain" is visible to everyone and cannot be quietly changed afterwards. A transaction is an instruction sent to the blockchain, for example "cancel this order".
- Off chain. Work done anywhere other than the blockchain, such as on a company's own servers, is "off chain". It is cheaper and faster, but it is not public and it depends on that company keeping its systems running.
- Maker and order. A maker is the person who offers a trade. An order is the offer itself: I will give this many tokens of one kind for that many of another kind. The order is signed by the maker so that nobody can alter it later.
- API. An API is a way for one computer program to ask another for information or to ask it to do something, like a waiter taking your order to the kitchen. Putty's APIs let programs fetch the list of orders.
- MEV. MEV stands for maximal extractable value. It is the profit that a fast, automated trader can make by looking at transactions that are waiting to be processed and slipping their own transaction in just before or after. These automated traders are often called MEV bots or searchers.
- Frontrunning. Frontrunning is placing your own action ahead of somebody else's known action to profit from it. If you see a cancellation queued up, you can try to get your fill in first.
- Centralised database. A database is an organised store of information. Centralised means one party controls it. If that party's service goes offline, the data becomes unreachable for everyone who relied on it.
- Nonce. A nonce is simply a number used once, usually a counter attached to an order or an account so the system can tell old items from new ones.
- Expiration. An expiration is a deadline attached to an order. After that time the order is no longer valid.
The setup
The report does not describe a particular deployment, a set of tools or specific accounts used to reproduce the problem. It is reasoning about how the cancellation flow is designed, not a live attack against a running system. Two characters appear in the scenario: Bob, a maker who signs orders, and Alice, someone who copies the order list through Putty's APIs.
Finding it
The starting observation is simple: cancel() takes the order as a parameter. To cancel, the maker therefore has to supply the exact order details. Because orders are signed off chain and kept in a centralised database, an ordinary user is unlikely to keep their own local record of every order they create. In practice the maker has to fetch the order details back from the central service before they can even build the cancellation call.
Two consequences follow:
- The cancellation transaction is visible on chain before it is processed, so MEV users can frontrun it and fill the order first.
- Cancellation depends on the central service. If that service goes offline, a maker who does not remember the exact token amounts cannot rebuild the order and cannot cancel it. Anyone holding a copy of the order database can then fill orders that would otherwise have been cancelled.
Exploitation
The report walks through the second problem as a six-step story.
Step 1: Bob signs an order
Bob signs an order, which gets recorded in Putty servers. Signing is the maker's commitment; recording it on the company's servers is what makes it discoverable by traders.
Step 2: Alice mirrors the order book
Alice mirrors all the orders using Putty APIs. She now holds a local copy of the order data, including Bob's order. Mirroring means making a duplicate of the list on her own machine. She does this using Putty APIs.
Step 3: The servers go offline
Putty servers go offline. This is the precondition for the whole scenario: the central service that holds the order details is no longer reachable.
Step 4: Bob wants to cancel
Changing token prices make Bob's order less favourable to him, so he wants to cancel it. Prices move, and an offer that looked good when signed can become a bad deal.
Step 5: Bob cannot cancel
Bob cannot cancel his order because Putty servers are down and he does not remember the exact amounts of tokens he used. Without those details he cannot call cancel(). This is the heart of the finding: the ability to withdraw an offer depends on data held by somebody else.
Step 6: Alice fills the order
Alice goes through all the orders in her local mirror and fulfils the non-cancelled orders, including Bob's, with extremely favourable terms for herself. Because she kept a copy, the outage does not stop her; it only stops Bob.
Root cause
Cancellation is tied to the full order details and to a single on-chain call. Because those details live in a centralised database rather than with the maker, the database being available becomes a condition for cancelling. The report describes cancel() as the only cancellation method, so once the service is unavailable there is nothing to stop the scenario above. The report describes the cancellation as an on-chain signal for MEV users to frontrun and fill the order.
Impact
The judge held that there would arguably be a loss of assets for the maker when the server goes down and the maker can no longer cancel. A party who has mirrored the order database can then fill the affected orders on terms that are extremely favourable to themselves. The report presents this as conditional: it requires the central service to be unavailable at the moment the maker wants to cancel.
The sponsor, the team behind Putty, questioned the severity. They argued that funds are not directly at risk unless the centralised order book server goes down and loses all the data, and that even then orders carry an expiration field that renders them useless after some set time period. They also noted easy frontend fixes, such as letting users download a txt file with their order or orderHash so they do not have to rely on the centralised database for data availability. A frontend is the part of the service users see in their browser; an orderHash is a short fingerprint of an order that identifies it.
The judge accepted the medium rating. They agreed the expiration parameter limits validity, but held that the scenario, while an edge case that is very unlikely to happen, would arguably cause a loss of assets for the maker because of the protocol's loss of functionality.
Fix
The recommended mitigation is to add a bulk cancellation method alongside the standard one, so a maker can invalidate all their orders without revealing each order on chain and without depending on the centralised database. The report offers two ways to do it.
The first is a minimum valid nonce held as a mapping from user address to nonce:
mapping(address => uint256) minimumValidNonce;
Line by line: mapping is a lookup table. address is the type of the key, an account address on the blockchain. uint256 is the type of the value, a whole number that can be very large. minimumValidNonce is the name of the table. Read together, it stores, for each user, the lowest nonce that is still allowed. Any order with a lower nonce is treated as cancelled.
Users can increment their minimumValidNonce. The increment function must not allow incrementing by more than 2**64, so callers cannot lock themselves out of creating orders by mistakenly raising minimumValidNonce to 2**256-1. Order filling is then blocked when order.nonce < minimumValidNonce. In plain words: raise the bar and every older order falls below it and stops being fillable, all in one action.
The second is a counter, as Seaport does: an extra order parameter that has to match the corresponding counter state variable, so a maker cancels all their orders by incrementing the counter by one. Seaport is another trading protocol, cited as an existing example of the pattern.
Either method enables cancelling orders without signalling to MEV bots and without a dependency on a centralised database.
The sponsor resolved the issue with a pull request, and the mitigation review raised a follow-up finding, M.M-04. A warden, meaning a reviewer in the audit, who checked the mitigation confirmed it was fixed by the introduction of a setMinimumValidNonce function and the corresponding control on order filling, and pointed to a follow-up finding in the mitigation review, M.M-04, where minimumValidNonce can be reduced due to an operational mistake, enabling old orders.
Variants to test
- Look for any protocol where cancellation requires the full order or intent as a parameter and the parameters are only stored off chain. A positive result is a maker who cannot reconstruct an order without the backend, combined with no bulk invalidation primitive.
- Check whether a nonce or counter exists but is only checked at signing time rather than at fill time. A positive result is an old order that still fills after the maker believed it was invalidated.
- Check the bounds on any increment function for a minimum valid nonce or counter. A positive result is the ability to set the value so high that the maker can no longer create valid orders.
- Watch for cancellation transactions that reveal the order before they are processed. A positive result is a fill that lands ahead of the cancellation in the same block.
Hunting notes
This class of bug tends to sit in the gap between off-chain order storage and on-chain settlement: anywhere the maker's ability to withdraw depends on data held by a server. During recon, meaning the early look around a target, look for order books served by APIs, signed orders with an expiration field, and a cancellation function that takes the order as an argument. Those signals point to a design where availability of the backend is part of the security model.
The report made its case through a concrete six-step scenario with two named actors, showing exactly how a mirrored order book plus an outage turns into a fill on favourable terms. The sponsor pushed back on severity, citing expiration and frontend workarounds, and the judge still accepted medium because the protocol's loss of functionality would arguably cause a loss of maker assets. The lesson for reporting is to spell out the precondition (backend unavailability), the attacker's preparation (mirroring via the public APIs) and the maker's loss, rather than relying on the frontrunning angle alone.
Glossary
- API: a way for one program to ask another for data or to perform an action.
- Argument: a value passed into a function so it knows what to work on.
- Blockchain: a public ledger kept in copies by many computers, where entries are visible to all.
- Centralised database: a store of information controlled by a single party, unavailable if that party's service goes down.
- Counter: a running number that increases by one, used to mark which orders are current.
- Expiration: a deadline after which an order is no longer valid.
- Frontrunning: placing your own action ahead of somebody else's known action to profit from it.
- Function: a named piece of code that performs an action when called.
- Maker: the person who creates and signs an order offering a trade.
- Mapping: a lookup table that pairs a key with a value.
- MEV: maximal extractable value, the profit automated traders make by ordering transactions around others.
- Mirroring: making a local duplicate of data held elsewhere.
- Nonce: a number used once, usually a counter that distinguishes old items from new ones.
- Off chain: work done outside the blockchain, for example on a company's servers.
- On chain: work recorded on the blockchain, visible to everyone.
- Order: an offer to trade one token for another, signed by the maker.
- Order book: the list of open orders available to trade against.
- Pull request: a proposed change to a codebase, submitted for review and merging.
- Recon: the early exploration of a target to understand how it works.
- Settlement: the step where a trade is finalised on chain.
- Sponsor: the team that owns the code being audited.
- Token: a digital unit of value on a blockchain.
- Transaction: an instruction sent to the blockchain.
- Warden: a security reviewer taking part in an audit.