57362 sc medium attacker can dos user withdraw in staking contract
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;
}
}
} else {
unchecked {
++i;
}
}
}
if (remaining != 0) revert MinStakePeriodNotMet();
}Impact Details
References
Proof of Concept
1
2
3
4
5
6
7
Suggested Mitigations (not exhaustive)
Previous57268 sc insight erc1155base missing collection uri fallback causes significant gas waste on every token mintNext57895 sc medium lack of msg sender validation in collection creation signature enables front running attack leading to creator impersonation
Was this helpful?