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.
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.
The operator call harvest(). This will increase WRON balance owned by the vault and also increase operatorFeeAmount.
A new user deposit assets and receive shares. The calculation of totalAssets() will include the amount of operator’s fee.
The operator withdraw the fee by calling fetchOperatorFee() function.
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
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.
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.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
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
The operator calls harvest(), increasing the vault's WRON balance and operatorFeeAmount.
A new user deposits assets and receives shares based on a totalAssets() that includes the operator fee.
The operator withdraws the fee by calling fetchOperatorFee().
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
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.