The Standard

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

Simplify Consolidate Pending Stakes & gas optimization

Summary

The consolidatePendingStakes is complex as it tries to manage delete pending staking by decreasing the index value and managing negative numbers.

Vulnerability Details

Need more maintenance of this code and need to manage integer conversion (potential overflow).

Impact

Difficulty to understand and future maintenance.

Tools Used

Manual Review.

Recommendations

Keep it simple, increase the index only in the case where we do not delete the pending stake.

function consolidatePendingStakes() private {
uint256 deadline = block.timestamp - 1 days;
uint i = 0;
while (i < pendingStakes.length) {
PendingStake memory _stake = pendingStakes[i];
if (_stake.createdAt < deadline) {
positions[_stake.holder].holder = _stake.holder;
positions[_stake.holder].TST += _stake.TST;
positions[_stake.holder].EUROs += _stake.EUROs;
deletePendingStake(i);
} else {
i++;
}
}
}

Also, pending stake seems to be timestamp related. Which means that timestamp_0th < timestamp_1th. In that case, we can break the loop directly after we have found a pending stake that does not match the deadline. In this case, in the recommendation code, instead of i++ we can directly do a break.

Updates

Lead Judging Commences

hrishibhat Lead Judge almost 2 years 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.