Closed github-actions[bot] closed 1 year ago
This should not happen on deposit (for more than a few wei). The amount of underlying withdrawn can be zero if there was a locking event, which is part of the normal functioning of the protocol
Closing based on the above comment
unforgiven
medium
User fund loss in withdraw() and deposit() of ProtectionPool due to division error
Summary
Functions
withdraw()
anddeposit()
in the ProtectionPool doesn't revert when calculated_sTokenShares
or_underlyingAmountToTransfer
amount is 0 and it can cause users to receive no share or underlying token while they pays underlying token or burns shares. code should revert when calculated amounts are zero.Vulnerability Detail
This is
_deposit()
andwithdraw()
code:As you can see code doesn't revert when calculated amount is zero and user may lose funds slowly because of the division error. contract may burn user shares and transfer no token to users or transfer users underlying token and mint 0 share for them. when code calculates underlying token amount based on share amount it uses
convertToUnderlying()
inwithdraw()
function and because of the division error the calculated amount can be zero but code doesn't check that. when code calculates share amount based on underlying token in_deposit()
, it usesconvertToSToken()
and because of the division error code would mint 0 share for user while transferring user funds.Impact
Users lose funds when they deposit or withdraw small amounts while those small amounts could have sum up and can be used later.
Code Snippet
https://github.com/sherlock-audit/2023-02-carapace/blob/main/contracts/core/pool/ProtectionPool.sol#L253-L259
https://github.com/sherlock-audit/2023-02-carapace/blob/main/contracts/core/pool/ProtectionPool.sol#L1035-L1037
Tool used
Manual Review
Recommendation
revert when calculated amount is zero