Early funds withdrawers can get bonus in multiples of vested bonus tokens (e.g. 2-times, 3-times, etc.)
The setBonusToken function allowed the same bonus token to be added multiple times to an array. When bonus rewards were distributed during a withdrawal, the duplicate entries caused the same token to be released more than once, letting early withdrawers receive multiples of their entitled bonus while later withdrawers might get none.
Submitted by hubble, also found by Ruhum
Vulnerability details
The function setBonusToken allows the same BonusToken to be added more than once to the array bonusTokens.
function setBonusToken(address newBonusERC20) external onlyBathHouse {
bonusTokens.push(newBonusERC20);
}
Impact
If that happens, early withdrawers can get Bonus in multiples of what they actually have the right to. Late withdrawers, might not get any Bonus due to shortage.
Proof of Concept
BathToken.sol, function setBonusToken
-
function setBonusToken allows the same BonusToken to be added more than once to the array.
BathToken.sol, function
distributeBonusTokenRewards
-
a. As and when distributeBonusTokenRewards is triggered during a withdraw call, the same bonusToken will be released more than once.
BathBuddy.sol, function release
-
b. The release function is called.
Recommended Mitigation Steps
Add the required validations to avoid duplicate additions of bonus tokens.
function setBonusToken(address newBonusERC20) external onlyBathHouse {
require(newBonusERC20 != address(0), "invalid_addr");
if (bonusTokens.length > 0) {
for (uint256 index = 0; index < bonusTokens.length; index++) {
require (token != newBonusERC20, "token already exists")
}
}
bonusTokens.push(newBonusERC20);
}
Similar, but different to unbounded tokens case because it’s about duplicates.
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 setBonusToken function lacked a check to prevent adding the same token address more than once to the bonusTokens array.
Impact
Early withdrawers could receive bonus tokens in multiples of their entitlement, potentially leaving later withdrawers with no bonus due to a shortage.
What the attacker needed
The ability to call setBonusToken (onlyBathHouse); a bonus token already added or being added
The fix
The setBonusToken function should be fixed to reject duplicate token addresses by checking the existing array before pushing a new entry.
How it was found
- Call setBonusToken with the same bonus token address more than once, adding duplicates to the array.
- Trigger a withdrawal that calls distributeBonusTokenRewards.
- The release function is called for each duplicate entry, releasing the same bonus token multiple times.
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 stored a list of bonus tokens but did not check for duplicates. If the same token was added twice, the payout logic would send that bonus twice to whoever withdrew first, using up funds meant for others.
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.