[Denial-of-Service] Contract Owner Could Block Users From Withdrawing Their Strike
The contract owner could block users from withdrawing their strike by making the fee transfer revert, either by setting the owner address to zero or by using an ERC777 token that rejects the fee. This would cause the entire withdrawal to fail, leaving users' assets stuck in the contract.
Originally disclosed on Code4rena
Submitted by xiaoming90, also found by berndartmueller
When users withdraw their strike escrowed in Putty contract, Putty will charge a certain amount of fee from the strike amount. The fee will first be sent to the contract owner, and the remaining strike amount will then be sent to the users.
function withdraw(Order memory order) public {
..SNIP..
// 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);
}
ERC20(order.baseAsset).safeTransfer(msg.sender, order.strike - feeAmount);
return;
}
..SNIP..
}
There are two methods on how the owner can deny user from withdrawing their strike amount from the contract
Method #1 - Set the owner() to zero address
Many of the token implementations do not allow transfer to zero address (Reference). Popular ERC20 implementations such as the following Openzeppelin’s ERC20 implementation do not allow transfer to zero address, and will revert immediately if the to address (recipient) points to a zero address during a transfer.
function _transfer(
address from,
address to,
uint256 amount
) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
// Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
// decrementing then incrementing.
_balances[to] += amount;
}
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
It is possible for the owner to transfer the ownership to a zero address, thus causing the fee transfer to the contract owner to always revert. When the fee transfer always reverts, no one can withdraw their strike amount from the contract.
This issue will affect all orders that adopt a baseAsset that reverts when transferring to zero address.
Method #2 - If baseAsset is a ERC777 token
Note:
owner()could point to a contract or EOA account. By pointing to a contract, the contract could implement logic to revert whenever someone send tokens to it.
ERC777 contains a tokensReceived hook that will notify the recipient whenever someone sends some tokens to the recipient .
Assuming that the baseAsset is a ERC77 token, the recipient, which is the owner() in this case, could always revert whenever PuttyV2 contract attempts to send the fee to recipient. This will cause the withdraw function to revert too. As a result, no one can withdraw their strike amount from the contract.
This issue will affect all orders that has ERC777 token as its baseAsset.
Impact
User cannot withdraw their strike amount and their asset will be stuck in the contract.
Recommended Mitigation Steps
It is recommended to adopt a withdrawal pattern for retrieving owner fee.
Instead of transferring the fee directly to owner address during withdrawal, save the amount of fee that the owner is entitled to in a state variable. Then, implement a new function that allows the owner to withdraw the fee from the PuttyV2 contract.
Consider the following implementation. In the following example, there is no way for the owner to perform denial-of-user because the outcome of the fee transfer (succeed or fail) to the owner will not affect the user’s strike withdrawal process.
This will give users more assurance and confidence about the security of their funds stored within Putty.
mapping(address => uint256) public ownerFees;
function withdraw(Order memory order) public {
..SNIP..
// 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;
ownerFees[order.baseAsset] += feeAmount
}
ERC20(order.baseAsset).safeTransfer(msg.sender, order.strike - feeAmount);
return;
}
..SNIP..
}
function withdrawFee(address baseAsset) public onlyOwner {
uint256 _feeAmount = ownerFees[baseAsset];
ownerFees[baseAsset] = 0;
ERC20(baseAsset).safeTransfer(owner(), _feeAmount);
}
outdoteth (Putty Finance) disagreed with severity
The scenarios provided are valid, especially for baseAssets that revert on zero-address transfer.
While the likelihood is low, assets are lost and cannot be retrieved.
3 — High: Assets can be stolen/lost/compromised directly (or indirectly if there is a valid attack path that does not have hand-wavy hypotheticals).
HickupHH3 (judge) decreased severity to Medium and commented:
Thinking about it further, the external conditions / requirements needed for the DoS to happen are somewhat strong.
- the ERC777 attack requires
owner()or the token to be engineered to be malicious and adopted.- DoS via revoking ownership requires
feeto be non-zero first, which is unlikely to happen. I can classify this as a “user-prone” bug, which would be similar to cases like including ETH when WETH is intended to be used (#226).Hence, I think medium severity is more appropriate:
2 — Med: Assets not at direct risk, but the function of the protocol or its availability could be impacted, or leak value with a hypothetical attack path with stated assumptions, but external requirements.
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: as the platform fee is now transferred on order filling, any owner griefing can only yield a denial of service. There will be no loss of funds as this way position is only about to be created when the fee is transferred.
Context
Putty is an on-chain protocol for options on ERC20 tokens. Users escrow a strike amount in the PuttyV2 contract, and when they withdraw, the contract charges a fee on that strike. The fee is sent to the contract owner first, and the remaining strike is then sent to the user. The relevant logic lives in the withdraw function of PuttyV2.sol:
function withdraw(Order memory order) public {
..SNIP..
// 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);
}
ERC20(order.baseAsset).safeTransfer(msg.sender, order.strike - feeAmount);
return;
}
..SNIP..
}
The fee transfer to owner() happens before the user's strike is transferred. That ordering is the whole problem: if the fee transfer reverts, the user's transfer never executes.
Setup
The finding concerns the withdraw path of PuttyV2 and the behaviour of the baseAsset ERC20 token used by an order. Two preconditions matter:
- The fee must be greater than zero, otherwise the fee branch is skipped entirely and no transfer to
owner()occurs. - The
baseAssetmust be a token whose transfer toowner()can be made to revert.
The report describes two ways to reach that state, one based on the owner address and one based on the token standard.
Finding it
The withdraw function performs the owner fee transfer inline, before paying the user. Because both transfers are in the same call, any revert in the first one aborts the second. The recipient of the first transfer is owner(), so the owner address and the token's transfer behaviour determine whether the fee transfer succeeds.
Exploitation
Step 1: Set owner() to the zero address
Many token implementations reject transfers to the zero address. The report cites the weird-ERC20 reference on revert-on-transfer-to-the-zero-address and shows OpenZeppelin's ERC20 implementation, which reverts immediately when the recipient is the zero address:
function _transfer(
address from,
address to,
uint256 amount
) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
// Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
// decrementing then incrementing.
_balances[to] += amount;
}
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
If the owner transfers ownership to the zero address, the safeTransfer(owner(), feeAmount) call reverts on every withdrawal. Since the user's transfer comes after it, no one can withdraw their strike. This affects all orders whose baseAsset reverts when transferring to the zero address.
Step 2: Use an ERC777 baseAsset whose recipient reverts
ERC777 defines a tokensReceived hook that notifies the recipient whenever tokens are sent to it. If the baseAsset is an ERC777 token, the recipient, here owner(), can revert inside that hook every time PuttyV2 tries to send the fee. The withdraw call then reverts as well, and again no one can withdraw their strike. This affects all orders that use an ERC777 token as their baseAsset.
The report notes that owner() can point to a contract or an EOA, and that a contract owner can implement logic to revert whenever someone sends tokens to it.
Root cause
The fee payment to the owner is coupled to the user's withdrawal in a single transaction, with the owner payment first. Any revert in the owner payment, whether caused by the owner address (zero address) or by the token's transfer semantics (ERC777 hook), blocks the user's payout. The contract does not isolate the two transfers, so the owner's ability to make its own payment fail becomes an availability lever over user funds.
Impact
Users cannot withdraw their strike amount, and their asset stays stuck in the contract. The report scopes this to orders whose baseAsset reverts on transfer to the zero address, and to orders whose baseAsset is an ERC777 token.
The severity was contested. outdoteth of Putty Finance disagreed with the severity. The judge, HickupHH3, initially rated it high, noting that the scenarios are valid, especially for baseAssets that revert on zero-address transfer, and that while the likelihood is low, assets are lost and cannot be retrieved. The judge then decreased it to medium, reasoning that the external conditions are somewhat strong: the ERC777 attack requires owner() or the token to be engineered to be malicious and adopted, and the DoS via revoking ownership requires fee to be non-zero first, which the judge considered unlikely. The judge classified it as a user-prone bug and settled on medium: assets are not at direct risk, but the function of the protocol or its availability could be impacted.
Fix
The report recommends a withdrawal pattern for the owner fee. Instead of transferring the fee directly during withdrawal, record the fee the owner is entitled to in a state variable, and add a separate function the owner calls to withdraw it. The suggested implementation:
mapping(address => uint256) public ownerFees;
function withdraw(Order memory order) public {
..SNIP..
// 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;
ownerFees[order.baseAsset] += feeAmount
}
ERC20(order.baseAsset).safeTransfer(msg.sender, order.strike - feeAmount);
return;
}
..SNIP..
}
function withdrawFee(address baseAsset) public onlyOwner {
uint256 _feeAmount = ownerFees[baseAsset];
ownerFees[baseAsset] = 0;
ERC20(baseAsset).safeTransfer(owner(), _feeAmount);
}
With this design, the outcome of the fee transfer to the owner does not affect the user's strike withdrawal. Putty Finance confirmed and resolved the issue with a fix in a pull request. Warden hyh reviewed the mitigation and noted it is the same fix as in H-01: the platform fee is now transferred on order filling, so any owner griefing can only yield a denial of service, and there is no loss of funds because the position is only about to be created when the fee is transferred.
Variants to test
- Owner-controlled recipient in a payout path. Look for functions that pay a privileged address before paying the user. A positive result is a token or owner configuration that makes the privileged transfer revert while the user's transfer would otherwise succeed.
- Zero-address ownership. Check whether ownership can be renounced or transferred to the zero address, and whether any payout path sends tokens to
owner(). A positive result is a withdrawal that reverts for every user once ownership is zeroed. - ERC777 hook recipients. For any contract that sends tokens to a configurable address, check whether the recipient can revert in
tokensReceived. A positive result is a payout that can be blocked by the recipient's hook. - Fee-gated branches. Identify paths where a fee transfer only happens when a fee parameter is non-zero. A positive result is a configuration where the fee is non-zero and the fee transfer is the only thing standing between the user and their funds.
Hunting notes
This class of bug hides in payout functions that combine a privileged transfer and a user transfer in one transaction, especially when the privileged transfer comes first. During review, look for safeTransfer calls to owner(), admin() or a treasury address inside user-facing withdrawal or claim functions. Signals worth checking are ownership that can be set to the zero address, tokens with transfer hooks such as ERC777, and fee parameters that gate whether the privileged transfer runs at all. The judge accepted the scenarios as valid but weighed the external requirements and settled on medium.
What happened, in plain words
Putty is a piece of software that runs on a blockchain. It lets people make agreements about tokens (digital assets) and holds those tokens safely in the meantime. One of the things it holds is called a strike amount: a quantity of tokens a user puts in while an agreement is active, and which they get back when they withdraw.
When a user withdraws, Putty takes a small fee from that strike amount. The fee goes to the contract owner, and the rest goes to the user. The report found that the fee is paid first, and the user is paid second, inside the same operation. If the first payment fails for any reason, the whole operation is cancelled, so the second payment never happens either. The contract owner can arrange for that first payment to fail, which means users cannot get their tokens back. Their tokens stay stuck in the contract.
The report describes two ways the owner can do this: by setting the owner address to a special empty address, or by using a particular kind of token whose recipient can refuse a payment. The judge accepted both scenarios as valid, initially rated the issue high, then decreased it to medium because the conditions needed are fairly specific. Putty Finance fixed it.
Background you need first
A few ideas come up again and again, so here they are from scratch.
Blockchain and smart contracts. A blockchain is a shared record book that many computers keep copies of. A smart contract is a small program stored in that record book. Anyone can ask it to run a function, and the result is recorded for everyone to see. Once a function runs successfully, its effects are permanent; if it fails, nothing it did is kept.
Tokens and ERC20. A token is a digital asset managed by a smart contract. ERC20 is the most common set of rules for such tokens: it defines functions like transfer (send tokens from one address to another) and balanceOf (how many tokens an address holds). Because so many tokens follow the same rules, other programs can handle them in a standard way.
Addresses. An address is like a bank account number on the blockchain. It can belong to a person (an EOA, an externally owned account, controlled by a private key) or to a contract (a program). There is a special address made of all zeros, usually written address(0) or the zero address. It is not a real account; it is a placeholder. Sending tokens there is like posting money to a house that does not exist: some tokens allow it, many refuse it.
Revert. When a smart contract decides an operation is not allowed, it "reverts". Think of it as the whole transaction being undone, as if it never happened, and an error being returned. If step one of a transaction reverts, step two never runs.
Escrow. Escrow means a neutral third party holds something of value until conditions are met. Here the Putty contract is the escrow: it holds the user's strike tokens while the agreement is active.
Fee. A small charge taken by the protocol, here a percentage of the strike amount, paid to the contract owner.
Denial of service (DoS). A denial-of-service problem is when something that should work is deliberately or accidentally made impossible. In the physical world it is like a shop whose only checkout till jams whenever a particular manager is on shift: customers cannot buy anything, not because the shop is empty, but because one step in the process always fails.
ERC777 and hooks. ERC777 is a different token standard. Its special feature is a hook: when tokens are sent to an address, the receiving contract is notified by a function called tokensReceived, and that function gets a chance to run code. If that code reverts, the transfer is cancelled. It is like a delivery service that phones you before leaving a parcel, and you are allowed to say "no, take it back".
State variable. A value the contract stores permanently in its own memory, such as a running total. It survives between transactions.
Withdrawal pattern. A common design where, instead of pushing money to someone automatically, the contract records that they are owed money, and they later call a separate function to collect it. Like a cloakroom that gives you a ticket instead of handing you the coat immediately.
The product and the feature
Putty is an on-chain protocol for options on ERC20 tokens. An option is an agreement giving someone the right to buy or sell an asset at agreed terms. Users escrow a strike amount in the PuttyV2 contract. When they withdraw, the contract charges a fee on that strike. The fee is sent to the contract owner first, and the remaining strike is then sent to the user.
The relevant logic lives in the withdraw function of PuttyV2.sol:
function withdraw(Order memory order) public {
..SNIP..
// 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);
}
ERC20(order.baseAsset).safeTransfer(msg.sender, order.strike - feeAmount);
return;
}
..SNIP..
}
Line by line, in plain words:
function withdraw(Order memory order) public {declares a function anyone can call, taking an order as input. The..SNIP..marks code left out of the excerpt.- The
ifline checks whether this is the moment the strike should be returned: either the order is a call and it has been exercised, or it is not a call and it has not been exercised. Options terminology aside, this is the branch where money moves back to the user. uint256 feeAmount = 0;starts the fee at zero.if (fee > 0) {only charges a fee when the fee setting is above zero. If the fee is zero, this whole block is skipped and no payment to the owner happens at all.feeAmount = (order.strike * fee) / 1000;calculates the fee as the strike multiplied by the fee setting, divided by 1000. So a fee setting of 10 means one per cent.ERC20(order.baseAsset).safeTransfer(owner(), feeAmount);sends that fee to the contract owner. This is the first transfer, and it is the one that matters for this bug.ERC20(order.baseAsset).safeTransfer(msg.sender, order.strike - feeAmount);sends the rest of the strike to the person who called the function, that is, the user. This is the second transfer.return;ends the function.
The fee transfer to owner() happens before the user's strike is transferred. That ordering is the whole problem: if the fee transfer reverts, the user's transfer never executes.
The setup needed
The finding concerns the withdraw path of PuttyV2 and the behaviour of the baseAsset ERC20 token used by an order. The baseAsset is simply the token in which the strike is denominated, the token being paid out. Two preconditions matter:
- The fee must be greater than zero, otherwise the fee branch is skipped entirely and no transfer to
owner()occurs. - The
baseAssetmust be a token whose transfer toowner()can be made to revert.
The report describes two ways to reach that state, one based on the owner address and one based on the token standard.
Finding it
The withdraw function performs the owner fee transfer inline, before paying the user. Because both transfers are in the same call, any revert in the first one aborts the second. The recipient of the first transfer is owner(), so the owner address and the token's transfer behaviour determine whether the fee transfer succeeds.
Exploitation
Step 1: Set owner() to the zero address
Many token implementations reject transfers to the zero address. The report cites the weird-ERC20 reference on revert-on-transfer-to-the-zero-address and shows OpenZeppelin's ERC20 implementation, which reverts immediately when the recipient is the zero address:
function _transfer(
address from,
address to,
uint256 amount
) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
// Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
// decrementing then incrementing.
_balances[to] += amount;
}
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
Line by line:
function _transfer(starts the internal function that every ERC20 transfer goes through.fromis the sender,tothe recipient,amountthe quantity.require(from != address(0), "ERC20: transfer from the zero address");refuses to send from the zero address.require(to != address(0), "ERC20: transfer to the zero address");refuses to send to the zero address. This is the line that matters here: if the recipient is the zero address, the transfer reverts._beforeTokenTransfer(from, to, amount);runs any extra checks the token may define before moving balances.uint256 fromBalance = _balances[from];reads the sender's balance.require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");refuses to send more than the sender has.- The
unchecked { ... }block updates the balances: it subtracts the amount from the sender and adds it to the recipient.uncheckedtells the compiler not to add overflow checks, which is safe here because the total supply is fixed. emit Transfer(from, to, amount);records an event, a public log entry that the transfer happened._afterTokenTransfer(from, to, amount);runs any extra logic defined after the move.
If the owner transfers ownership to the zero address, the safeTransfer(owner(), feeAmount) call reverts on every withdrawal. Since the user's transfer comes after it, no one can withdraw their strike. This affects all orders whose baseAsset reverts when transferring to the zero address.
Step 2: Use an ERC777 baseAsset whose recipient reverts
ERC777 defines a tokensReceived hook that notifies the recipient whenever tokens are sent to it. If the baseAsset is an ERC777 token, the recipient, here owner(), can revert inside that hook every time PuttyV2 tries to send the fee. The withdraw call then reverts as well, and again no one can withdraw their strike. This affects all orders that use an ERC777 token as their baseAsset.
The report notes that owner() can point to a contract or an EOA, and that a contract owner can implement logic to revert whenever someone sends tokens to it. In everyday terms: the owner can be a program that always refuses deliveries, so the delivery step fails, and because the user's payout is in the same operation, it fails too.
Root cause
The fee payment to the owner is coupled to the user's withdrawal in a single transaction, with the owner payment first. Any revert in the owner payment, whether caused by the owner address (zero address) or by the token's transfer semantics (ERC777 hook), blocks the user's payout. The contract does not isolate the two transfers, so the owner's ability to make its own payment fail becomes an availability lever over user funds.
Impact
Users cannot withdraw their strike amount, and their asset stays stuck in the contract. The report scopes this to orders whose baseAsset reverts on transfer to the zero address, and to orders whose baseAsset is an ERC777 token.
The severity was contested. outdoteth of Putty Finance disagreed with the severity. The judge, HickupHH3, initially rated it high, noting that the scenarios are valid, especially for baseAssets that revert on zero-address transfer, and that while the likelihood is low, assets are lost and cannot be retrieved. The judge then decreased it to medium, reasoning that the external conditions are somewhat strong: the ERC777 attack requires owner() or the token to be engineered to be malicious and adopted, and the DoS via revoking ownership requires fee to be non-zero first, which the judge considered unlikely. The judge classified it as a user-prone bug and settled on medium: assets are not at direct risk, but the function of the protocol or its availability could be impacted.
Fix
The report recommends a withdrawal pattern for the owner fee. Instead of transferring the fee directly during withdrawal, record the fee the owner is entitled to in a state variable, and add a separate function the owner calls to withdraw it. The suggested implementation:
mapping(address => uint256) public ownerFees;
function withdraw(Order memory order) public {
..SNIP..
// 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;
ownerFees[order.baseAsset] += feeAmount
}
ERC20(order.baseAsset).safeTransfer(msg.sender, order.strike - feeAmount);
return;
}
..SNIP..
}
function withdrawFee(address baseAsset) public onlyOwner {
uint256 _feeAmount = ownerFees[baseAsset];
ownerFees[baseAsset] = 0;
ERC20(baseAsset).safeTransfer(owner(), _feeAmount);
}
Line by line:
mapping(address => uint256) public ownerFees;creates a permanent table that records, for each token address, how much fee the owner is owed.publicmeans anyone can read it.- In
withdraw, the fee calculation is unchanged, but instead of sending the fee,ownerFees[order.baseAsset] += feeAmountadds the fee to the owner's running total for that token. No transfer to the owner happens here, so nothing the owner does can make this step fail. ERC20(order.baseAsset).safeTransfer(msg.sender, order.strike - feeAmount);then pays the user as before. The user's payout no longer depends on the owner's payment succeeding.function withdrawFee(address baseAsset) public onlyOwner {adds a separate function, callable only by the owner, to collect the recorded fees for one token.uint256 _feeAmount = ownerFees[baseAsset];reads the amount owed.ownerFees[baseAsset] = 0;resets the record to zero before sending, so the same fee cannot be collected twice.ERC20(baseAsset).safeTransfer(owner(), _feeAmount);sends the collected fee to the owner. If this fails, only the owner's own collection fails; users are unaffected.
With this design, the outcome of the fee transfer to the owner does not affect the user's strike withdrawal. Putty Finance confirmed and resolved the issue with a fix in a pull request. Warden hyh reviewed the mitigation and noted it is the same fix as in H-01: the platform fee is now transferred on order filling, so any owner griefing can only yield a denial of service, and there is no loss of funds because the position is only about to be created when the fee is transferred.
Variants to test
These are patterns to look for in other code, not steps performed in this report.
- Owner-controlled recipient in a payout path. Look for functions that pay a privileged address before paying the user. A positive result is a token or owner configuration that makes the privileged transfer revert while the user's transfer would otherwise succeed.
- Zero-address ownership. Check whether ownership can be renounced or transferred to the zero address, and whether any payout path sends tokens to
owner(). A positive result is a withdrawal that reverts for every user once ownership is zeroed. - ERC777 hook recipients. For any contract that sends tokens to a configurable address, check whether the recipient can revert in
tokensReceived. A positive result is a payout that can be blocked by the recipient's hook. - Fee-gated branches. Identify paths where a fee transfer only happens when a fee parameter is non-zero. A positive result is a configuration where the fee is non-zero and the fee transfer is the only thing standing between the user and their funds.
Hunting notes
This class of bug hides in payout functions that combine a privileged transfer and a user transfer in one transaction, especially when the privileged transfer comes first. During review, look for safeTransfer calls to owner(), admin() or a treasury address inside user-facing withdrawal or claim functions. Signals worth checking are ownership that can be set to the zero address, tokens with transfer hooks such as ERC777, and fee parameters that gate whether the privileged transfer runs at all. The judge accepted the scenarios as valid but weighed the external requirements and settled on medium.
Glossary
- Address: an identifier on a blockchain, like an account number; it can belong to a person or to a contract.
- Base asset: the token in which an order's strike is denominated and paid out.
- Blockchain: a shared, tamper-evident record book kept by many computers.
- Call / put: two kinds of option agreement; the report only uses them to decide when the strike is returned.
- Contract owner: the privileged address that receives protocol fees and can call owner-only functions.
- Denial of service (DoS): making a function that should work impossible to complete.
- EOA (externally owned account): an address controlled by a private key, that is, a person's account rather than a program.
- ERC20: the common standard for tokens, defining functions such as
transferandbalanceOf. - ERC777: a token standard with a
tokensReceivedhook that lets the recipient run code, and refuse, on receipt. - Escrow: holding an asset on someone's behalf until agreed conditions are met.
- Event: a log entry a contract writes to the blockchain to record that something happened.
- Fee: a percentage charge taken by the protocol, here paid to the contract owner.
- Hook: a function the receiving contract is asked to run during a transfer, which can accept or reject it.
- Mapping: a key-value table stored in a contract, here token address to amount owed.
- Option: an agreement giving a right to buy or sell an asset on agreed terms.
- Revert: cancelling a transaction and undoing its effects, usually because a check failed.
- SafeTransfer: a transfer helper that also checks whether the transfer succeeded.
- State variable: a value stored permanently in a contract between transactions.
- Strike: the amount a user escrows in the contract and later withdraws.
- Transaction: one request to run contract code; it either fully succeeds or fully reverts.
- Weird ERC20: tokens that deviate from the usual ERC20 behaviour, for example by rejecting transfers to the zero address.
- Withdrawal pattern: recording what someone is owed and letting them collect it separately, instead of paying them automatically.
- Zero address: the all-zeros address, a placeholder that is not a real account; many tokens refuse transfers to it.