Skip to content
Business logic Audit finding Intermediate

Incorrect Netting Logic Leads to Excessive Withdrawal Amounts

A logic error in the netting calculation during commit causes the withdrawal amount to remain unchanged when both deposits and withdrawals are pending, leading to excessive withdrawal fees for vaults that charge them. An attacker could not exploit this directly, but it results in unnecessary fee payments.

0L5S6W Follow with 0x23r0, 0xpinkman and 19 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-04-burve-judging/issues/174

Found by

0L5S6W, 0x23r0, 0xpinkman, 0xpranav, KungFuPanda, RektOracle, Rhaydden, Sparrow_Jac, TheCarrot, Tigerfrake, aman, anirruth_, curly11, future, imageAfrika, kazan, m3dython, ni8mare, peppef, prosper, shushu, stonejiajia

Summary

A logical error in the netting calculation will cause incorrect withdrawal amounts as the protocol fails to subtract deposit amounts when netting pending transactions properly.

Root Cause

During the trimBalance, the protocol gets the real balance of a vertex:

Solidity
uint256 realBalance = AdjustorLib.toReal(idx, self.balances[idx], true);

which is the targetReal and also within the vertex, the protocol gets the actual balance of the closure based on its share balance in the vault:

Solidity
uint256 realBalance = vProxy.balance(cid, false);

When the real balance is > targetReal, then we have some residual that needs to be withdrawn from the vault, and the bgtResidual:

Solidity
bgtResidual = FullMath.mulDiv(residualReal, bgtValue, value);

becomes the amount to deposit for reserve, thereafter, a commit is made:

Solidity
function trimBalance(
        Vertex storage self,
        ClosureId cid,
        uint256 targetReal,
        uint256 value,
        uint256 bgtValue
    ) internal returns (uint256 reserveSharesEarned, uint256 bgtResidual) {
        VaultProxy memory vProxy = VaultLib.getProxy(self.vid);
        uint256 realBalance = vProxy.balance(cid, false);
        // We don't error and instead emit in this scenario because clearly the vault is not working properly but if
        // we error users can't withdraw funds. Instead the right response is to lock and move vaults immediately.
        if (targetReal > realBalance) {
            emit InsufficientBalance(self.vid, cid, targetReal, realBalance);
            return (0, 0);
        }
        uint256 residualReal = realBalance - targetReal;
        vProxy.withdraw(cid, residualReal);
        bgtResidual = FullMath.mulDiv(residualReal, bgtValue, value);
        reserveSharesEarned = ReserveLib.deposit(
            vProxy,
            self.vid,
            residualReal - bgtResidual
        );
        vProxy.commit();
    }

The issue arises in the commit function, at this point both deposit and withdrawal > 0

Solidity
function commit(VaultE4626 storage self, VaultTemp memory temp) internal {
        uint256 assetsToDeposit = temp.vars[1];
        uint256 assetsToWithdraw = temp.vars[2];

        if (assetsToDeposit > 0 && assetsToWithdraw > 0) {
            // We can net out and save ourselves some fees.
            if (assetsToDeposit > assetsToWithdraw) {
                assetsToDeposit -= assetsToWithdraw;
                assetsToWithdraw = 0;
            } else if (assetsToWithdraw > assetsToDeposit) {
                assetsToDeposit = 0;  // @audit 
                assetsToWithdraw -= assetsToDeposit;
            } else {
                // Perfect net!
                return;
            }
        }

        if (assetsToDeposit > 0) {
            // Temporary approve the deposit.
            SafeERC20.forceApprove(
                self.token,
                address(self.vault),
                assetsToDeposit
            );
            self.totalVaultShares += self.vault.deposit(
                assetsToDeposit,
                address(this)
            );
            SafeERC20.forceApprove(self.token, address(self.vault), 0);
        } else if (assetsToWithdraw > 0) {
            // We don't need to hyper-optimize the receiver.
            self.totalVaultShares -= self.vault.withdraw(
                assetsToWithdraw,
                address(this),
                address(this)
            );
        }
    }

The code sets assetsToDeposit to 0 and then attempts to subtract this value (now 0) from assetsToWithdraw, resulting in no change to the withdrawal amount.

Internal Pre-conditions

  • Both pending deposits (temp.vars[1] > 0) and pending withdrawals (temp.vars[2] > 0) at the time of commit
  • The pending withdrawal amount must be greater than the pending deposit amount (assetsToWithdraw > assetsToDeposit)

External Pre-conditions

  • There is profit on the vault so preview redeem has increased

Attack Path

  • None

Impact

The netting optimization exists to make the protocol more efficient, but this bug prevents it from working properly.

For vaults that charge withdrawal fees (like some yield aggregators), the vault will pay fees on the full withdrawal amount rather than just the net amount.

PoC

No response

Mitigation

Solidity
if (assetsToDeposit > 0 && assetsToWithdraw > 0) {
            if (assetsToDeposit > assetsToWithdraw) {
                assetsToDeposit -= assetsToWithdraw;
                assetsToWithdraw = 0;
            } else if (assetsToWithdraw > assetsToDeposit) {
                assetsToWithdraw -= assetsToDeposit; // audit fix
                assetsToDeposit = 0;
            } else {
                // Perfect net!
                return;
            }
        }

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/itos-finance/Burve/commit/c14995d806cdabc20bfedb094d585ed7b8668c8c

The original report as published on Sherlock, by 0L5S6W. 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

Impact

For vaults that charge withdrawal fees, the vault pays fees on the full withdrawal amount rather than just the net amount, but no direct loss of funds or exploit is demonstrated.

What the attacker needed

Both pending deposits and withdrawals exist; Withdrawal amount exceeds deposit amount; Vault charges withdrawal fees

The fix

The issue was fixed by correcting the order of operations in the netting logic.

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.

When a vault handles both deposits and withdrawals at the same time, it tries to cancel them out to save on fees. A mistake in the code meant that when withdrawals were larger than deposits, the withdrawal amount wasn't reduced by the deposit amount, so the vault paid fees on the full withdrawal instead of just the difference.

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 0L5S6W

View all

4 more disclosed reports, best first.

More from Burve

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.