Closed code423n4 closed 1 year ago
berndartmueller marked the issue as duplicate of #245
Downgrading to QA (Low). Please see https://github.com/code-423n4/2022-12-caviar-findings/issues/245#issuecomment-1382854995 for my reasoning.
berndartmueller marked the issue as not a duplicate
Lines of code
https://github.com/code-423n4/2022-12-caviar/blob/main/src/Pair.sol#L182-L207
Vulnerability details
Impact
In
Pair.sol
,sell()
could be used to fool users into selling fractional tokens to receive base tokens whose contract has already been self-destructed. As a result, the swappers would end up getting zero base tokens out because the base token contract had been destroyed by its malicious owner.Proof of Concept
As denoted by File: SafeTransferLib.sol#L9:
As such, the following token transfer, when externally called to Solmate's
SafeTransferLib.sol
, is performing low-level calls without confirming contract’s existence that could return success even though no function call was executed:File: Pair.sol#L182-L207
Here is an example of the hypothetical situation:
selfdestruct()
.create()
inCaviar.sol
creating a pool using his malicious token contract asbaseToken
.selfdestruct()
on his token contract.sell()
will lead to users losing their sent in tokens since no tokens out will be realized.Tools Used
Manual inspection
Recommended Mitigation Steps
Consider implementing contract existence check on
ERC20(baseToken).safeTransfer
. This will ensuresell()
to revert when a token contract no longer exists, preventing traders from losing their funds.Note: When a contract calls SELFDESTRUCT , it does not get deleted. Instead, its code gets zeroed out and its nonce increased by 2**40 . As such, the protocol's zero address check will not stem this from happening.