Anyone can call StrategySupplyBase.harvest , allowing users to avoid paying performance fees on interest
The harvest function in StrategySupplyBase could be called by anyone, allowing users to front-run the administrator's rebalance call or call harvest regularly to avoid paying performance fees on interest. This let users receive more interest than they should.
Submitted by klau5, also found by 0xlemon, 0xpiken, and shaflow2
Finding description and impact
Since StrategySupplyBase.harvest can be called by anyone, users can front-run the rebalance call or regularly call harvest to avoid paying protocol fees on interest. This allows users to receive more interest than they should.
Proof of Concept
When there are profits in the Strategy, the administrator calls rebalance to settle protocol fees(performance fee). This calls Strategy.harvest to update the total deployed asset amount including interest and returns the amount of newly generated interest. Then n% of the interest is taken as protocol fees.
function _harvestAndMintFees() internal {
uint256 currentPosition = _totalAssets();
if (currentPosition == 0) {
return;
}
@> int256 balanceChange = _harvest();
if (balanceChange > 0) {
address feeReceiver = getFeeReceiver();
uint256 performanceFee = getPerformanceFee();
if (feeReceiver != address(this) && feeReceiver != address(0) && performanceFee > 0) {
uint256 feeInEth = uint256(balanceChange) * performanceFee;
uint256 sharesToMint = feeInEth.mulDivUp(totalSupply(), currentPosition * PERCENTAGE_PRECISION);
@> _mint(feeReceiver, sharesToMint);
}
}
}
function _harvest() internal virtual override returns (int256 balanceChange) {
@> return _strategy.harvest(); // Calls the harvest function of the strategy
}
However, StrategySupplyBase.harvest can be called by anyone. By front-running the rebalance request or regularly calling this function, users can avoid paying protocol fees on interest. This allows users to receive more interest than they should.
@> function harvest() external returns (int256 balanceChange) {
// Get Balance
uint256 newBalance = getBalance();
@> balanceChange = int256(newBalance) - int256(_deployedAmount);
if (balanceChange > 0) {
emit StrategyProfit(uint256(balanceChange));
} else if (balanceChange < 0) {
emit StrategyLoss(uint256(-balanceChange));
}
if (balanceChange != 0) {
emit StrategyAmountUpdate(newBalance);
}
@> _deployedAmount = newBalance;
}
This is PoC. It demonstrates that anyone can call StrategySupplyBase.harvest. This can be run by adding it to the StrategySupplyAAVEv3.ts file.
it('PoC - anyone can call harvest', async () => {
const { owner, strategySupply, stETH, aave3Pool, otherAccount } = await loadFixture(
deployStrategySupplyFixture,
);
const deployAmount = ethers.parseEther('10');
await stETH.approve(await strategySupply.getAddress(), deployAmount);
await strategySupply.deploy(deployAmount);
//artificial profit
await aave3Pool.mintAtokensArbitrarily(await strategySupply.getAddress(), deployAmount);
await expect(strategySupply.connect(otherAccount).harvest())
.to.emit(strategySupply, 'StrategyProfit')
.to.emit(strategySupply, 'StrategyAmountUpdate');
});
Recommended Mitigation Steps
Add the onlyOwner modifier to StrategySupplyBase.harvest to restrict access.
chefkenji (BakerFi) confirmed
Status: Mitigation confirmed. Full details in reports from 0xlemon and shaflow2.
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 harvest function lacked an access control modifier, allowing any external caller to update the deployed amount and reset the balance change before fees could be calculated.
Impact
Users could avoid paying performance fees on interest, receiving more interest than they should.
What the attacker needed
A deployed strategy with interest; ability to call harvest before rebalance
The fix
The harvest function should be restricted to the owner by adding an onlyOwner modifier.
How it was found
- Deploy the strategy and deposit funds.
- Simulate profit by minting extra aTokens to the strategy.
- Call harvest from an account other than the owner.
- Observe that the harvest succeeds and emits profit events.
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 smart contract has a function that updates the recorded balance and calculates how much interest has been earned. Normally, a fee is taken from that interest when an admin triggers a rebalance. Because anyone could call the harvest function directly, a user could update the balance first so that when the admin later checked, there was no new interest to charge a fee on. This meant the user kept more of the interest than they were supposed to.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.