Anyone can break the constant product by minting into Pair directly
Summary
There is a following comment for mint, burn and swap function in the Pair contract:
"this low-level function should be called by addLiquidity functions in Router.sol, which performs important safety checks standard uniswap v2 implementation."
The addLiquidity function in Router.sol perform safety check to maintain the product of the amounts of pair reserves.
But anyone can mint into pair directly without safety check.
Thus, attackers can break the product of the amounts of pair reserves.
Vulnerability Detail
The Router.addLiquidity function checks the input amount of assets.
After this checking, the addLiquidity function calls IPair(pair).mint.
But attacker can break the product of the amounts of pair reserves by transfering tokens to pair and calling IPair(pair).mint directly.
Invalid, no product is broken, the mint() function will force the reserves to be 1:1 with balance of contract, and the attacker will lose all donated funds
KupiaSec
High
Anyone can break the constant product by minting into
Pair
directlySummary
There is a following comment for
mint
,burn
andswap
function in thePair
contract: "this low-level function should be called by addLiquidity functions in Router.sol, which performs important safety checks standard uniswap v2 implementation." TheaddLiquidity
function in Router.sol perform safety check to maintain the product of the amounts of pair reserves. But anyone can mint into pair directly without safety check. Thus, attackers can break the product of the amounts of pair reserves.Vulnerability Detail
The
Router.addLiquidity
function checks the input amount of assets.https://github.com/sherlock-audit/2024-06-velocimeter/blob/63818925987a5115a80eff4bd12578146a844cfd/v4-contracts/contracts/Router.sol#L186-L195
It is for maintaining the product of the amounts of pair reserves.
https://github.com/sherlock-audit/2024-06-velocimeter/blob/63818925987a5115a80eff4bd12578146a844cfd/v4-contracts/contracts/Router.sol#L186-L195
After this checking, the
addLiquidity
function callsIPair(pair).mint
. But attacker can break the product of the amounts of pair reserves by transfering tokens to pair and callingIPair(pair).mint
directly.https://github.com/sherlock-audit/2024-06-velocimeter/blob/63818925987a5115a80eff4bd12578146a844cfd/v4-contracts/contracts/Pair.sol#L250
Impact
Attacker can break the constant product of pair’s reserve balances.
Code Snippet
https://github.com/sherlock-audit/2024-06-velocimeter/blob/63818925987a5115a80eff4bd12578146a844cfd/v4-contracts/contracts/Router.sol#L186-L195
https://github.com/sherlock-audit/2024-06-velocimeter/blob/63818925987a5115a80eff4bd12578146a844cfd/v4-contracts/contracts/Router.sol#L186-L195
https://github.com/sherlock-audit/2024-06-velocimeter/blob/63818925987a5115a80eff4bd12578146a844cfd/v4-contracts/contracts/Pair.sol#L250
Tool used
Manual Review
Recommendation
It is recommended to check that the caller of the
mint
,swap
andburn
functions isRouter
contract.