The exec function in the FlapperUniV2 contract is susceptible to reentrancy attacks. This vulnerability could allow a malicious contract to re-enter the exec function before it completes, potentially draining funds from the contract.
Vulnerability Detail
The exec function performs multiple external calls:
Token Transfer: It transfers DAI to the Uniswap pair contract GemLike(dai).transfer(address(pair), _sell);.
Uniswap Swap: It calls the swap function on the Uniswap pair pair.swap(_amt0Out, _amt1Out, address(this), new bytes(0));.
Token Transfer (Liquidity): It transfers DAI and GEM to the pair for liquidity minting GemLike(dai).transfer(address(pair), lot - _sell); and GemLike(gem).transfer(address(pair), _buy);.
Liquidity Minting: It calls the mint function on the pair pair.mint(receiver);.
If any of these external contract calls are to a malicious contract, that contract could exploit this vulnerability by calling back into the exec function before the original call completes. This could allow the attacker to repeat these actions multiple times within a single transaction, potentially draining funds from the contract.
Impact
A successful reentrancy attack could lead to significant financial losses for the contract owner and users. The attacker could drain the contract's DAI and GEM balances, disrupting its intended functionality.
All of the external calls are to constant/immutable addresses or to ones set by governance, so assumed non malicious. Also exec is authed, so only authorized callers can enter it.
kevinkien
High
Reentrancy Vulnerability in
exec
FunctionSummary
The
exec
function in theFlapperUniV2
contract is susceptible to reentrancy attacks. This vulnerability could allow a malicious contract to re-enter theexec
function before it completes, potentially draining funds from the contract.Vulnerability Detail
The
exec
function performs multiple external calls:GemLike(dai).transfer(address(pair), _sell);
.pair.swap(_amt0Out, _amt1Out, address(this), new bytes(0));
.GemLike(dai).transfer(address(pair), lot - _sell);
andGemLike(gem).transfer(address(pair), _buy);
.pair.mint(receiver);
.If any of these external contract calls are to a malicious contract, that contract could exploit this vulnerability by calling back into the exec function before the original call completes. This could allow the attacker to repeat these actions multiple times within a single transaction, potentially draining funds from the contract.
Impact
A successful reentrancy attack could lead to significant financial losses for the contract owner and users. The attacker could drain the contract's DAI and GEM balances, disrupting its intended functionality.
Code Snippet
https://github.com/sherlock-audit/2024-06-makerdao-endgame/blob/main/dss-flappers/src/FlapperUniV2.sol#L141-L164
Tool used
Manual Review
Recommendation
Implement a reentrancy guard on the exec function