Owner can collect management fees with a new increased fee for previous time period.
The vault owner can change the management fee and then collect fees for a past period using the new higher rate, because the timestamp of the last fee update is not reset when the fee changes. This lets the owner charge more than intended for time when a lower or zero fee was active.
GreedyGoblin Follow with chaduke, jasonxiale and 2 others
Originally disclosed on Code4rena
Submitted by GreedyGoblin, also found by chaduke, jasonxiale, 0xNineDec, and peakbolt
https://github.com/code-423n4/2023-01-popcorn/blob/main/src/vault/Vault.sol#L480
https://github.com/code-423n4/2023-01-popcorn/blob/main/src/vault/Vault.sol#L488
https://github.com/code-423n4/2023-01-popcorn/blob/main/src/vault/Vault.sol#L540
https://github.com/code-423n4/2023-01-popcorn/blob/main/src/vault/Vault.sol#L429
Impact
The Owner of the contract can change the fee, and after the rage quit period it can cash those fees for the period of time where different fees were active.
This allows the Owner to collect as much management fee as it wants for an already passed time period, when it should only apply from the time it has been changed.
Proof of Concept
This contract allows the Owner to change the fees. To do so the proposeFees() procedure is called. This procedure will update the proposed fees, which then can be applied by calling the changeFees() procedure after the rage quit period has passed (the rage quit period is a period of time that has to pass between proposing a fee and applying it).
To collect the fees, the Owner calls the procedure takeManagementAndPerformanceFees(). This procedure contains the modifier takeFees() which collects the fees.
modifier takeFees() {
uint256 managementFee = accruedManagementFee();
uint256 totalFee = managementFee + accruedPerformanceFee();
uint256 currentAssets = totalAssets();
uint256 shareValue = convertToAssets(1e18);
if (shareValue > highWaterMark) highWaterMark = shareValue;
if (managementFee > 0) feesUpdatedAt = block.timestamp;
if (totalFee > 0 && currentAssets > 0)
_mint(feeRecipient, convertToShares(totalFee));
_;
}
Inside the takeFees() modifier the code if (managementFee > 0) feesUpdatedAt = block.timestamp; updates the variable feesUpdatedAt only if the fees are greater than 0. This variable is used as a timestamp of when was the last time fees were collected.
managementFee is calculated using the function accruedManagementFees().
function accruedManagementFee() public view returns (uint256) {
uint256 managementFee = fees.management;
return
managementFee > 0
? managementFee.mulDiv(
totalAssets() * (block.timestamp - feesUpdatedAt),
SECONDS_PER_YEAR,
Math.Rounding.Down
) / 1e18
: 0;
}
Here the managementFee is calculated using the feesUpdatedAt variable. In the calculation, the further apart the feesUpdated is in comparison to the block.timestamp, the greater the fee will be.
This feesUpdatedAt variable is not updated when the fee is changed using changeFee() or when the fees are proposed using proposeFee(). This allows the owner to collect a fee for a period of time where the fee was different.
Current behaviour:
Change fee to 2
|
v Collect fees with
Fee = 0 Fee = 2 managementFee = 2
| | |
v v v
-----------------------------------------------------
^ ^ ^
| | |
| Day 0 Day 5 Day 7 |
| |
+-------------------------------------------------------+
Period of time of fees
collected with
management fee = 2
Ideal behaviour:
Change fee to 2
|
v Collect fees with
Fee = 0 Fee = 2 managementFee = 2
| | |
v v v
-----------------------------------------------------
^ ^ ^
| | |
| Day 0 Day 5 Day 7 |
| | |
+-----------------------------+-------------------------+
Period of time of fees Period of time of fees
collected with collected with
management fee = 0 management fee = 2
The diagrams show how the management fees are charged for a period of time where they were not active. The ideal behaviour diagram shows how it should behave in order to apply the management fees fairly.
Steps:
- Create vault with 0 fees
- Wait x amount of days
- Change fee to something bigger than the previous fee
- Collect the fees (fees collected will be from creation of vault until now with the new fee)
With these 4 steps, a Vault creator can charge a new management fee for period of time where a different fee was active.
Tools Used
Visual Studio Code
Recommended Mitigation Steps
The variable feesUpdatedAt should be updated even when the fees are 0.
Fees should be collected when a new fee is applied, therefore the time period where the former fee was current will be collected correctly and the feesUpdatedAt variable will be updated to the timestamp of when the new fee has been applied.
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 fee update timestamp is only refreshed when fees are collected and the management fee is greater than zero, not when the fee rate is changed.
Impact
The owner could collect more management fees than deserved for a past period, potentially taking assets from the vault.
What the attacker needed
Owner privileges; vault with assets
The fix
The fee update timestamp should be refreshed whenever the fee is changed, and fees should be collected before applying a new fee.
How it was found
- Create a vault with zero fees.
- Wait for some days.
- Change the fee to a higher value.
- Collect the fees, which will be calculated from vault creation to now using the new fee.
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 charges a management fee over time, like interest. The fee rate can be changed by the owner, but the contract forgets to reset the clock when the rate changes. So the owner can set a high rate and then charge it for the whole time since the last fee collection, even though the high rate was only active for a short while.
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.