depositETHOverTargetWeight() malicious modifications poolIdArrayIndexForExcessDeposit
The function depositETHOverTargetWeight() updates the pool index for excess ETH deposits even when no validator can be funded, allowing an attacker to manipulate the index with a tiny transfer. This lets the attacker prioritise their own validator in the next allocation round.
Submitted by bin2chen, also found by sces60107
Malicious modification in favor of your own funds’ allocation rounds.
Proof of Concept
poolIdArrayIndexForExcessDeposit is used to save depositETHOverTargetWeight(), which Pool is given priority for allocation in the next round.
The current implementation rolls over to the next pool, regardless of whether the current balance is sufficient or not.
poolAllocationForExcessETHDeposit:
function poolAllocationForExcessETHDeposit(uint256 _excessETHAmount)
external
override
returns (uint256[] memory selectedPoolCapacity, uint8[] memory poolIdArray)
{
..
for (uint256 j; j < poolCount; ) {
uint256 poolCapacity = poolUtils.getQueuedValidatorCountByPool(poolIdArray[i]);
uint256 poolDepositSize = ETH_PER_NODE - poolUtils.getCollateralETH(poolIdArray[i]);
uint256 remainingValidatorsToDeposit = ethToDeposit / poolDepositSize;
selectedPoolCapacity[i] = Math.min(
poolAllocationMaxSize - selectedValidatorCount,
Math.min(poolCapacity, remainingValidatorsToDeposit)
);
selectedValidatorCount += selectedPoolCapacity[i];
ethToDeposit -= selectedPoolCapacity[i] * poolDepositSize;
@> i = (i + 1) % poolCount;
//For ethToDeposit < ETH_PER_NODE, we will be able to at best deposit one more validator
//but that will introduce complex logic, hence we are not solving that
@> if (ethToDeposit < ETH_PER_NODE || selectedValidatorCount >= poolAllocationMaxSize) {
@> poolIdArrayIndexForExcessDeposit = i;
break;
}
Suppose now, the balance of StaderStakePoolsManager is 0 and poolIdArrayIndexForExcessDeposit = 1
If I have a Validator with funds to be allocated at pool = 2, I can maliciously transfer 1 wei and let poolIdArrayIndexForExcessDeposit roll over to 2.
This way, the next round of funding will be allocated in favor of my Validator.
Normally, if the current funds are not enough to allocate one Validator, then poolIdArrayIndexForExcessDeposit should not be rolled over. This is fairer.
Suggested: If poolAllocationForExcessETHDeposit() returns all 0’s, revert to avoid rolling poolIdArrayIndexForExcessDeposit.
Recommended Mitigation Steps
function depositETHOverTargetWeight() external override nonReentrant {
..
+ bool findValidator;
for (uint256 i = 0; i < poolCount; i++) {
uint256 validatorToDeposit = selectedPoolCapacity[i];
if (validatorToDeposit == 0) {
continue;
}
+ findValidator = true;
address poolAddress = IPoolUtils(poolUtils).poolAddressById(poolIdArray[i]);
uint256 poolDepositSize = staderConfig.getStakedEthPerNode() -
IPoolUtils(poolUtils).getCollateralETH(poolIdArray[i]);
lastExcessETHDepositBlock = block.number;
//slither-disable-next-line arbitrary-send-eth
IStaderPoolBase(poolAddress).stakeUserETHToBeaconChain{value: validatorToDeposit * poolDepositSize}();
emit ETHTransferredToPool(i, poolAddress, validatorToDeposit * poolDepositSize);
}
+ require(findValidator,"not valid validator");
Assessed type
Context
manoj9april (Stader) confirmed and commented:
Sure, we will fix this.
manoj9april (Stader) disagreed with severity and commented:
We expect this issue to be in QA. As in,
Cooldowneventually evens out every pool.
Technically valid, although the impact should remain small. Especially as the
cooldownprevents it from using this frequently and really imbalancing among validators. Keeping Medium severity as funds are at stake and it wasn’t the intended design.
sanjay-staderlabs (Stader) commented:
@Picodes - can you please elaborate how funds are at stake? I think funds will never be at stake, as funds might go to a different
pool, and there is no risk of funds being at stake in this case.
My reasoning was although the impact is very limited, as the system can be gamed to send funds to the incorrect validator, which then could behave incorrectly, this report qualifies for Med severity under “leak value with a hypothetical attack path with stated assumptions, but external requirements”.
sanjay-staderlabs (Stader) commented:
@Picodes - just to clarify, there is no incorrect validator. All validators work as expected. We have penalty mechanics in place to penalize and exit validators if they behave incorrectly, so the question of sending ETH to the incorrect validator or fund loss does not exist.
Yes, it is not an incorrect validator in the sense of a malicious one as safeguards exist, just compared to what it would have been without this bug. Unless I am missing something, you still could slightly game the system; in favor of, for example, your own validators, less performing ones, or validators starting to behave incorrectly.
sanjay-staderlabs (Stader) commented:
This is fixed.
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
Likely the function updates the pool index even when the deposit amount is too small to fund any validator, instead of reverting or leaving the index unchanged.
Impact
The attacker could slightly game the system to favour their own validators, but the impact is limited by a cooldown and safeguards prevent fund loss.
What the attacker needed
Attacker has a validator in a specific pool; contract balance is zero or insufficient; attacker can send 1 wei
The fix
The function should revert if no validators are found to deposit, preventing the index from rolling over unnecessarily.
How it was found
- Ensure the StaderStakePoolsManager balance is zero and the pool index is set to 1.
- Transfer 1 wei to the contract to trigger the index rollover to 2.
- The next allocation round will prioritise the attacker's validator in pool 2.
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 decides which pool of validators gets new deposits next. The code that picks the next pool can be tricked by sending a tiny amount of cryptocurrency, so the attacker's own validator gets funded first. This is unfair to other users.
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.