[UNCHAIN-H#6] Depositors can be priced out and NFTs and baseToken can be stolen #310
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
duplicate-442
edited-by-warden
satisfactory
satisfies C4 submission criteria; eligible for awards
Lines of code
https://github.com/code-423n4/2022-12-caviar/blob/main/src/Pair.sol#L58-L99
Vulnerability details
Finder
Yawn, Tomo, keit
Summary
The
Add
function allows the user to add any amount to the Pair contract.Both theadd
andremove
functions use the balance of the contract’s baseToken in their calculations for shares.This allows attacker to tie the share to very high amounts, and steal fractionalToken and baseToken by pricing out smaller depositors.
Vulnerability Detail
nftAdd
function with arguments so thatlpTokenAmount
is close to the minimum amount 1.1000
USDC directly to the Pair contract. The baseToken’sbalanceOf()
is now1000e6 + 1
baseTokenShare = (baseTokenAmount * lpTokenSupply) / baseTokenReserves() = (1000e6 * 1) / (1000e6 + 1) = 0
buy
function and provides liquidity with theadd
function, the share will be zero because the smaller share is calculated as the amount of the lpToken.return Math.min(baseTokenShare, fractionalTokenShare);
remove
aslpTokenAmount = 1
to receive the entire Pair balance both of baseToken and fractional tokens. So attacker can steal all of the NFTs and baseToken balance.Code Snippet
Tool used
Manual Review
Recommendation
It is recommended to define a minimum deposit amount as UniswapV2 does, and mint the initial shares like
1000
to the zero address.[yawn H-02] The value of the
lpToken
could be manipulated by sendingbaseToken
directly.Summary
Since the actual
baseToken
andfractionalToken
balance in thePair
contract is used to calculate thelpToken
value andfractionalToken
price, they can be manipulated by transferring directly to thePair
contract.Under some conditions, users’ share may be estimated lower than expected and loses value of assets.Vulnerability Detail
Pair
byadd
function.baseToken
directly to thePair
contract.fractionalToken
is calculated byxy*k
, so it sets higher.baseToken
, the share will be smaller than expected.fractionalToken
with theadd
function, the share will be smaller than expected when the amount ofbaseToken
to provide has a small impact on the liquidity of thePair
.return Math.min(baseTokenShare, fractionalTokenShare);
remove
to receive morebaseTokens
andfractionalTokens
than expected.Code Snippet
Tool used
Manual Review
Recommendation
It is recommended that the
baseToken
andfractionalToken
balances in thePair
contract be saved as storage variables likereserve
each time they are updated, as is done in UniswapV2.The text was updated successfully, but these errors were encountered: