The Standard

The Standard
DeFiHardhat
20,000 USDC
View results
Submission Details
Severity: low
Invalid

LiquidationPool::consolidatePendingStakes is deleting the elements of the array it is looping over

Summary

The LiquidationPool::consolidatePendingStakes is deleting the elements of the array it is looping over.

Vulnerability Details

The logic structure should be elegant and should avoid any potential conflicts on the data. in the consolidatePendingStakes, the logic is operating over the
storage variable and in this process, it is also deleting elements from the array.

The code structuring and processing is not gas efficient and ideally, as a general principle, it is not a good idea to delete elements from the data collection that is being operated upon. Instead, qualify the list of elements to be deleted can be kept in a memory variable. Once the processing is completed on the main data collection, using the memory variable, the qualified elements can be deleted.

Also, the logic is not gas efficient.

Impact

Gas inefficient and incorrect approach

Tools Used

Manual review

Recommendations

store the delectable elements in a separate set and delete them at the end.

struct PendingStake { address holder; uint256 createdAt; uint256 TST; uint256 EUROs;, bool isDelete; }
function consolidatePendingStakes() private {
uint256 toDelete
uint256 deadline = block.timestamp - 1 days;
for (int256 i = 0; uint256(i) < pendingStakes.length; i++) {
PendingStake memory _stake = pendingStakes[uint256(i)];
if (_stake.createdAt < deadline && ! _stake.isDelete) {
positions[_stake.holder].holder = _stake.holder;
positions[_stake.holder].TST += _stake.TST;
positions[_stake.holder].EUROs += _stake.EUROs;
_stake.isDelete = true;
}
}
==>@audit, loop through the pendingStakes and delete those marked for deletion.
}
Updates

Lead Judging Commences

hrishibhat Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

informational/invalid

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.