ValidatorWithdrawalVault.distributeRewards can be called to make operator slashable
The permissionless distributeRewards function can be called by anyone to reset the vault balance to zero before a validator withdrawal, changing the operatorShare calculation so that it falls below the accrued penalty and triggers a slash. An attacker can front-run the withdrawal to cause this loss, or an operator can call it to rescue rewards before being slashed.
Originally disclosed on Code4rena
Submitted by rvierdiiev
An attacker can call distributeRewards right before settleFunds to make operatorShare < penaltyAmount. As a result, the validator will face loses.
Proof of Concept
ValidatorWithdrawalVault.distributeRewards can be called by anyone. It’s purpose is to distribute validators rewards among the stakers protocol and the operator. After the call, the balance of ValidatorWithdrawalVault becomes 0.
ValidatorWithdrawalVault.settle is called when a validator is withdrawn from beacon chain. In this case, the balance of the contract is used to find operatorShare. If it’s less than the accrued penalty by the validator, then operator is slashed.
Because distributeRewards is permissionless, then next situation is possible:
- Operator decided to withdraw a validator. At the moment of that call, the balance of
ValidatorWithdrawalVaultis not 0 andoperatorShareis 1 eth. Also the validator accrued 4.5 eth of penalty. - A malicious user sees when 32 eth of a validator’s deposit is sent to the
ValidatorWithdrawalVaultand frontruns it withdistributeRewardscall. This makes balance to be 32 eth. operatorSharewill be 4 eth this time (permisssionless) and the penalty is 4.5, so the user is slashed.- In this case, if a malicious user didn’t call
distributeRewards, then the slash would not occur.
Also in same way, a permissioned operator can call distributeRewards to get their rewards when they are going to be slashed. As permissioned validators are not forced to have collateral to be slashed, they rescued their earnings; otherwise, they would have been sent to the pool.
Tools Used
VsCode
Recommended Mitigation Steps
Maybe think about restricting access to the distributeRewards function.
Assessed type
Access Control
manoj9april (Stader) disputed and commented:
This is intended, as we want to
slash SDfor an operator if the penalty is greater than operator share. Rewards share of vaults is going to be distributed by Stader every so often to enforce this.
This report shows how an operator can be slashed depending on the order of actions. It seems a valid Medium severity issue to me, as front-running/changing a sequence of action could lead to a loss of funds compared to what the
operatorandusersthought they should get.Wouldn’t it solve this to also fetch and solve
penaltyAmountduringdistributeRewards?
Not sure if I’m following the impact here.
At the moment of that call, balance of
ValidatorWithdrawalVaultis not 0 andoperatorShareis 1 eth. Also validator accrued 4.5 eth of penalty.This case means the validator has to be slashed. In both cases, the user must be slashed according to the design. I can’t see the exact root cause. Also,
distributeRewardscan be called at any time; no need to make a front-run, so the system behaves as intended.
rvierdiyev (warden) commented:
@Co0nan - the problem here is that once
distributeRewardsis called, then all balances of the vault becomes 0. As I described in the example, the user had 1 eth inside the vault before thedistributeRewardscall and he has 4.5 eth of penalty.When withdrawals of 32 eth should come, the user’s balance will be 1 + 4 eth, which is more than penalty. But because a malicious user calls
distributeRewardsbefore 32 eth will come, then the user in the end has only 4 eth, which is less than penalty.
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 permissionless distributeRewards function resets the vault balance to zero, and the subsequent settle calculation uses that reduced balance to determine operatorShare, making it possible for the share to fall below the penalty amount.
Impact
An operator could be slashed and lose funds compared to what they and users expected, and a permissioned operator could rescue rewards before being slashed.
What the attacker needed
Validator has accrued a penalty; attacker can front-run the withdrawal transaction; distributeRewards is permissionless
The fix
The report suggests restricting access to the distributeRewards function, and the judge suggests also fetching and solving penaltyAmount during distributeRewards.
How it was found
- Operator decides to withdraw a validator; vault balance is not zero and operatorShare is 1 ETH, with 4.5 ETH penalty accrued.
- Attacker sees the 32 ETH deposit being sent to the vault and front-runs it with a distributeRewards call.
- The vault balance becomes 32 ETH and operatorShare is recalculated as 4 ETH.
- Since 4 ETH is less than the 4.5 ETH penalty, the operator is slashed.
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 holds rewards and penalties for a validator operator. Anyone can call a function that pays out rewards and empties the contract. If this is done just before a withdrawal, the operator's share is calculated from a smaller balance and can end up below the penalty, so the operator gets slashed (loses money).
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.