acceptCounterOffer() May Result In Both Orders Being Filled
The acceptCounterOffer function cancels the original order but does not check if it has already been filled, allowing an attacker to front-run and fill the original order before cancellation. This results in both the original and counter orders being filled, doubling the user's intended leverage.
Originally disclosed on Code4rena
Submitted by kirk-baird, also found by csanuragjain, hansfriese, Lambda, and minhquanym
When a user is attempting to accept a counter offer they call the function acceptCounterOffer() with both the originalOrder to be cancelled and the new order to fill. It is possible for an attacker (or any other user who happens to call fillOrder() at the same time) to fill the originalOrder before acceptCounterOffer() cancels it.
The impact is that both originalOrder and order are filled. The msg.sender of acceptCounterOffer() is twice as leveraged as they intended to be if the required token transfers succeed.
Proof of Concept
acceptCounterOffer() calls cancel() on the original order, however it will not revert if the order has already been filled.
function acceptCounterOffer(
Order memory order,
bytes calldata signature,
Order memory originalOrder
) public payable returns (uint256 positionId) {
// cancel the original order
cancel(originalOrder);
// accept the counter offer
uint256[] memory floorAssetTokenIds = new uint256[](0);
positionId = fillOrder(order, signature, floorAssetTokenIds);
}
cancel() does not revert if an order has already been filled it only prevents future fillOrder() transactions from succeeding.
function cancel(Order memory order) public {
require(msg.sender == order.maker, "Not your order");
bytes32 orderHash = hashOrder(order);
// mark the order as cancelled
cancelledOrders[orderHash] = true;
emit CancelledOrder(orderHash, order);
}
Therefore any user may front-run the acceptCounterOffer() transaction with a fillOrder() transaction that fills the original order. As a result the user ends up filling both order and originalOrder. Then acceptCounterOffer() cancels the originalOrder which is essentially a no-op since it’s been filled and continues to fill the new order resulting in both orders being filled.
Recommended Mitigation Steps
Consider having cancel() revert if an order has already been filled. This can be done by adding the following line require(_ownerOf[uint256(orderHash)] == 0).
outdoteth (Putty Finance) confirmed and commented:
Report: It’s possible to fill an order twice by accepting a counter offer for an already filled order.
outdoteth (Putty Finance) resolved:
PR with fix: https://github.com/outdoteth/putty-v2/pull/2.
hyh (warden) reviewed mitigation:
Fixed by requiring that order can’t be in the filled state on cancel. This fully adheres to the original logic, but wasn’t controlled for before.
Context
Putty is an NFT options protocol. The finding concerns PuttyV2, the contract that holds the order book and the fill and cancel logic. The feature at the centre of the report is the counter offer flow: a maker publishes an order, a taker responds with a different set of terms, and the original maker can accept that counter offer by calling acceptCounterOffer(). That function is meant to do two things in one transaction: cancel the maker's original order and fill the counter offer. The intended outcome is that exactly one order ends up filled, the counter offer, and the original order is withdrawn from the book.
The report was submitted by kirk-baird, and the same issue was also found by csanuragjain, hansfriese, Lambda and minhquanym. It was rated high severity.
Setup
The report does not describe any accounts, tooling, versions or deployment. The relevant preconditions follow from the code paths it quotes:
- A maker has an open
originalOrderon the book. - A taker has produced a counter offer, the
orderparameter, with a validsignature. - The maker calls
acceptCounterOffer(order, signature, originalOrder)to cancel the original and fill the counter offer.
No special privileges are needed by the attacker. The report notes that the second fill can come from an attacker or simply from any other user who happens to call fillOrder() at the same time.
Finding it
The researcher looked at what acceptCounterOffer() actually does when it cancels the original order. It calls cancel(originalOrder) and then fills the new order. The question is what cancel() does when the order it is asked to cancel has already been filled. The answer, from the code, is that it does not revert. It only sets a flag that stops future fillOrder() calls from succeeding. So the cancellation step is not a guard against the order having been filled already; it is a guard against it being filled later.
That gap is what makes the flow exploitable. Between the moment the maker broadcasts acceptCounterOffer() and the moment it is mined, anyone can fill the original order. When the maker's transaction lands, the cancel is effectively a no-op on an already filled order, and the function continues to fill the counter offer. Both orders end up filled.
Exploitation
Step 1: understand the accept path
The function under attack is quoted in the report as follows:
function acceptCounterOffer(
Order memory order,
bytes calldata signature,
Order memory originalOrder
) public payable returns (uint256 positionId) {
// cancel the original order
cancel(originalOrder);
// accept the counter offer
uint256[] memory floorAssetTokenIds = new uint256[](0);
positionId = fillOrder(order, signature, floorAssetTokenIds);
}
The first action is cancel(originalOrder). The second is fillOrder(order, signature, floorAssetTokenIds) with an empty array of floor asset token IDs. There is no check between the two that the original order was still open, and no return value from cancel() is inspected.
Step 2: understand what cancel actually enforces
The cancel function is quoted as:
function cancel(Order memory order) public {
require(msg.sender == order.maker, "Not your order");
bytes32 orderHash = hashOrder(order);
// mark the order as cancelled
cancelledOrders[orderHash] = true;
emit CancelledOrder(orderHash, order);
}
The only requirement is that the caller is the maker of the order. The function then computes the order hash and sets cancelledOrders[orderHash] = true. It does not read or check the filled state of the order. It does not revert if the order has already been filled. Its only effect on future behaviour is that later fillOrder() calls for that hash will fail.
Step 3: front-run the accept transaction
An attacker, or any other user calling fillOrder() at the same time, submits a fillOrder() transaction for the originalOrder and gets it mined before the maker's acceptCounterOffer() transaction. The original order is now filled.
Step 4: the accept transaction lands
When acceptCounterOffer() executes, cancel(originalOrder) runs. The caller is the maker, so the require passes. The order hash is computed and cancelledOrders[orderHash] is set to true. Because the order is already filled, this flag has no practical effect: it only blocks future fills, and there will be no future fill of an order that is already filled. The function then proceeds to fillOrder(order, signature, floorAssetTokenIds) and fills the counter offer as well.
Result
Both originalOrder and order are filled. The report states that the msg.sender of acceptCounterOffer() is twice as leveraged as they intended to be, if the required token transfers succeed. That condition matters: the double fill only has the described effect when the maker's balances and approvals are sufficient to satisfy both fills.
Root cause
The mistake is that cancel() treats cancellation as a one-way flag and never checks whether the order has already been filled. acceptCounterOffer() relies on cancel() to take the original order off the book before filling the counter offer, but cancel() cannot fail on an already filled order, so the sequence does not enforce the intended invariant that only one of the two orders is filled.
The existing defence, the cancelledOrders mapping, only prevents future fillOrder() transactions. It does nothing about a fill that has already happened, which is exactly the state an attacker creates by front-running. The report does not discuss any other guard in the contract, so on the quoted code the check is simply absent.
Impact
The maker who calls acceptCounterOffer() ends up with both the original order and the counter offer filled, rather than only the counter offer. The report frames this as the caller being twice as leveraged as intended, conditional on the required token transfers succeeding. The report does not quantify losses, describe specific assets, or state who bears the cost beyond the maker's doubled exposure.
Fix
The recommended mitigation is to make cancel() revert when the order has already been filled, by adding the following line:
require(_ownerOf[uint256(orderHash)] == 0)
With that check, a front-run fill of the original order would cause cancel() to revert, and therefore acceptCounterOffer() would revert as a whole instead of filling the counter offer on top of an already filled original order.
The Putty team confirmed the issue, describing it as the possibility of filling an order twice by accepting a counter offer for an already filled order, and resolved it with a pull request. The warden review of the mitigation states that it was fixed by requiring that an order cannot be in the filled state on cancel, and that this fully adheres to the original logic but was not controlled for before.
Variants to test
- Any function that performs a cancel-then-act sequence in one transaction. Look for a
cancel-style helper whose only effect is setting a flag, and check whether the subsequent action assumes the cancel succeeded in removing a live order. A positive result is a state where both the cancelled object and the new object end up active or filled. - Order books with a separate filled-state mapping and cancelled-state mapping. Check whether cancel paths consult the filled mapping at all. A positive result is a cancel call that succeeds on an already filled order.
- Batch or multicall wrappers around cancel and fill. If a user can bundle cancel and fill, check whether an interleaved fill from another account between the two steps changes the outcome. A positive result is a double fill or a double spend of the same position.
- Signature-based orders where the maker's authorisation is reusable. Check whether a filled order's signature can still be consumed by a different code path. A positive result is a second fill using the same signed order.
Hunting notes
This class of bug hides in composite user flows that chain two state changes in one transaction, especially where one of the steps is a cancellation. The signal during review is a cancel function whose body only writes a boolean and emits an event, with no read of the filled or consumed state. If the same contract exposes a public fill function that anyone can call, the front-running window between broadcast and inclusion is the exploitation window.
To show impact convincingly, the report does three things: it quotes the exact functions involved, it explains the precise ordering of transactions that produces the double fill, and it states the condition under which the impact materialises, namely that the required token transfers succeed. It also proposes a concrete one-line fix.
One limit worth noting when reading the report: it does not include a runnable proof of concept, transaction hashes or measured losses. The argument rests entirely on the quoted code and the transaction ordering.
What happened, in plain words
Putty is a service (a protocol) built on a blockchain, where people trade options on NFTs. An NFT is a unique digital item, and an option is a contract that gives someone the right to buy or sell something on agreed terms. The report is about one specific feature of Putty: the counter offer.
A counter offer works like haggling in a shop. One person (the maker) puts an offer on the table. A second person (the taker) does not accept it as it is, but replies with slightly different terms. That reply is the counter offer. The original maker can then accept the counter offer, and the expectation is simple: the old offer is withdrawn and the new one is filled. One deal, not two.
The report shows that this expectation can be broken. If someone else fills the original offer in the short window before the maker's acceptance is processed, the maker ends up with both the original offer and the counter offer filled. The report calls this being twice as leveraged as intended: the maker is committed to twice the deal they wanted.
The finding was submitted by kirk-baird, and the same issue was also found by csanuragjain, hansfriese, Lambda and minhquanym. It was rated high severity.
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 public functions, and the code runs exactly as written.
PuttyV2is the contract in this report. It holds the order book (the list of open offers) and the logic to fill and cancel orders. - Transaction: a request sent to the blockchain to run a function in a contract. Transactions wait in a queue (the mempool) before they are processed (mined). Anyone can see a transaction while it waits, and anyone can send their own transaction with a higher fee so that it is processed first. That is called front-running: jumping ahead of someone in the queue.
- Order: a record in the contract describing a deal, including who made it (the maker) and its terms. Each order can be turned into a unique fingerprint called a hash, a short string of characters computed from the order's contents. The same order always gives the same hash, so the hash is used as the order's identity.
- Fill: to carry out an order, meaning the deal is executed and the tokens move.
- Cancel: to withdraw an order so that it can no longer be filled.
- Revert: to abort a transaction with an error. When a function reverts, all its changes are undone, as if it never ran. A
require(...)statement is a check that reverts when its condition is false. - Mapping: a lookup table inside a contract, like a dictionary.
cancelledOrders[orderHash] = truemeans "in the table of cancelled orders, mark this order's hash as cancelled". - Event: a log entry a contract writes to the blockchain so that outside tools can see something happened.
emit CancelledOrder(...)writes such a log. msg.sender: the address of whoever called the function. It is how a contract knows who is asking.- Token transfer: moving the assets involved in a deal. A fill only completes if the parties have the tokens and have given the contract permission to move them.
The setup
The report does not describe any accounts, tools, versions or deployment details. The situation it analyses follows from the code it quotes:
- A maker has an open
originalOrderon the book. - A taker has produced a counter offer, passed as the
orderparameter, together with asignature. A signature is cryptographic proof that the taker really authorised that counter offer; it cannot be forged. - The maker calls
acceptCounterOffer(order, signature, originalOrder)to cancel the original and fill the counter offer.
The attacker needs no special privileges. The report notes that the second fill can come from an attacker or simply from any other user who happens to call fillOrder() at the same time.
Finding it
The researcher looked at what acceptCounterOffer() actually does when it cancels the original order. It calls cancel(originalOrder) and then fills the new order. The question is what cancel() does when the order it is asked to cancel has already been filled. The answer, from the code, is that it does not revert. It only sets a flag that stops future fillOrder() calls from succeeding. So the cancellation step is not a guard against the order having been filled already; it is a guard against it being filled later.
That gap is what makes the flow exploitable. Between the moment the maker broadcasts acceptCounterOffer() and the moment it is mined, anyone can fill the original order. When the maker's transaction lands, the cancel is effectively a no-op on an already filled order, and the function continues to fill the counter offer. Both orders end up filled.
Exploitation
Step 1: understand the accept path
The function under attack is quoted in the report as follows:
function acceptCounterOffer(
Order memory order,
bytes calldata signature,
Order memory originalOrder
) public payable returns (uint256 positionId) {
// cancel the original order
cancel(originalOrder);
// accept the counter offer
uint256[] memory floorAssetTokenIds = new uint256[](0);
positionId = fillOrder(order, signature, floorAssetTokenIds);
}
Line by line:
function acceptCounterOffer(starts the definition of the function. It takes three inputs:order(the counter offer to fill),signature(the taker's proof that the counter offer is genuine) andoriginalOrder(the maker's earlier offer, the one to withdraw).Order memory orderandOrder memory originalOrdersay that both orders are passed in as structured records.memoryjust means they are held temporarily while the function runs.bytes calldata signatureis the signature, passed as raw data.public payablemeans anyone can call the function, and it is allowed to carry a payment of the blockchain's native currency.returns (uint256 positionId)says the function gives back a number identifying the resulting position.cancel(originalOrder);is the first action: withdraw the maker's original order.uint256[] memory floorAssetTokenIds = new uint256[](0);creates an empty list of token IDs. The report does not explain what floor assets are; it only shows that an empty list is passed on.positionId = fillOrder(order, signature, floorAssetTokenIds);is the second action: fill the counter offer and store the resulting position identifier.
The important point is the order of the two actions. There is no check between them that the original order was still open, and the return value of cancel() is not inspected. The function assumes the cancel worked as a withdrawal.
Step 2: understand what cancel actually enforces
The cancel function is quoted as:
function cancel(Order memory order) public {
require(msg.sender == order.maker, "Not your order");
bytes32 orderHash = hashOrder(order);
// mark the order as cancelled
cancelledOrders[orderHash] = true;
emit CancelledOrder(orderHash, order);
}
Line by line:
function cancel(Order memory order) public {defines a public function that takes one order.require(msg.sender == order.maker, "Not your order");is the only check: the caller must be the maker of the order, otherwise the transaction reverts with the message "Not your order". This stops strangers from cancelling other people's orders.bytes32 orderHash = hashOrder(order);computes the order's unique fingerprint.cancelledOrders[orderHash] = true;records in the lookup table that this order is cancelled.emit CancelledOrder(orderHash, order);writes a log entry announcing the cancellation.
What is missing is the key detail: the function never reads or checks whether the order has already been filled. It does not revert on an already filled order. Its only effect on future behaviour is that later fillOrder() calls for that hash will fail. In everyday terms, it is like a shop putting a "sold" sticker on an item without checking whether the item has already left the shop.
Step 3: front-run the accept transaction
An attacker, or any other user calling fillOrder() at the same time, submits a fillOrder() transaction for the originalOrder and gets it mined before the maker's acceptCounterOffer() transaction. The original order is now filled. This is the queue-jumping described earlier: the maker's acceptance is visible while it waits, and a competing transaction can be placed ahead of it.
Step 4: the accept transaction lands
When acceptCounterOffer() executes, cancel(originalOrder) runs. The caller is the maker, so the require passes. The order hash is computed and cancelledOrders[orderHash] is set to true. Because the order is already filled, this flag has no practical effect: it only blocks future fills, and there will be no future fill of an order that is already filled. The function then proceeds to fillOrder(order, signature, floorAssetTokenIds) and fills the counter offer as well.
Result
Both originalOrder and order are filled. The report states that the msg.sender of acceptCounterOffer() is twice as leveraged as they intended to be, if the required token transfers succeed. That condition matters: the double fill only has the described effect when the maker's balances and approvals are sufficient to satisfy both fills.
Root cause
The mistake is that cancel() treats cancellation as a one-way flag and never checks whether the order has already been filled. acceptCounterOffer() relies on cancel() to take the original order off the book before filling the counter offer, but cancel() cannot fail on an already filled order, so the sequence does not enforce the intended rule that only one of the two orders is filled.
The existing defence, the cancelledOrders mapping, only prevents future fillOrder() transactions. It does nothing about a fill that has already happened, which is exactly the state an attacker creates by front-running. The report does not discuss any other guard in the contract, so on the quoted code the check is simply absent.
Impact
The maker who calls acceptCounterOffer() ends up with both the original order and the counter offer filled, rather than only the counter offer. The report frames this as the caller being twice as leveraged as intended, conditional on the required token transfers succeeding. The report does not quantify losses, describe specific assets, or state who bears the cost beyond the maker's doubled exposure.
Fix
The recommended mitigation is to make cancel() revert when the order has already been filled, by adding the following line:
require(_ownerOf[uint256(orderHash)] == 0)
This line checks a record of ownership for the order's hash and reverts unless it is empty, meaning the order has not been filled. With that check, a front-run fill of the original order would cause cancel() to revert, and therefore acceptCounterOffer() would revert as a whole instead of filling the counter offer on top of an already filled original order. In shop terms, the "sold" sticker can no longer be applied to an item that has already gone.
The Putty team confirmed the issue, describing it as the possibility of filling an order twice by accepting a counter offer for an already filled order, and resolved it with a pull request. The warden review of the mitigation states that it was fixed by requiring that an order cannot be in the filled state on cancel, and that this fully adheres to the original logic but was not controlled for before. A warden, in this context, is an independent reviewer who checks the fix.
Variants to test
- Any function that performs a cancel-then-act sequence in one transaction. Look for a
cancel-style helper whose only effect is setting a flag, and check whether the subsequent action assumes the cancel succeeded in removing a live order. A positive result is a state where both the cancelled object and the new object end up active or filled. - Order books with a separate filled-state mapping and cancelled-state mapping. Check whether cancel paths consult the filled mapping at all. A positive result is a cancel call that succeeds on an already filled order.
- Batch or multicall wrappers around cancel and fill. If a user can bundle cancel and fill, check whether an interleaved fill from another account between the two steps changes the outcome. A positive result is a double fill or a double spend of the same position.
- Signature-based orders where the maker's authorisation is reusable. Check whether a filled order's signature can still be consumed by a different code path. A positive result is a second fill using the same signed order.
Hunting notes
This class of bug hides in composite user flows that chain two state changes in one transaction, especially where one of the steps is a cancellation. The signal during review is a cancel function whose body only writes a boolean and emits an event, with no read of the filled or consumed state. If the same contract exposes a public fill function that anyone can call, the front-running window between broadcast and inclusion is the exploitation window.
To show impact convincingly, the report does three things: it quotes the exact functions involved, it explains the precise ordering of transactions that produces the double fill, and it states the condition under which the impact materialises, namely that the required token transfers succeed. It also proposes a concrete one-line fix.
One limit worth noting when reading the report: it does not include a runnable proof of concept, transaction hashes or measured losses. The argument rests entirely on the quoted code and the transaction ordering.
Glossary
- Blockchain: a shared, append-only record of transactions that many computers keep in sync.
- Counter offer: a reply to an offer with different terms, which the original maker can accept.
- Event: a log entry a contract writes to the blockchain for outside tools to read.
- Fill: to execute an order so that the deal is carried out.
- Front-running: sending a transaction that jumps ahead of someone else's in the queue, usually by paying a higher fee.
- Hash: a short fingerprint computed from data, used here as an order's unique identity.
- Maker: the person who created an order.
- Mempool: the waiting queue where transactions sit before being processed.
- Mined: processed and recorded on the blockchain.
msg.sender: the address of the account that called the function.- NFT: a unique digital item recorded on a blockchain.
- No-op: an action that has no effect.
- Option: a contract giving the right to buy or sell something on agreed terms.
- Order: a record describing a proposed deal, including its maker and terms.
- Order book: the list of open orders.
- Protocol: a set of rules and contracts that together provide a service.
- Revert: to abort a transaction with an error, undoing all its changes.
- Signature: cryptographic proof that a specific party authorised a specific piece of data.
- Smart contract: a program on a blockchain that anyone can call and that runs as written.
- Taker: the person who responds to a maker's order.
- Token: a digital asset recorded on a blockchain.
- Transaction: a request to run a function in a contract, which waits in a queue before being processed.
- Warden: an independent reviewer who checks a fix in this kind of audit contest.