DOS attack prevents refunding previous bid in Shortfall.sol and malicious bidder always wins the auction
The Shortfall auction contract refunds the previous highest bidder using a direct token transfer. If that refund fails (e.g., due to a token blacklist or an ERC777 recipient rejecting the transfer), the new higher bid cannot be placed, so the previous bidder remains the winner and the auction is disrupted.
berlin-101 Follow with Emmanuel, YungChaza and 8 others
Originally disclosed on Code4rena
Submitted by berlin-101, also found by Emmanuel, YungChaza, Emmanuel, sashik_eth, Team_Rocket, fs0c, fs0c, Audit_Avengers_2, 0xadrii and bin2chen.
https://github.com/code-423n4/2023-05-venus/blob/main/contracts/Shortfall/Shortfall.sol#L183 https://github.com/code-423n4/2023-05-venus/blob/main/contracts/Shortfall/Shortfall.sol#L190
The auction logic in Shortfall.sol refunds the previously accepted (highest) bid when a new acceptable bid is placed via the placeBid function.
It is important that this refund succeeds as otherwise a new acceptable (higher) bid is not possible and the auction is disrupted which consequently makes the current highest bidder the auction winner and causes a loss for the Venus project and its users.
When refunding the safeTransfer of OpenZeppelin SafeERC20Upgradeable (inheriting from SafeERC20) is used which deals with the multiple ways in which different ERC-20 (BEP-20) tokens indicate the success/failure of a token transfer.
For details see: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/utils/SafeERC20.sol#L12
Nevertheless, there are additional scenarios that may still disrupt the auction and put it into a state of DOS (Denial of Service). Specifically, 2 scenarios were identified:
- DOS with the underlying token implementing a blacklist.
- DOS with the underlying token being an ERC20-compatible ERC777 token.
Proof of Concept
1. DOS with the underlying token implementing a blacklist
In this scenario, the underlying token is implemented with a blacklist (also known as blocklist).
Because this is common for tokens on the Ethereum network (e.g. USDC/USDT implementing blacklist/blocklist; See: https://github.com/d-xo/weird-erc20) this is a scenario also possible for tokens on the Binance Chain.
And since it is not specifically stated that such tokens are excluded from the Venus project, while the fee on transfer/deflationary/rebase tokens are specifically mentioned to be excluded, this is assumed to be a potential issue.
The following steps describe the issue:
- Bidder 1 makes a bid while he is not on the token blacklist.
- After the bid, he is put on the token blacklist.
- Bidder 2 makes a higher bid and the refund to bidder 1 is attempted.
- The refund reverts due to bidder 1 being blacklisted which blocks the token transfer back.
- Bidder 1 remains the highest bidder and wins the auction.
2. DOS with the underlying token being an ERC20-compatible ERC777 token.
In this scenario, the underlying token is an ER777 token instead of an ERC20. Since the audit does not specifically state that ERC777 tokens (which are ERC-20 compatible) are out of scope, this is assumed to be a potential issue.
See https://docs.openzeppelin.com/contracts/2.x/api/token/erc777 for details on ERC777 tokens.
The following steps describe the issue:
- Bidder 1 implements a contract that acts as an “ERC777 recipient” which can either accept/reject tokens that are transferred to it.
- Bidder 1 makes a bid not with an EOA (externally owned account) but uses his smart contract to make the bid.
- After the bid was accepted, he activates his smart contract and rejects any tokens transferred to it.
- Bidder 2 makes a higher bid and the refund to the smart contract of bidder 1 is attempted.
- The refund fails due to the smart contract of bidder 1 rejecting the token transfer (ERC777 token calls
tokensReceivedfunction of receiving a smart contract to finalize the token transfer which reverts). - Bidder 1 remains the highest bidder and wins the auction.
Coded POC
To prove both aforementioned scenarios of putting the auction into a state of DOS, the Shortfall.ts test was modified and 1 test case for each scenario was added. Code for additional required mock tokens etc. (MockTokenERC20Blacklistable.sol, MockTokenERC777.sol, ERC777Recipient.sol) are included.
Note: see DOS attack prevents refunding previous bid in Shortfall.sol and malicious bidder always wins the auction for coding details.
Recommended Mitigation Steps
Use a withdrawal pattern (“pull over push”) instead of directly refunding the highest bidder during the bid. See: https://fravoll.github.io/solidity-patterns/pull_over_push.html for details. This way, the auction will not get into a state of DOS.
Assessed type
DoS
chechu (Venus) confirmed and commented via duplicate issue #376:
We won’t accept ERC777 tokens as underlying tokens. But we have upgradable ERC20 tokens that can include a similar behavior, so the risk exists and we’ll try to mitigate it by applying some changes.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The contract uses a push refund (direct token transfer) instead of a pull pattern, so a failing transfer blocks new bids.
Impact
A malicious bidder could win the auction at a lower price and cause a loss for the project and its users, if the underlying token has a blacklist or ERC777-like behaviour.
What the attacker needed
Underlying token has blacklist or ERC777 hooks; attacker can get blacklisted or use a contract; attacker places a bid before being blocked
How it was found
- Bidder 1 places a bid while not blacklisted.
- Bidder 1 is then blacklisted by the token.
- Bidder 2 places a higher bid, triggering a refund attempt to bidder 1.
- The refund reverts because bidder 1 is blacklisted, so the higher bid fails.
- Bidder 1 remains the highest bidder and wins the auction.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In an auction, when someone places a higher bid, the previous highest bidder should get their money back automatically. If that refund fails (for example, because the token can block certain addresses), the new bid cannot go through, so the old bidder stays the winner even though someone else tried to bid higher. This is a denial-of-service (DoS) problem: the auction gets stuck.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.