Incorrect loop indexing in LibAddressStakingReleases.compact() leads to unprocessed pending releases
The compact() function in LibAddressStakingReleases compared an absolute index (startIdx) against a relative count of pending releases (length), so once more releases had been processed than remained pending the loop never ran. This left claimable validator collateral locked and broke the claim flow.
Submitted by 0xAsen, also found by BlueSheep, danzero, newspacexyz, NexusAudits, and sin1st3r__
The root cause of this issue is the use of an absolute index (self.startIdx) in the loop condition of the compact() function in LibAddressStakingReleases, while self.length represents the number of pending releases.
If there are more processed releases than pending releases, the following will be true: self.startIdx > self.length.
This will cause the compact() function to never enter the processing loop:
function compact(AddressStakingReleases storage self) internal returns (uint256, uint16) {
uint16 length = self.length;
if (self.length == 0) {
revert NoCollateralToWithdraw();
}
uint16 i = self.startIdx; // <-- 'i' is the absolute index, e.g., 100 after previous processing
uint16 newLength = length;
uint256 amount;
while (i < length) { // <-- ! // Incorrect: compares absolute index (e.g., 100) with pending count (15)
StakingRelease memory release = self.releases[i];
// releases are ordered ascending by releaseAt, no need to check
// further as they will still be locked.
if (release.releaseAt > block.number) {
break;
}
amount += release.amount;
delete self.releases[i];
unchecked {
++i;
--newLength;
}
}
self.startIdx = i; // <-- Updates startIdx to the final value of 'i'
self.length = newLength; // Updates the length to the number of pending releases
return (amount, newLength);
}
This prevents the contract from processing and releasing collateral that should be claimable, locking validator funds and breaking the core logic of the compact function.
Since startIdx only increases over time (as it is never reset), this issue becomes more likely as the absolute index grows larger and at some point it becomes inevitable.
Note: compact is called in the claim function that is critical for the validator collateral claiming flow.
Proof of Concept
Let’s go over the following scenario:
- 115 releases to be processed, 100 of them available to claim at the current release time.
compactfunction is called,i = startIdx = 0,newLength = length = 115.compactprocesses the 100 available releases, the loop breaks and this is executed:
self.startIdx = i; // = 100 (it was incremented 100 times)
self.length = newLength; // = 15 (it was decremented 100 times - number of pending releases)
Now, on the next iteration, let’s say for simplicity the number of releases stays the same, and time has passed so now they are available for claiming. We have this:
startIdx = 100,self.length = 15.- The loop starts with
i = 100and checkswhile (i < 15), which immediately fails.
Outcome:
- The loop body does not execute.
- Pending releases (indices 100 to 114 in absolute terms) are never processed.
This discrepancy between the absolute index and the relative count prevents claimable collateral from being released. This is extremely likely to happen since the absolute index of processed releases only grows; it never decreases. Therefore, it’ll reach a point of its value being 100, 1000, 10_000, etc.
At some point, the value will be so big that the pending releases will inevitably be of much lower value than the processed releases, leading to locked validator collateral that should be available to claim.
Recommended mitigation steps
Adjust the loop condition. For example, change the condition to:
while (i < self.startIdx + self.length)
Recall confirmed
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The loop condition compared the absolute array index (startIdx) with the relative number of pending releases (length) instead of the absolute end position.
Impact
Claimable validator collateral could become permanently locked, and the issue becomes inevitable as startIdx only grows.
What the attacker needed
Processed releases exceed pending ones
The fix
The loop condition should compare against the absolute end position, for example startIdx plus length, as the report recommends.
How it was found
- Have 115 releases with 100 claimable at the current block.
- Call compact() with startIdx 0 and length 115, which processes the 100 claimable releases.
- startIdx becomes 100 and length becomes 15.
- After time passes, call compact() again: the loop starts at i = 100 and the condition i < 15 fails immediately.
- The pending releases at absolute indices 100 to 114 are never processed.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract keeps a list of staking releases and tracks two numbers: where the next unprocessed entry sits in the list, and how many entries are still pending. The code compared the position in the list with the count of pending entries, which are different kinds of number, so after enough entries were processed the check was always false and nothing more got released. As a result, money that should have been claimable stayed stuck.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.