Attacker can partially DoS L1 operations in StakingManager by making huge number of deposits
The StakingManager contract deletes its entire pending deposit queue in one operation, which can exceed the block gas limit if the queue is large. An attacker can flood the queue with many minimal deposits, causing the operator's processing function to revert with out-of-gas and disrupting staking operations.
givn Follow with 0x15, AnimeConsumer and 6 others
Originally disclosed on Code4rena
Submitted by givn, also found by 0x15, AnimeConsumer, chibi, CoheeYang, dimorge, holtzzx, K42, and NexusAudits
When a user stakes in StakingManager, initially the funds go towards hypeBuffer and when it is filled, every deposit is placed in a L1 operation queue.
L1Operation[] private _pendingDeposits;
Once a day an operator calls processL1Operations. The amount of each deposit is delegated towards a validator and once the whole queue is processed it gets deleted.
if (_depositProcessingIndex == length) {
delete _pendingDeposits;
_depositProcessingIndex = 0;
}
The issue is that the whole array gets deleted, which can exceed the block gas limit (30M gas) if the array is big enough. It is very unlikely that this situation happens on its own, because even the biggest staking protocol Lido has < 3k daily active users during its peak usages for the last 4 years.
However, an attacker can intentionally spam the queue with minimal deposits and cause a DoS. The scenario would be something like this:
- Attacker takes out a (flash) loan of HYPE
- Attacker stakes minimum amounts to flood the deposit queue and receives kHYPE in return
- The attacker then sells the kHYPE and pays loan fees
- When the
StakingManageroperator callsprocessL1Operationsit will fail with out of gas error, because the amount of gas required to delete the array will be > 30M.
We should note that:
-
minStakeAmountdoesn’t stop the attack since HYPE is relatively cheap -
This DoS is done only via staking and is different form DoS caused by withdrawals.
Impact
-
StakingManageroperations will be disrupted, because processing the last element of the deposit queue will cause delete which will revert with OOG. Only allowing batches (max - 1) element to be processed. -
Last element will never deposit.
-
Rebalancing and user deposits both will be affected.
-
resetL1OperationsQueuewill reach block gas limit and revert.
Root Cause
The whole pending deposit queue is deleted at once without the possibility of doing it partially.
Proof of Concept
This PoC demonstrates how processL1Operations and resetL1OperationsQueue will revert with Out Of Gas when _pendingDeposits is too big.
Run forge install foundry-rs/forge-std to get latest APIs required for most accurate gas measurement.
We assume the following values for limits and price:
### (take note of 2 block types, one's limit is much less), the bigger is 30M
cast block --rpc-url https://rpc.hyperliquid.xyz/evm
HYPE price = 16.00$ # as time of writing
minStakeAmount = 0.1 HYPE
To make the delete exceed 30M in gas, about 4480 deposits need to be made. The amount necessary to execute the attack would be minStakeAmount * 4480 * HYPE price or ~7 168$ as of today.
Flash loan fees range from 0.09% to 0.3%. If we assume the higher bound, that would be 21.5$ in fees, making the attack quite affordable. Any griefer can afford this amount.
Place the code below under StakingManager.t.sol:
function test_DepositsDoS() public {
// Set delegation targets for staking managers
vm.startPrank(manager);
validatorManager.activateValidator(validator);
validatorManager.setDelegation(address(stakingManager), validator);
// Set target buffer to 0
stakingManager.setTargetBuffer(0);
// Add many L1 operations in array
uint256 stakeAmount = 0.1 ether;
vm.deal(user, 10_000 ether);
vm.startPrank(user);
// 0.1 * 4480 (num deposits) * 16 (current HYPE price) = 7168 $ required
for (uint256 i; i < 4480; ++i) { //
stakingManager.stake{value: stakeAmount}();
}
// Try to process L1 operations
// block gas limit: cast block --rpc-url https://rpc.hyperliquid.xyz/evm (take note of 2 block types, one's limit is much less)
vm.startPrank(operator);
vm.startSnapshotGas("processL1Operations");
stakingManager.processL1Operations();
uint256 gasUsed = vm.stopSnapshotGas();
console.log("gasUsed", gasUsed);
assertGt(gasUsed, 30_000_000);
}
Recommended Mitigation Steps
Allow deleting _pendingDeposits in multiple transactions. On each call, make sure to check that all elements have been processed.
Kinetiq disputed and commented:
We can use
processL1Operations(uint256 batchSize)to batch process those queued operations, also we are able to reset them at once by usingresetL1OperationsQueue.
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
Impact
Processing the deposit queue can revert with out-of-gas, preventing the last deposit from being processed and disrupting rebalancing and user deposits; the reset function also reverts.
What the attacker needed
Flash loan of HYPE tokens; ability to stake minimum amounts; operator calls processL1Operations
The fix
The contract should allow deleting the pending deposits array in multiple transactions, checking that all elements are processed.
How it was found
- Attacker takes out a flash loan of HYPE tokens.
- Attacker stakes minimum amounts repeatedly to flood the deposit queue.
- Attacker sells the received kHYPE and repays the loan.
- Operator calls processL1Operations, which reverts with out-of-gas due to deleting the large array.
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 pending deposits. When it processes them, it deletes the whole list at once. If the list is very long, deleting it costs more gas than a block allows, so the transaction fails. An attacker can make the list very long by making many tiny deposits, which stops the operator from processing deposits.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.