The Standard

The Standard
DeFiHardhat
20,000 USDC
View results
Submission Details
Severity: high
Valid

Unbounded loop in `LiquidationPool::deletePendingStake` and `LiquidationPool::consolidatePendingStakes` can lead to DOS

Summary

The audited smart contract protocol contains two Solidity functions with unbounded loops, where an array is iterated. The potential risk arises from the excessive gas consumption during the loop execution, which may lead to surpassing the gas limit per block and causing function failures. The identified functions are deletePendingStake and consolidatePendingStakes.

Vulnerability Details

The audited smart contract protocol contains two functions with potential vulnerabilities due to unbounded loops iterating over arrays. The first function, deletePendingStake, iterates over the pendingStakes array without a predefined upper limit, which may lead to excessive gas consumption, especially for larger array sizes. The second function, consolidatePendingStakes., also utilizes an unbounded loop over the same array, potentially causing high gas usage. Both functions pose a risk of surpassing the gas limit per block, resulting in transaction failures and disruptions to the intended functionality of the smart contract protocol.

function deletePendingStake(uint256 _i) private {
for (uint256 i = _i; i < pendingStakes.length - 1; i++) {
pendingStakes[i] = pendingStakes[i + 1];
}
pendingStakes.pop();
}
function consolidatePendingStakes() private {
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) {
positions[_stake.holder].holder = _stake.holder;
positions[_stake.holder].TST += _stake.TST;
positions[_stake.holder].EUROs += _stake.EUROs;
deletePendingStake(uint256(i));
// pause iterating on loop because there has been a deletion. "next" item has same index
i--;
}
}
}

Impact

The identified unbounded loops may result in excessive gas consumption, potentially surpassing the gas limit per block. This could lead to transaction failures and disrupt the intended functionality of the smart contract protocol.

Code Snippet

https://github.com/Cyfrin/2023-12-the-standard/blob/91132936cb09ef9bf82f38ab1106346e2ad60f91/contracts/LiquidationPool.sol#L105-L110

https://github.com/Cyfrin/2023-12-the-standard/blob/91132936cb09ef9bf82f38ab1106346e2ad60f91/contracts/LiquidationPool.sol#L119-L132

Tools Used

Manual Review

Recommendations

Limit Loop Iterations: Implement a mechanism to limit the number of iterations in loops, preventing excessive gas consumption. This ensures that the loops will complete within reasonable gas limits.

Updates

Lead Judging Commences

hrishibhat Lead Judge over 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

pendingstake-dos

hrishibhat Lead Judge over 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

pendingstake-high

Support

FAQs

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