Closed c4-bot-4 closed 7 months ago
141345 marked the issue as primary issue
invalid
_sync() func all have nonReentrant modifier
141345 marked the issue as sufficient quality report
141345 marked the issue as insufficient quality report
thereksfour marked the issue as unsatisfactory: Invalid
Lines of code
https://github.com/code-423n4/2024-03-abracadabra-money/blob/1f4693fdbf33e9ad28132643e2d6f7635834c6c6/src/mimswap/MagicLP.sol#L290-L353
Vulnerability details
Impact
MagicLp.flashLoan
function enabes users to utilize the contract quote and base balances, but due to a missing balance check; the contracts balances can be drained, let's see the following scenario:A malicious user calls
flashLoan
function with:baseAmount = _BASE_TOKEN_.balanceOf(address(magicLp)) - 1
quoteAmount = _QUOTE_TOKEN_.balanceOf(address(magicLp)) - 1
Then a call is made to the attacker contract (
assetTo
address), where it will callMagicLp.sync()
function to set the reserves to the current balance of tokens, knowing that the current balances are 1 wei & 1 wei:Now, when the
flashLoan()
function checks for the balances and reserves after the external call, it will pass since the reserves == balances == 1 wei, and the function will proceed.The next blocks that check for extra quote or base tokens reserves to sell them will be passed since balances == reserves.
Proof of Concept
MagicLP.flashLoan function
Tools Used
Manual Review.
Recommended Mitigation Steps
Update
MagicLP.flashLoan()
function to first sync the reserves with the balances, and then cache the tokens reserves before the call, and check they are <= reserves after the call, so that the attacker can't drain the contract funds:Assessed type
Invalid Validation