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

Potential Exploitation via Reentrancy Attack in External Calls within `claimAndSwap` Function

Title

Potential Exploitation via Reentrancy Attack in External Calls within claimAndSwap Function

Summary

The claimAndSwap function, present in all three strategy contracts, is critically vulnerable to reentrancy attacks. Since it interacts with external components like the transmuter and router, malicious actors could exploit this vulnerability to reenter the contract and drain protocol funds, leading to significant exploitation risks.

Vulnerability Details

Here's the implementation of claimAndSwap function in StrategyOp contract:

function claimAndSwap(uint256 _amountClaim, uint256 _minOut, IVeloRouter.route[] calldata _path ) external onlyKeepers {
>> transmuter.claim(_amountClaim, address(this));
uint256 balBefore = asset.balanceOf(address(this));
>> _swapUnderlyingToAsset(_amountClaim, _minOut, _path);
uint256 balAfter = asset.balanceOf(address(this));
require((balAfter - balBefore) >= _minOut, "Slippage too high");
>> transmuter.deposit(asset.balanceOf(address(this)), address(this));
}

And here's how _swapUnderlyingToAsset function interacts with router:

function _swapUnderlyingToAsset(uint256 _amount, uint256 minOut, IVeloRouter.route[] calldata _path) internal {
// TODO : we swap WETH to ALETH -> need to check that price is better than 1:1
// uint256 oraclePrice = 1e18 * 101 / 100;
require(minOut > _amount, "minOut too low");
uint256 underlyingBalance = underlying.balanceOf(address(this));
require(underlyingBalance >= _amount, "not enough underlying balance");
>> IVeloRouter(router).swapExactTokensForTokens(_amount, minOut, _path, address(this), block.timestamp);
}

The claimAndSwap function involves multiple external calls, making it susceptible to reentrancy attacks. This vulnerability allows attackers to repeatedly call the function, potentially draining funds, corrupting balances, or leaving critical contract variables in an inconsistent state. It can further deminify financial losses and disrupt user trust in the protocol.

Additionally, this reentrancy vulnerability exists in couple other functions like _deployFunds and _freeFunds.

Impact

The vulnerability in the claimAndSwap function could lead to fund theft, state inconsistencies, and significant financial and reputational damage to the protocol if exploited.

Tools Used

Manual Review

Recommendations

Add nonReentrant modifier to these external functions to prevent any possible reentrancy attacks.

Updates

Appeal created

inallhonesty Lead Judge 8 months ago
Submission Judgement Published
Invalidated
Reason: Lack of quality

Support

FAQs

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