Skip to content
Business logic Audit finding Intermediate

usedFunds can be greater than totalFunds in contract KangarooVault , which leads to KangarooVault being unable to close its trades and users being unable to withdraw

The KangarooVault contract tracks usedFunds and totalFunds without ensuring totalFunds stays at least usedFunds. If someone sends funds directly to the vault, usedFunds can exceed totalFunds, causing underflow reverts that prevent closing trades and user withdrawals.

KIntern_NA Follow

Originally disclosed on Code4rena

Submitted by KIntern_NA

KangarooVault contract can’t close the trades and users can’t withdraw from it, then users and KangarooVaults will lose a lot of funds.

Proof of concept

  1. In contract KangarooVault, usedFunds is the uint256 variable which tracks the funds utilitized from the vault. And totalFunds is the uin256 variable which tracks the funds claimed by vault from profits and users’ depositing.
  2. Contract KangarooVault has no check if totalFunds >= usedFunds when usedFunds is increased (transfer from vault) or totalFunds is decreased (transfer to vault).
  3. If someone transfers funds directly into the vault, usedFunds can be greater than totalFunds because the vault can transfer out more than totalFunds.
  4. When usedFunds > totalFunds, KangarooVault can not close its trades because it will revert on underflow in function _resetTrade:
function _resetTrade() internal {
        ...
        totalFunds -= usedFunds;
        ...
    }
  1. When usedFunds > totalFunds, user can’t not withdraw by function processWithdrawalQueue because it will revert on underflow.
function processWithdrawalQueue(uint256 idCount) external nonReentrant {
    for (uint256 i = 0; i < idCount; i++) {
        ...

        uint256 availableFunds = totalFunds - usedFunds;

        ...

Scenario:

  • A deposit 1000 SUSD, then totalFunds = 1000 SUSD, usedFunds = 0
  • B transfer directly 1000 SUSD to the KangarooVault, that doesn’t change totalFunds and usedFunds
  • KangarooVault opens a short position and uses 2000 SUSD to increase the margin, then usedFunds = 2000
  • After that, usedFunds > totalFunds (2000 > 1000) then KangarooVault can’t close its position

Recommended Mitigation Steps

Should add the checks if totalFunds >= usedFunds when increasing usedfunds or decreasing totalFunds in contract KangarooVault.sol.

mubaris (Polynomial) acknowledged, but disagreed with severity

Dravee (judge) decreased severity to Medium


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

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 contract does not check that totalFunds is at least usedFunds when usedFunds increases or totalFunds decreases, so a direct transfer can make usedFunds exceed totalFunds.

Impact

KangarooVault cannot close its trades and users cannot withdraw, so users and the vault could lose funds.

What the attacker needed

Attacker can transfer funds directly to the vault; vault opens a position using more than totalFunds

The fix

The contract should check that totalFunds is at least usedFunds when usedFunds is increased or totalFunds is decreased.

How it was found

  1. A deposits 1000 SUSD, setting totalFunds to 1000 and usedFunds to 0.
  2. B transfers 1000 SUSD directly to the KangarooVault, which does not change totalFunds or usedFunds.
  3. KangarooVault opens a short position and uses 2000 SUSD to increase the margin, setting usedFunds to 2000.
  4. Now usedFunds (2000) is greater than totalFunds (1000), so KangarooVault cannot close its position.

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 vault contract keeps two numbers: totalFunds (money it thinks it has) and usedFunds (money it has lent out or used). If someone sends money straight to the contract, the contract does not update totalFunds, so it can later use more than it recorded. When it tries to subtract usedFunds from totalFunds, the maths goes negative and the transaction fails, locking the vault.

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 KIntern_NA

View all

21 more disclosed reports, best first.

More from Polynomial Protocol contest

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.