getNextValidator() error could temporarily make depositEther() inoperable
The depositEther() function reverts if a validator's public key has already been used, because the code checks activeValidators[pubKey] and reverts. An attacker could cause a temporary denial of service by making a validator key be reused, blocking deposits until governance removes the bad validator.
Originally disclosed on Code4rena
Submitted by 141345
When depositEther(), if 1 validators is used before, the whole deposit function will revert, causing DoS. depositEther() function will be inoperable until the gov manually removes the mistaken validator.
Proof of Concept
In depositEther(), if the pubKey is already used, the whole loop will revert, and the deposit operation cannot move on.
// src/frxETHMinter.sol
function depositEther() external nonReentrant {
// ...
for (uint256 i = 0; i < numDeposits; ++i) {
// Get validator information
(
bytes memory pubKey,
bytes memory withdrawalCredential,
bytes memory signature,
bytes32 depositDataRoot
) = getNextValidator(); // Will revert if there are not enough free validators
// Make sure the validator hasn't been deposited into already, to prevent stranding an extra 32 eth
// until withdrawals are allowed
require(!activeValidators[pubKey], "Validator already has 32 ETH");
// ...
}
And in the next rewards cycle, lastRewardAmount will be linearly added to storedTotalAssets, their sum is the return value of totalAssets():
function totalAssets() public view override returns (uint256) {
// ...
if (block.timestamp >= rewardsCycleEnd_) {
// no rewards or rewards fully unlocked
// entire reward amount is available
return storedTotalAssets_ + lastRewardAmount_;
}
// rewards not fully unlocked
// add unlocked rewards to stored total
uint256 unlockedRewards = (lastRewardAmount_ * (block.timestamp - lastSync_)) / (rewardsCycleEnd_ - lastSync_);
return storedTotalAssets_ + unlockedRewards;
}
Temporarily the depositEther() function will be inaccessible. Until the governance calls the registry to pop the wrong validator.
// src/OperatorRegistry.sol
function popValidators(uint256 times) public onlyByOwnGov {
// Loop through and remove validator entries at the end
for (uint256 i = 0; i < times; ++i) {
validators.pop();
}
emit ValidatorsPopped(times);
}
Recommended Mitigation Steps
Use try/catch to skip the wrong validator, then the deposit function will be more robust to unexpected situations.
FortisFortuna (Frax) commented:
We plan to keep an eye on the number of free validators and have a decent sized buffer of them.
Awarding as Medium, given that this can disable deposits, the registry should check against the mapping.
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 deposit loop does not handle the case where a validator public key is already marked as active, so the require statement reverts the entire transaction instead of skipping that validator.
Impact
Deposits are temporarily blocked (denial of service) until governance manually removes the offending validator, but the report does not claim permanent loss of funds.
What the attacker needed
A validator key already used; governance intervention needed to recover
The fix
The deposit function should use try/catch to skip a bad validator, and the registry should check against the activeValidators mapping before adding validators.
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.
This is a smart contract bug where a function that accepts deposits stops working if it encounters a validator that was already used. The check that prevents double deposits causes the whole transaction to fail, so no one can deposit until the owner manually removes the bad validator.
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.