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
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.
Potential assets loss for the users who withdraw funds after operator withdraw the fee.
To make things clear here, lets consider the following scenario. To make the scenario easier, just assume there is enough balance for the new user to withdraw.
The detailed example:
Initial state:
Operator call harvest():
The state of vault now:
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:
Operator withdraws the fee:
The state of vault now:
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.
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.
Change the formula that calculate totalAssets() to include operatorFeeAmount to subtract the total balance.
Owl (Liquid Ron) confirmed and commented via duplicate issue S-174:
0xsomeone (judge) increased severity to High and commented via duplicate issue S-174:
Liquid Ron mitigated:
Status: Mitigation confirmed. Full details in reports from Aamir, 0rpse, and ilchovski.
