Wrong implementation of withdrawAdminFees() can cause the adminFees to be charged multiple times and therefore cause users’ fund loss
The withdrawAdminFees function does not reset the adminFees balance after transferring tokens, allowing the admin to withdraw the same fees multiple times. This can slowly drain funds from liquidity providers.
Submitted by WatchPug
function withdrawAdminFees(Swap storage self, address to) internal {
IERC20[] memory pooledTokens = self.pooledTokens;
for (uint256 i = 0; i < pooledTokens.length; i++) {
IERC20 token = pooledTokens[i];
uint256 balance = self.adminFees[i];
if (balance != 0) {
token.safeTransfer(to, balance);
}
}
}
self.adminFees[i] should be reset to 0 every time it’s withdrawn. Otherwise, the adminFees can be withdrawn multiple times.
The admin may just be unaware of this issue and casualty withdrawAdminFees() from time to time, and rug all the users slowly.
Recommended Mitigation Steps
Change to:
function withdrawAdminFees(Swap storage self, address to) internal {
IERC20[] memory pooledTokens = self.pooledTokens;
for (uint256 i = 0; i < pooledTokens.length; i++) {
IERC20 token = pooledTokens[i];
uint256 balance = self.adminFees[i];
if (balance != 0) {
self.adminFees[i] = 0;
token.safeTransfer(to, balance);
}
}
}
LayneHaber (Connext) confirmed and resolved:
0xleastwood (judge) commented:
Completely agree with the validity of this finding. Even if the admin was not malicious, the bug will still continue to withdraw additional fees which were not included as part of the swap calculations. LPs would lose considerable value as a result.
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 withdrawAdminFees function transfers the admin fees but does not reset the stored adminFees balance to zero, so the same amount can be withdrawn repeatedly.
Impact
The admin could withdraw the same fees multiple times, slowly draining funds from liquidity providers, even if unintentional.
What the attacker needed
Admin privileges; admin calls withdrawAdminFees repeatedly
The fix
The function should set self.adminFees[i] to 0 before transferring the tokens, and this was fixed in a later commit.
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 a smart contract, fees collected for the admin are stored in a variable. When the admin withdraws them, the contract sends the tokens but forgets to set the stored amount back to zero. So the admin can call withdraw again and again, each time receiving the same tokens, which ultimately takes money from the pool that belongs to liquidity providers.
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.