Skip to content
Business logic Audit finding Intermediate

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.

0x04 Follow with 0x23r0, 0x37 and 47 others

Originally disclosed on Sherlock

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).

JavaScript
            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:

  1. Current supplyExchangePrice is 1e12

Example:

  1. User creates a normal supply position and supplies a minimum amount (e.g. 1e6) of tokens. tokenRawSupply of user's _positionData is populated as follows. User now has an NFT and a position in the NFT
JavaScript
// tokenRawSupply_ = ((uint256(supplyAmount_) * LC.EXCHANGE_PRICES_PRECISION) - 1) / supplyExchangePrice_;
// if (tokenRawSupply_ > 0) tokenRawSupply_ -= 1;

_positionData[][].tokenRawSupply = (((1e6 * 1e12) - 1) / 1e12) - 1 = 999998
  1. User withdraws from the above position with supplyAmount of -1000e18 (or any amount > type(int256).min). This is more than what the user has supplied. In _processNormalSupplyAction, withdrawAmountRaw_ is greater than totalRawSupply of the user's position, so it will be capped, and _updateStorageForWithdraw deletes user's _positionData.
JavaScript
// 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
  1. However, supplyAmount is not correspondingly capped based on the totalRawSupply of the user's position. Thereafter, _processNormalSupplyAction calls LIQUIDITY.operate to transfer 1000e18 of tokens to user.
JavaScript
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
  1. User supplied 1e6 tokens but withdraws 1000e18 tokens. User withdraws more than they supplied, protocol loss of funds.

Impact

  1. User withdraws more than they supplied
  2. Protocol loss of funds

PoC

Refer attack path

Mitigation

If withdrawAmountRaw_ exceed tokenRawSupply_, cap the supplyAmount based on the tokenRawSupply_

Diff
            } 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_);
+               }
            }

The original report as published on Sherlock, by 0x04. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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

  1. User creates a normal supply position and supplies a minimum amount of tokens.
  2. User withdraws with a supplyAmount larger than what they supplied.
  3. The raw withdrawal amount is capped to the user's total raw supply, but the supplyAmount remains uncapped.
  4. 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.

More by 0x04

View all

3 more disclosed reports, best first.

More from Fluid DEX v2

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.