Protocol loses fees because highWaterMark is updated every time someone deposit, withdraw, mint
The vault's highWaterMark is updated on every deposit, mint, or withdraw, so the protocol loses track of yield and cannot charge performance fees. An attacker can front-run the fee-taking call with a small deposit to reset the highWaterMark and prevent the protocol from collecting fees.
rvierdiiev Follow with peakbolt
Originally disclosed on Code4rena
Submitted by rvierdiiev, also found by peakbolt
https://github.com/code-423n4/2023-01-popcorn/blob/main/src/vault/Vault.sol#L138
https://github.com/code-423n4/2023-01-popcorn/blob/main/src/vault/Vault.sol#L215
https://github.com/code-423n4/2023-01-popcorn/blob/main/src/vault/Vault.sol#L480-L499
https://github.com/code-423n4/2023-01-popcorn/blob/main/src/vault/Vault.sol#L447-L460
Impact
Protocol loses fees because highWaterMark is updated every time someone deposit, withdraw, mint.
Proof of Concept
This bug is related to the fees accruing design. It was discussed with the sponsor in order to understand how it should work.
Protocol has such thing as performance fee. Actually this is fee from accrued yields. If user deposited X assets and after some time he can withdraw X+Y assets for that minted amount of shares, that means that strategy has earned some Y amount of yields. Then protocol is able to get some part of that Y amount as a performance fee.
takeFees modifier is responsible for taking fees.
It calls accruedPerformanceFee function to calculate fees amount.
https://github.com/code-423n4/2023-01-popcorn/blob/main/src/vault/Vault.sol#L447-L460
function accruedPerformanceFee() public view returns (uint256) {
uint256 highWaterMark_ = highWaterMark;
uint256 shareValue = convertToAssets(1e18);
uint256 performanceFee = fees.performance;
return
performanceFee > 0 && shareValue > highWaterMark
? performanceFee.mulDiv(
(shareValue - highWaterMark) * totalSupply(),
1e36,
Math.Rounding.Down
)
: 0;
}
As you can see, protocol has such variable as highWaterMark. This variable actually should store convertToAssets(1e18) amount at the time when last fee were accrued or after first deposit. Then after some time when strategy earned some yields, convertToAssets(1e18) will return more assets than highWaterMark, so protocol will take fees.
But currently updating of highWaterMark is done incorrectly.
Deposit, mint, withdraw function use syncFeeCheckpoint modifier.
https://github.com/code-423n4/2023-01-popcorn/blob/main/src/vault/Vault.sol#L496-L499
modifier syncFeeCheckpoint() {
_;
highWaterMark = convertToAssets(1e18);
}
This modifier will update highWaterMark to current assets amount that you can receive for 1e18 of shares.
That means that every time when deposit, mint, withdraw is called, highWaterMark is updated to the new state, so protocol doesn’t track yield progress anymore.
In case if protocol accrued some performance fees, which can be possible if noone called deposit, withdraw, mint for a long time, then anyone can frontrun takeFees and deposit small amount of assets in order to update highWaterMark, so protocol will not get any fees.
Tools Used
VS Code
Recommended Mitigation Steps
I believe that you need to store highWaterMark = convertToAssets(1e18) at the time of first deposit, or when totalShares is 0, this will be the value that protocol started with and then at time, when takefee was called you can calculate current convertToAssets(1e18) in case if it’s bigger, than previous stored, then you can mint fees for protocol and update highWaterMark to current value.
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
The syncFeeCheckpoint modifier updates highWaterMark after every deposit, mint, and withdraw, instead of only when fees are accrued or at the first deposit.
What the attacker needed
Performance fee > 0; no recent deposit/withdraw/mint; attacker can front-run takeFees
The fix
The highWaterMark should only be set at the first deposit (when total supply is zero) and updated only when fees are actually taken, not on every user action.
How it was found
- Wait until performance fees have accrued and no deposit, withdraw, or mint has occurred for a while.
- Front-run the takeFees call by depositing a small amount of assets.
- The deposit triggers syncFeeCheckpoint, which sets highWaterMark to the current share value.
- The subsequent takeFees call sees no profit above the new highWaterMark and takes no fees.
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 performance fee on profits, using a stored value called highWaterMark to remember the share price at the last fee charge. The bug is that this stored value is reset on every user deposit or withdrawal, so the vault forgets earlier profits. An attacker can make a tiny deposit just before fees are taken, resetting the value and causing the protocol to miss its fees.
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.