57245 sc medium needless iterations in for loops should be removed for better optimization and code maintenance
Description
Brief/Intro
Vulnerability Details
function _consumeUnlockedSharesOrRevert(address staker, uint256 need) internal {
Stake[] storage userStakes = stakes[staker];
uint256 _min = minStakePeriod;
uint256 nowTs = block.timestamp;
uint256 remaining = need;
for (uint256 i; i < userStakes.length && remaining > 0;) {
Stake memory s = userStakes[i];
if (nowTs >= s.timestamp + _min) {
uint256 take = s.shares <= remaining ? s.shares : remaining;
if (take == s.shares) {
// full consume → swap and pop
remaining -= take;
userStakes[i] = userStakes[userStakes.length - 1];
userStakes.pop();
// don't ++i: a new element is now at index i
} else {
// partial consume
userStakes[i].shares = s.shares - take;
remaining = 0;
unchecked {
++i; // @audit loop should not continue if there are no shares remaining.
}
}
} else {
unchecked {
++i;
}
}
}
if (remaining != 0) revert MinStakePeriodNotMet();
}Impact Details
Proof of Concept
Suggested Fix
Previous57677 sc medium signature replay in venuedeposit enables affiliate referral code hijacking leading to unauthorized commission theftNext57875 sc medium signature bypass lets creators alter key accesstoken parameters before deployment
Was this helpful?