Non-whitelisted tokens cannot be added if the limit of token addresses is filled with whitelisted ones
The deposit function only applied the token address limit to non-whitelisted tokens, but whitelisted tokens also counted towards that same limit. As a result, a bounty minter who had deposited many whitelisted tokens could no longer deposit non-whitelisted ones.
HollaDieWaldfee Follow with unforgiven, rvierdiiev and 17 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-02-openq-judging/issues/530
Found by
HollaDieWaldfee, unforgiven, rvierdiiev, Jeiwan, 0xbepresent, RaymondFam, libratus, cergyk, CodeFoxInc, XKET, csanuragjain, Ruhum, Breeje, ast3ros, kiki_dev, carrot, bin2chen, 0xdeadbeef, hake, yixxas
Summary
Non-whitelisted tokens cannot be deposited to a bounty contract if too many whitelisted contracts were deposited.
Vulnerability Detail
The DepositManagerV1.fundBountyToken function allows depositing both whitelisted and non-whitelisted tokens by implementing the following check:
- if a token is whitelisted, it can be deposited without restrictions;
- if a token is not whitelisted, it cannot be deposited if
openQTokenWhitelist.TOKEN_ADDRESS_LIMITtokens have already been deposited.
However, while the token addresses limit requirement is only applied to non-whitelisted tokens, whitelisted tokens also increase the counter of token addresses: both non-whitelisted and whitelisted token addresses are added to the tokenAddresses set.
Impact
Bounty minters may not be able to deposit non-whitelisted tokens after they have deposited multiple whitelisted ones.
Code Snippet
DepositManagerV1.sol#L45-L50 BountyCore.sol#L326-L328 BountyCore.sol#L55
Tool used
Manual Review
Recommendation
Consider excluding whitelisted token addresses when checking the number of deposited tokens against the limit.
Discussion
FlacoJones
We are going to remove the ability to fund with an arbitrary ERC20 - removing the TOKEN_ADDRESS_LIMIT and simply reverting if a token, erc721 or erc20, is not whitelisted
This will effectively cap the number of ERC20 or ERC721 tokens to the total number of whitelisted tokens (which the protocol controls)
FlacoJones
https://github.com/OpenQDev/OpenQ-Contracts/pull/113
jacksanford1
Lead Senior Watson comment on PR #113:
Changes look good.
Token requirement has been simplified to just a whitelist. It makes the rest changes to support this revision. tokenAddressLimitReach method has been removed from DepositManagerV1. _tokenAddressLimit has been removed from TokenWhitelist constructor. TOKEN_ADDRESS_LIMIT has been removed along with it's setter. Tests have been updated to accommodate 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 limit check was applied only to non-whitelisted tokens, but the counter it compared against was incremented for every token, including whitelisted ones.
Impact
Bounty minters may be unable to deposit non-whitelisted tokens once enough whitelisted tokens have been deposited.
What the attacker needed
A bounty contract; many whitelisted token deposits
The fix
The project removed the ability to fund with arbitrary tokens, so any token that is not whitelisted now reverts, and the token address limit was removed.
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.
A smart contract lets people add tokens to a bounty. It has a cap on how many different token addresses can be stored. The cap was meant to apply only to tokens that are not on an approved list, but approved tokens were counted too, so the cap could be used up by approved tokens and block other tokens.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.