sherlock-audit / 2023-02-carapace-judging

2 stars 0 forks source link

SPYBOY - Possible DOS in `getAllProtections()` and `accruePremiumAndExpireProtections()` functions because of unbounded gas consumption #269

Closed github-actions[bot] closed 1 year ago

github-actions[bot] commented 1 year ago

SPYBOY

medium

Possible DOS in getAllProtections() and accruePremiumAndExpireProtections() functions because of unbounded gas consumption

Summary

In the ProtectionPool.sol contract getAllProtections() and accruePremiumAndExpireProtections() functions are declared . getAllProtections() returns the Protections array and accruePremiumAndExpireProtections() iterates through a number of lendingPoolIndexs. We can only get this list of Protections from the getAllProtections() view function. for loops inside accruePremiumAndExpireProtections() will run for each lendingPoolIndex. Every time this calculation is gas-consuming.

Vulnerability Detail

Impact

The getAllProtections() function fetched all elements of the list from storage, which is really gas-consuming and even can break the block gas limit in case the list is too large. Even though users don’t need to pay gas for the view function, this function is still failed if its gas cost larger than the block gas limit. most likely accruePremiumAndExpireProtections() will always fail because its first for loop iterates through lendingPoolIndex and inside this for loop there is another for loop which will be iterateing through protections of that lendingPool. which is more gas consuming

Code Snippet

https://github.com/sherlock-audit/2023-02-carapace/blob/main/contracts/core/pool/ProtectionPool.sol#L279-L354 https://github.com/sherlock-audit/2023-02-carapace/blob/main/contracts/core/pool/ProtectionPool.sol#L562-L581

Tool used

Manual Review

Recommendation

The function getAllProtections() should return an array in range or should iterate in range The function accruePremiumAndExpireProtections() should not dp this amount of iterate in same function

Duplicate of #63