Admin can break _numberOfValidTokens
The admin can repeatedly call removeFromTokenWhitelist on an already-removed token, decrementing the valid token counter each time until it reaches zero. This makes the token whitelist report an incorrect number of valid tokens.
Submitted by cmichel, also found by gzeon and 0x1f8b
The ProtocolGovernance._numberOfValidTokens can be decreased by the admin in the ProtocolGovernance.removeFromTokenWhitelist function:
function removeFromTokenWhitelist(address addr) external {
require(isAdmin(msg.sender), "ADM");
_tokensAllowed[addr] = false;
if (_tokenEverAdded[addr]) {
// @audit admin can repeatedly call this function and sets _numberOfValidTokens to zero. because they don't flip _tokenEverAdded[addr] here
--_numberOfValidTokens;
}
}
This function can be called repeatedly until the _numberOfValidTokens is zero.
Impact
The _numberOfValidTokens is wrong and with it the tokenWhitelist().
Recommended Mitigation Steps
It seems that _numberOfValidTokens should only be decreased if the token was previously allowed:
function removeFromTokenWhitelist(address addr) external {
require(isAdmin(msg.sender), "ADM");
if (_tokensAllowed[addr]) {
_tokensAllowed[addr] = false;
--_numberOfValidTokens;
}
}
0xleastwood (judge) commented:
Can you confirm if this issue is valid or not? @MihanixA
0xleastwood (judge) commented:
Just realised this is a duplicate of another issue. Marking this as the primary issue
MihanixA (Mellow Protocol) commented:
@0xleastwood Confirmed, it’s a bug.
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
Likely the function decrements the counter without checking whether the token was previously allowed, so repeated calls on an already-removed token keep decreasing the count.
Impact
The token whitelist count becomes incorrect, which could affect any logic that relies on it.
What the attacker needed
Admin privileges
The fix
The counter should only be decreased if the token was previously allowed, by checking the allowed status before decrementing.
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 keeps a count of how many tokens are allowed. The admin can remove a token from the allowed list, but the code does not check if the token was already removed. So the admin can call the removal function many times for the same token, and the count goes down each time, even though no new token was removed. This makes the count wrong.
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.