The `Singularity::removeAsset share can become zero due to rounding down, and any user can be extracted some amount of asset` issue has not been fixed #19
Now, navigate to the issue, coupling this with the @audit tag in snippets above, we can see that an attacker can use rounding down of the share of asset to zero, to remove small amounts of asset from any user, since the allowance needed in that case would be zero, though there is the _allowedLend(from, share); check, in this case it would pass considering the share is 0. Also the shares are calculated in a rounding down format, i.e share = (fraction * allShare) / _totalAsset.base; so it can aswell be 0 which makes the share 0, now the comment as the mitigation on the issue was that this was fixed in the supposed commit, however in the current commit there still seems to be no mitigation to this issue.
Attack Scenario
Any user can steal some amount of asset from any other user, by ensuring their calculated share rounds down to zero. see here for more info.
Recommendation
Consider applying the fix as suggested here, which would be to apply a requirement that share != 0 while removing the assets.
Attachments
Github username: @bauchibred Twitter username: bauchibred Submission hash (on-chain): 0xa23b1d8029983b7af9fb6728f75ee289019eb42c96930767aaa5ae826bad2c95 Severity: medium
Description: Description
Take a look at https://github.com/hats-finance/Tapioca--Lending-Engine--0x5bee198f5b060eecd86b299fdbea6b0c07c728dd/blob/8920782db6044643fd0c682f58ef37f7e59f99b1/contracts/markets/singularity/Singularity.sol#L257-L266
And https://github.com/hats-finance/Tapioca--Lending-Engine--0x5bee198f5b060eecd86b299fdbea6b0c07c728dd/blob/8920782db6044643fd0c682f58ef37f7e59f99b1/contracts/markets/singularity/Singularity.sol#L426-L444
Now, navigate to the issue, coupling this with the @audit tag in snippets above, we can see that an attacker can use rounding down of the share of asset to zero, to remove small amounts of asset from any user, since the allowance needed in that case would be zero, though there is the
_allowedLend(from, share);
check, in this case it would pass considering the share is0
. Also the shares are calculated in a rounding down format, i.eshare = (fraction * allShare) / _totalAsset.base;
so it can aswell be0
which makes the share0
, now the comment as the mitigation on the issue was that this was fixed in the supposed commit, however in the current commit there still seems to be no mitigation to this issue. Attack Scenario Any user can steal some amount of asset from any other user, by ensuring their calculatedshare
rounds down to zero. see here for more info. Recommendation Consider applying the fix as suggested here, which would be to apply a requirement thatshare != 0
while removing the assets. AttachmentsN/A
N/A