DeFiFoundrySolidity
16,653 OP
View results
Submission Details
Severity: medium
Invalid

Complete the _harvestAndReport function

Summary

Complete the _harvestAndReport function

Vulnerability Details

Complete this _harvestAndReport function to implement some key functions, such as reward collection, underlying asset exchange, and accurate asset calculation. The following is the code supplement and optimization of the missing parts to ensure that the strategy can correctly calculate the total assets when calling this function.

https://github.com/Cyfrin/2024-12-alchemix/blob/82798f4891e41959eef866bd1d4cb44fc1e26439/src/StrategyMainnet.sol#L172-L192

https://github.com/Cyfrin/2024-12-alchemix/blob/82798f4891e41959eef866bd1d4cb44fc1e26439/src/StrategyArb.sol#L148-L171

https://github.com/Cyfrin/2024-12-alchemix/blob/82798f4891e41959eef866bd1d4cb44fc1e26439/src/StrategyOp.sol#L161-L174

Impact

Complete the _harvestAndReport function

Tools Used

Manual review

Recommendations

function _harvestAndReport()
internal
override
returns (uint256 _totalAssets)
{
// 1. Receive rewards
uint256 claimable = transmuter.getClaimableBalance(address(this));
if (claimable > 0) {
// Receive rewards
transmuter.claim(claimable, address(this));
}
// 2. Exchange the underlying asset to the target asset (if there is a balance of the underlying asset)
if (underlying.balanceOf(address(this)) > 0) {
_swapUnderlyingToAsset(underlying.balanceOf(address(this)));
}
// 3. Get unexchanged assets (aLETH)
uint256 unexchanged = transmuter.getUnexchangedBalance(address(this));
// 4. Get the current balance of the underlying asset (such as WETH)
uint256 underlyingBalance = underlying.balanceOf(address(this));
// 5. Get the current target asset balance (such as aLETH or other target assets)
uint256 assetBalance = asset.balanceOf(address(this));
// 6. Calculate the total assets: unexchanged portion + currently held target assets + currently held underlying assets
_totalAssets = unexchanged + assetBalance + underlyingBalance;
// Return the calculated total assets
return _totalAssets;
}
Updates

Appeal created

inallhonesty Lead Judge 5 months ago
Submission Judgement Published
Invalidated
Reason: Design choice

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.