Skip to content
Business logic Audit finding Intermediate

The calculation of totalAssets() could be wrong if operatorFeeAmount > 0 , this can cause potential loss for the new depositors

The vault's totalAssets() calculation included the operator's accumulated fee, which is held as WRON tokens in the vault. When the operator later withdrew the fee, totalAssets() dropped, causing users who deposited while the fee was pending to receive fewer assets on withdrawal than expected.

0x04bytes Follow with 056Security, 0x0dd and 48 others

Originally disclosed on Code4rena

Submitted by 0x04bytes, also found by 056Security, 0rpse (1, 2), 0x0bserver (1, 2), 0x0dd, 0x23r0, 0xAlix2, 0xDemon, 0xG0P1, 0xRajkumar, 0xrex, 0xvd, Aamir, aariiif, Adotsam, air_0x, aldarion, Alekso, arman, attentioniayn, Bauchibred, bigbear1229, BlackAdam, Breeje (1, 2), ccvascocc, csanuragjain, curly, Darinrikusham, DemoreX, DoD4uFN, ElCid, emerald7017, EPSec, eta, Fitro, future2_22, gesha17, grearlake, harry_cryptodev, hrmneffdii, hyuunn, ilchovski, IlIlHunterlIlI, JCN, Josh4324, jsonDoge, klau5, muncentu, nnez, oakcobalt (1, 2), PabloPerez, peanuts, phoenixV110, roccomania, rudhra, Ryonen, santiellena, serial-coder, Shahil_Hussain, silver_eth, sl1, spuriousdragon, stuart_the_minion, t0x1c (1, 2), Tadev, udogodwin, valy001, victortheoracle, wellbyt3, y4y, YouCrossTheLineAlfie, zainab_ou, and zraxx

LiquidRon.sol#L293-L295 LiquidRon.sol#L121-L126

Description

The fee accumulated by operator is stored in operatorFeeAmount. The amount is directly recorded based on the number of actual assets accumulated, not the portion of shares. The problem is, this fee is stored in the vault contract as WRON token balance together with the assets deposited by the users.

Because the calculation of totalAssets() will also depend on the WRON token balance owned by the vault contract, the fee withdrawn by the operator can decrease the total assets in circulation. It means that the users who withdraw their funds after the operator withdraw the fee will receive less assets than the users who withdraw before the fee withdrawal.

Impact

Potential assets loss for the users who withdraw funds after operator withdraw the fee.

Proof of Concept

To make things clear here, let’s consider the following scenario. To make the scenario easier, just assume there is enough balance for the new user to withdraw.

  1. The operator call harvest(). This will increase WRON balance owned by the vault and also increase operatorFeeAmount.
  2. A new user deposit assets and receive shares. The calculation of totalAssets() will include the amount of operator’s fee.
  3. The operator withdraw the fee by calling fetchOperatorFee() function.
  4. The new user withdraw his funds by calling redeem(). Now the user receives less assets because the calculation of totalAssets() will be based on the new WRON balance after fee withdrawal.

The detailed example:

Initial state:

totalBalance = 10000 // balance in all (vault, staked, rewards)
totalShares = s // just assume it is a variable `s` to make the calculation easier
operatorFeeAmount = 0

Operator call harvest():

The state of vault now:

totalBalance = 10000 // the total balance is not changed, just the form is changed from rewards into actual WRON
totalShares = s
operatorFeeAmount = 10 // let's assume the operator get 10 units as fee

New user deposit 100 units:

The number of shares received by the new user:

userShares = (100*totalShares)/totalBalance userShares = (100*s)/10000 userShares = (1/100)s

The step above will increase the totalShares.

The state of vault now:

totalBalance = 10100 // including the deposit by new user
totalShares = s + s/100
operatorFeeAmount = 10

Operator withdraws the fee:

The state of vault now:

totalBalance = 10090 // total balance is decreased by 10 as operator withdraw the fee
totalShares = s + s/100
operatorFeeAmount = 0

The user withdraw his funds:

The assets received by the new user will be:

userAsset = (userShares*totalBalance)/totalShares userAsset = ((s/100) * 10090)/(s + (s/100)) userAsset = ((s/100) * 10090)/((101/100)s) userAsset = 10090/101 userAsset = 99.9

After withdrawal, the new user will receive 99.9 units. The new user loss 0.1 units.

POC Code

Copy the POC code below to LiquidRonTest contract in test/LiquidRon.t.sol and then run the test.

function test_withdraw_new_user() public {
        address user1 = address(0xf1);
        address user2 = address(0xf2);

        uint256 amount = 100000 ether;
        vm.deal(user1, amount);
        vm.deal(user2, amount);

        vm.prank(user1);
        liquidRon.deposit{value: amount}();

        uint256 delegateAmount = amount / 7;
        uint256[] memory amounts = new uint256[](5);
        for (uint256 i = 0; i < 5; i++) {
            amounts[i] = delegateAmount;
        }
        liquidRon.delegateAmount(0, amounts, consensusAddrs);

        skip(86400 * 365 + 2 + 1);
        // operator fee before harvest
        assertTrue(liquidRon.operatorFeeAmount() == 0);
        liquidRon.harvest(0, consensusAddrs);
        // operator fee after harvest
        assertTrue(liquidRon.operatorFeeAmount() > 0);

        // new user deposit
        vm.prank(user2);
        liquidRon.deposit{value: amount}();
        uint256 user2Shares = liquidRon.balanceOf(user2);
        uint256 expectedRedeemAmount = liquidRon.previewRedeem(user2Shares);

        // fee withdrawal by operator
        liquidRon.fetchOperatorFee();
        assertTrue(liquidRon.operatorFeeAmount() == 0);

        // user2 redeem all his shares
        vm.prank(user2);
        liquidRon.redeem(user2Shares, user2, user2);

        console.log(user2.balance);
        console.log(expectedRedeemAmount);
        assertTrue(user2.balance == expectedRedeemAmount);
    }

Based on the POC code above, the last assertion assertTrue(user2.balance == expectedRedeemAmount); will fail because the amount withdrawn is not equal to the expected withdrawn.

Recommended Mitigation Steps

Change the formula that calculate totalAssets() to include operatorFeeAmount to subtract the total balance.

function totalAssets() public view override returns (uint256) {
-        return super.totalAssets() + getTotalStaked() + getTotalRewards();
+        return super.totalAssets() + getTotalStaked() + getTotalRewards() - operatorFeeAmount;
    }

Owl (Liquid Ron) confirmed and commented via duplicate issue S-174:

A simpler fix would be to include operationFeeAmount in total assets like such:

    function totalAssets() public view override returns (uint256) {
        return super.totalAssets() + getTotalStaked() + getTotalRewards() - operationFeeAmount;
    }

0xsomeone (judge) increased severity to High and commented via duplicate issue S-174:

The finding and its duplicates outline that the accumulated operator fee is factored in total asset calculations despite being meant to be redeemed as a fee.

Apart from contradicting the EIP-4626 standard, it allows the operator fee to be redeemed by users, undervalues deposits made when a non-zero operator fee exists, and abruptly reduces the total assets whenever the operator fee is claimed.

I believe the consistent dilution of all incoming deposits whenever a non-zero operator fee is present to be a significant issue and one that would merit a high severity rating. Specifically:

  • The vulnerability is consistently present whenever an operator fee is realized (i.e. operatorFeeAmount is non-zero) - Likelihood of High.
  • The impact of the vulnerability is significant as it devalues all incoming user deposits whenever a non-zero fee is present and can also result in the operatorFeeAmount becoming irredeemable in extreme circumstances (i.e. total withdrawal of vault) - Impact of Medium.

Combining the likelihood and impact traits above, I believe that a severity level of high is better suited for this issue.

Liquid Ron mitigated:

Add operatorFeeAmount in totalAssets calculations.

Status: Mitigation confirmed. Full details in reports from Aamir, 0rpse, and ilchovski.


The original report as published on Code4rena, by 0x04bytes. 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 totalAssets() function did not subtract operatorFeeAmount, so the fee was counted as user-owned assets until it was withdrawn.

Impact

Users who deposit while a non-zero operator fee exists could lose part of their deposit when they withdraw after the fee is claimed; the judge noted the fee could also become irredeemable in extreme cases.

What the attacker needed

OperatorFeeAmount is greater than zero; user deposits before the operator claims the fee; user withdraws after the fee is claimed

The fix

The totalAssets() calculation was changed to subtract operatorFeeAmount, and the mitigation was confirmed.

How it was found

  1. The operator calls harvest(), increasing the vault's WRON balance and operatorFeeAmount.
  2. A new user deposits assets and receives shares based on a totalAssets() that includes the operator fee.
  3. The operator withdraws the fee by calling fetchOperatorFee().
  4. The new user redeems all shares and receives less than the expected amount.

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 holds users' deposits and also tracks a fee owed to the operator. The vault's share price is based on the total assets it reports, but that total wrongly included the operator's fee. When the operator took the fee out, the reported total fell, so anyone who joined before the withdrawal got less back than they should.

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

View all

1 more disclosed report, best first.

More from Liquid Ron

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.