User can steal funds using `_processNormalSupplyAction` uncapped withdrawal
The `_processNormalSupplyAction` function caps the raw withdrawal amount to the user's total supply but fails to cap the user-specified withdrawal amount, allowing a user to withdraw more tokens than they supplied. An attacker could exploit this to drain funds from the protocol.
Source: https://github.com/sherlock-audit/2026-01-fluid-dex-v2-judging/issues/610
Found by
0x04, 0x23r0, 0x37, 0xBoraichoT, 0xCrypt0nite, 0xSeerBear, 0xShoonya, 0xastronatey, 0xbzbee42, 0xpetern, AV, Baazigar, Bigsam, Billy19d, Bizarro, Blackdruid, BogdanCastraveti, Draxen, EddiePumpin, Edoscoba, ElmInNyc99, Frontrunner, I1iveF0rTh1Sh1t, Icon_0x, Leaningone, Merlinsan, Proof-of-Spirit, Riceee, Ridden5839, SecurityAgentOZ, Thisisit, Waydou, Wojack, ZeroTrust, axelot, botdidy, bratwork, crab0saurus, crunter, elolpuer, ff4de, fgh56ty, fuzious, gabkov, gh0xt, hirusha, i-am-kuldeep, iamephraim, lanrebayode77, legat, luc1jan, maigadoh, neeloy, nonso72, oct0pwn, pranamya, rajatbeladiya, slowpoke, thimthor, vivekd, xiaoming90
Summary
In contracts/protocols/moneyMarket/core/operateModule/helpers.sol, _processNormalSupplyAction caps the withdrawalAmountRaw to the totalRawSupply of the user's position, but does not cap the user's withdrawal amount specified (supplyAmount) based on the totalRawSupply of the user's position (the amount user has previously supplied).
Hence, users can withdraw more than they supplied, protocol loss of funds.
Root Cause
In contracts/protocols/moneyMarket/core/operateModule/helpers.sol, _processNormalSupplyAction caps the withdrawalAmountRaw to the totalRawSupply of the user's position, but does not cap the user's withdrawal amount specified (supplyAmount) based on the totalRawSupply of the user's position (the amount user has previously supplied).
if (supplyAmount_ == type(int256).min) {
...<SNIP>...
} else {
withdrawAmountRaw_ = (((uint256(-supplyAmount_) * LC.EXCHANGE_PRICES_PRECISION) + 1) / supplyExchangePrice_) + 1; // rounded up so protocol is on the winning side
@> if (withdrawAmountRaw_ > tokenRawSupply_) withdrawAmountRaw_ = tokenRawSupply_; // added this check for safety
}
Internal Pre-conditions
N/A
External Pre-conditions
N/A
Attack Path
Conditions of example:
- Current
supplyExchangePriceis 1e12
Example:
- User creates a normal supply position and supplies a minimum amount (e.g. 1e6) of tokens.
tokenRawSupplyof user's_positionDatais populated as follows. User now has an NFT and a position in the NFT
// tokenRawSupply_ = ((uint256(supplyAmount_) * LC.EXCHANGE_PRICES_PRECISION) - 1) / supplyExchangePrice_;
// if (tokenRawSupply_ > 0) tokenRawSupply_ -= 1;
_positionData[][].tokenRawSupply = (((1e6 * 1e12) - 1) / 1e12) - 1 = 999998
- User withdraws from the above position with
supplyAmountof -1000e18 (or any amount > type(int256).min). This is more than what the user has supplied. In_processNormalSupplyAction,withdrawAmountRaw_is greater thantotalRawSupplyof the user's position, so it will be capped, and_updateStorageForWithdrawdeletes user's_positionData.
// if (supplyAmount_ == type(int256).min) {
// } else {
// withdrawAmountRaw_ = (((uint256(-supplyAmount_) * LC.EXCHANGE_PRICES_PRECISION) + 1) / supplyExchangePrice_) + 1;
// if (withdrawAmountRaw_ > tokenRawSupply_) withdrawAmountRaw_ = tokenRawSupply_;
// }
withdrawAmountRaw_ = (((-(-1000e18) * 1e12) + 1) / 1e12) + 1
= 1000000000000000000001
= 999998 // capped to user's totalRawSupply
- However,
supplyAmountis not correspondingly capped based on thetotalRawSupplyof the user's position. Thereafter,_processNormalSupplyActioncallsLIQUIDITY.operateto transfer 1000e18 of tokens to user.
LIQUIDITY.operate(token_, supplyAmount_, 0, to_, address(0), abi.encode(MONEY_MARKET_IDENTIFIER, NORMAL_WITHDRAW_ACTION_IDENTIFIER));
// supplyAmount not capped based on `totalRawSupply` of the user's position
// supplyAmount is still -1000e18 at this point
- User supplied 1e6 tokens but withdraws 1000e18 tokens. User withdraws more than they supplied, protocol loss of funds.
Impact
- User withdraws more than they supplied
- Protocol loss of funds
PoC
Refer attack path
Mitigation
If withdrawAmountRaw_ exceed tokenRawSupply_, cap the supplyAmount based on the tokenRawSupply_
} else {
withdrawAmountRaw_ = (((uint256(-supplyAmount_) * LC.EXCHANGE_PRICES_PRECISION) + 1) / supplyExchangePrice_) + 1; // rounded up so protocol is on the winning side
- if (withdrawAmountRaw_ > tokenRawSupply_) withdrawAmountRaw_ = tokenRawSupply_; // added this check for safety
+ if (withdrawAmountRaw_ > tokenRawSupply_){
+ withdrawAmountRaw_ = tokenRawSupply_;
+ uint256 withdrawAmount_ = ((tokenRawSupply_ * supplyExchangePrice_) - 1) / LC.EXCHANGE_PRICES_PRECISION;
+ if (withdrawAmount_ > 0) withdrawAmount_ -= 1;
+ supplyAmount_ = -int256(withdrawAmount_);
+ }
}
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 withdrawal amount specified by the user (`supplyAmount`) is not capped to the user's total raw supply when the computed raw withdrawal exceeds it.
Impact
A user could withdraw more tokens than they supplied, causing a loss of funds for the protocol.
What the attacker needed
A supply position with tokens
The fix
The code should cap the `supplyAmount` based on the user's `tokenRawSupply_` when the computed withdrawal exceeds it.
How it was found
- User creates a normal supply position and supplies a minimum amount of tokens.
- User withdraws with a supplyAmount larger than what they supplied.
- The raw withdrawal amount is capped to the user's total raw supply, but the supplyAmount remains uncapped.
- The protocol transfers the uncapped supplyAmount to the user, resulting in a loss.
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 money market, users deposit tokens and get a position. When withdrawing, the code should limit the withdrawal to what was deposited. Here, a check limits one internal number but not the actual amount requested, so a user can ask for more than they put in and receive extra tokens, stealing from the protocol.
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.