investedAssets() Does Not Take Into Consideration The Performance Fee Charged On Strategy Withdrawals
The investedAssets() function does not subtract the performance fee that would be charged when strategy assets are withdrawn. An attacker could withdraw before fees are charged and re-enter after, avoiding their share of the performance fee.
Submitted by leastwood, also found by danb
The investedAssets() function is implemented by the vault’s strategy contracts as a way to express a vault’s investments in terms of the underlying currency. While the implementation of this function in BaseStrategy.sol and NonUSTStrategy.sol is mostly correct. It does not account for the performance fee charged by the treasury as shown in finishRedeemStable().
Therefore, an attacker could avoid paying their fair share of the performance fee by withdrawing their assets before several calls to finishRedeemStable() are made and reenter the vault once the fee is charged.
Proof of Concept
function finishRedeemStable(uint256 idx) public virtual {
require(redeemOperations.length > idx, "not running");
Operation storage operation = redeemOperations[idx];
uint256 aUstBalance = _getAUstBalance() + pendingRedeems;
uint256 originalUst = (convertedUst * operation.amount) / aUstBalance;
uint256 ustBalanceBefore = _getUstBalance();
ethAnchorRouter.finishRedeemStable(operation.operator);
uint256 redeemedAmount = _getUstBalance() - ustBalanceBefore;
uint256 perfFee = redeemedAmount > originalUst
? (redeemedAmount - originalUst).percOf(perfFeePct)
: 0;
if (perfFee > 0) {
ustToken.safeTransfer(treasury, perfFee);
emit PerfFeeClaimed(perfFee);
}
convertedUst -= originalUst;
pendingRedeems -= operation.amount;
operation.operator = redeemOperations[redeemOperations.length - 1]
.operator;
operation.amount = redeemOperations[redeemOperations.length - 1].amount;
redeemOperations.pop();
}
function investedAssets()
external
view
virtual
override(IStrategy)
returns (uint256)
{
uint256 underlyingBalance = _getUnderlyingBalance() + pendingDeposits;
uint256 aUstBalance = _getAUstBalance() + pendingRedeems;
return
underlyingBalance +
((exchangeRateFeeder.exchangeRateOf(address(aUstToken), true) *
aUstBalance) / 1e18);
}
function investedAssets()
external
view
override(BaseStrategy)
returns (uint256)
{
uint256 underlyingBalance = _getUnderlyingBalance();
uint256 aUstBalance = _getAUstBalance() + pendingRedeems;
uint256 ustAssets = ((exchangeRateFeeder.exchangeRateOf(
address(aUstToken),
true
) * aUstBalance) / 1e18) + pendingDeposits;
return
underlyingBalance +
curvePool.get_dy_underlying(ustI, underlyingI, ustAssets);
}
Tools Used
Manual code review. Discussions with the Sandclock team (mostly Ryuhei).
Recommended Mitigation Steps
When calculating the investedAssets() amount (expressed in the underlying currency), consider calculating the expected performance fee to be charged if all the strategy’s assets are withdrawn from the Anchor protocol. This should ensure that investedAssets() returns the most accurate amount, preventing users from gaming the protocol.
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 investedAssets() calculation does not deduct the performance fee that finishRedeemStable() would charge upon withdrawal.
Impact
An attacker could avoid paying their fair share of the performance fee, reducing the treasury's revenue.
What the attacker needed
A vault user with strategy assets
The fix
The investedAssets() calculation should subtract the expected performance fee that would be charged if all strategy assets were withdrawn.
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 invests money and charges a performance fee when profits are taken. The function that reports how much is invested ignores this fee, so a user can take money out before the fee is applied and put it back later, paying less 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.