Open code423n4 opened 2 years ago
sponsor confirmed
ahh the inflation attack..... Wardens love this one.
The contract locks a minimum liquidity amount which blocks the feasibility attack for the most part. Please see enableLiquidityReserve
for the code where the locking occurs.
Some good worthwhile ideas from the warden but after reviewing the enableLiquidityReserve
going to downgrade this to medium. After reading the code and the described attack, its not very clear how the attacker would benefit and bring the contract into this state.
By sending tokens directly to the contract (expensive) and increasing total totalLockedValue, this will decrease the amount the amountToMint for the user but unclear that this cost is worth it or how an attacker could actually benefit (from what I can see).
Think its still worth exploring this vector in more depth as its a creative attack. Warrants medium and further investigation.
Lines of code
https://github.com/code-423n4/2022-06-yieldy/blob/524f3b83522125fb7d4677fa7a7e5ba5a2c0fe67/src/contracts/LiquidityReserve.sol#L100-L127
Vulnerability details
Impact
Function
addLiquidity()
suppose to do add Liquidity for thestaking Token
and receivelrToken
in exchange. to calculate amount ofIrToken
codes uses this calculation:amountToMint = (_amount * lrFoxSupply) / totalLockedValue
but it's possible for attacker to manipulatetotalLockedValue
(by sending tokens directly toLiquidityReserve
address) and maketotalLockedValue/lrFoxSupply
very high in early stage of contract deployment so because of rounding error in calculation ofamountToMint
the users would receive very lowerIrToken
and users funds would be lost and attacker can steal them. Attacker can perform this attack by sending tokens before evenLiquidityReserve
deployed because the contract address would be predictable and attacker can perform front-run or sandwich attack too.also it's possible to perform this attack for
STAKING_TOKEN
with low precision and low price even ifLiquidityReserve
had some balances.Proof of Concept
This is
addLiquidity()
code inLiquidityReserve
:As you can see code uses this calculation:
amountToMint = (_amount * lrFoxSupply) / totalLockedValue;
to find the amount ofIrToken
that is going to mint for user. but attacker can sendstakingToken
orrewardToken
directly toLiquidityReserve
address when the there is no liqudity in the contract and maketotalLockedValue
very high. then attacker calladdLiquidity()
and mint someIrToken
for himself and from then anyone tries to calladdLiquidity()
because of rounding error is going to lose some funds (receives lessIrToken
than he is supposed to)Tools Used
VIM
Recommended Mitigation Steps
add more precision when calculating
IrToken
so this attack wouldn't be feasible to perform.