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
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
SPYBOY
medium
Possible DOS in
getAllProtections()
andaccruePremiumAndExpireProtections()
functions because of unbounded gas consumptionSummary
In the ProtectionPool.sol contract
getAllProtections()
andaccruePremiumAndExpireProtections()
functions are declared .getAllProtections()
returns the Protections array andaccruePremiumAndExpireProtections()
iterates through a number of lendingPoolIndexs. We can only get this list of Protections from thegetAllProtections()
view function. for loops insideaccruePremiumAndExpireProtections()
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 likelyaccruePremiumAndExpireProtections()
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 consumingCode 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 functionaccruePremiumAndExpireProtections()
should not dp this amount of iterate in same functionDuplicate of #63