Closed github-actions[bot] closed 1 year ago
@clems4ev3r this is by design to reduce the gas cost. Because accruing premium is gas intensive, we can't call that function on each transaction referring to totalSTokenUnderlying
@vnadoda This could probably be solved with a continuous accrual, but for now agreed it could be gas intensive to accrue all protections on each user operation
Closing based on the above comments
141345
medium
totalSTokenUnderlying
not timely updatedSummary
The accruing of premium is after the expiry of protection, and then
totalSTokenUnderlying
will be updated. And the updates are triggered manually by hand or by bot, not built into the smart contracts, so it is possible that there is some time gap whentotalSTokenUnderlying
is not timely updated. The inaccurate value oftotalSTokenUnderlying
could lead to problem when users deposit and withdraw.Vulnerability Detail
When there is un-accrued premium and
totalSTokenUnderlying
are delayed,convertToUnderlying()/convertToSToken()
functions could return inaccurate results. Hence when users deposit and withdraw, the calculated amount will be inaccurate.Currently, accruing of premium only happens after the protection is expired.
And the accrued amount will be added to
totalSTokenUnderlying
.totalSTokenUnderlying
is used for exchange rate when deposit and withdraw.Imagine, the un-accrued premium is $100, and
totalSTokenUnderlying
is $10,000, when deposit, users could get 1% more sToken, and 1% less when withdraw.Impact
When users deposit and withdraw, the amounts would be inaccurate, some user will get undeserved fund and some will get less then they should.
Code Snippet
https://github.com/sherlock-audit/2023-02-carapace/blob/main/contracts/core//pool/ProtectionPool.sol#L987-L1002
https://github.com/sherlock-audit/2023-02-carapace/blob/main/contracts/core//pool/ProtectionPool.sol#L230-L234
Tool used
Manual Review
Recommendation
When referring to
totalSTokenUnderlying
, first accruing the premium to make sure the value is up to date.Or accrue premium as soon as it is transferred at the beginning.