Flaw in Pair Contract Allows Users to Get Free Fractional Tokens #276
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
duplicate-243
satisfactory
satisfies C4 submission criteria; eligible for awards
Lines of code
https://github.com/code-423n4/2022-12-caviar/blob/main/src/Pair.sol#L398-L400
https://github.com/code-423n4/2022-12-caviar/blob/main/src/Pair.sol#L147-L176
Vulnerability details
Impact
The
buy()
function in thePair.sol
contract is designed to allow users to purchase fractional tokens from the pair. A buy quote is created through thebuyQuote()
function which returns the amount of fractional tokens to be minted by returning(outputAmount * 1000 * baseTokenReserves()) / ((fractionalTokenReserves() - outputAmount) * 997)
however, there is a critical flaw when there are no base tokens in the reserves, this will allow the malicious actor to get free Fractional tokens as anything multiplied by zero base token reserves is always going to equal zero input tokens. This was rated a Medium in severity because whilst NFT tokens can be stolen, certain edge cases must be met for the base token reserves to reach zero.Proof of Concept
The following proof of concept solidity test outlines the impact mentioned above:
Recommended Mitigation Steps
It is recommended that the user who creates a caviar pair is required to initially add liquidity to the pool so they are obligated to provide input tokens in exchange for fraction tokens. In addition to this, the sanity check below in the
buy()
function is recommended to ensure that base liquidity tokens have already been provided:The text was updated successfully, but these errors were encountered: