This repository has been archived by the owner on May 26, 2023. It is now read-only.
SPYBOY - Possible DOS in getPositionIdsByOwner()
function because of unbounded gas consumption
#95
Labels
Duplicate
A valid issue that is a duplicate of an issue with `Has Duplicates` label
Non-Reward
This issue will not receive a payout
SPYBOY
medium
Possible DOS in
getPositionIdsByOwner()
function because of unbounded gas consumptionSummary
In the
BlueBerryBank.sol
contractgetPositionIdsByOwner
function is declared which returns the position ids of the position owner. We can only get this list of ids from thegetPositionIdsByOwner
view function. There is no option to remove this ids from this array. for loop insidegetPositionIdsByOwner()
will be running for each position until it findspositions[i].owner == owner
. Every time this calculation is gas-consuming.Vulnerability Detail
Impact
This 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.
Related sherlock report : sherlock-audit/2022-10-union-finance-judging#69
Code Snippet
https://github.com/sherlock-audit/2023-02-blueberry/blob/main/contracts/BlueBerryBank.sol#L315-L333
Tool used
Manual Review
Recommendation
The function
getPositionIdsByOwner
should return an array in range or should iterate in rangeDuplicate of #77
The text was updated successfully, but these errors were encountered: