Griefer can transfer baseToken
directly into pool and lead to loss of user funds
#164
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
unsatisfactory
does not satisfy C4 submission criteria; not eligible for awards
Lines of code
https://github.com/code-423n4/2022-12-caviar/blob/0212f9dc3b6a418803dbfacda0e340e059b8aae2/src/Pair.sol#L418-L429
Vulnerability details
Impact
Users might lose funds due to the miscalculation of
lpToken
they should get.Proof of Concept
Attacker can transfer ERC20 token directly into contract or use
selfdestruct
to force sending ETH into the contract.https://github.com/code-423n4/2022-12-caviar/blob/0212f9dc3b6a418803dbfacda0e340e059b8aae2/src/Pair.sol#L479-L483
This would make
baseTokenShare
return a lower value than what it should.https://github.com/code-423n4/2022-12-caviar/blob/0212f9dc3b6a418803dbfacda0e340e059b8aae2/src/Pair.sol#L418-L429
Example:
For simplicity assume
lpTokenSupply == 1
.baseToken
directly into the pair contract.add()
with 100baseToken
andfractionalToken
Because of attacker's direct transfer
baseTokenShare
is now 0 instead of 100lpToken
user receives 0, making them unable to burnlpToken
for base tokens or fractional tokens.Recommended Mitigation Steps
Use internal accounting to not be affected by tokens directly deposited into the contract.
The text was updated successfully, but these errors were encountered: