Skip to content
DoS Audit finding Advanced

A snapshot may face a permanent DoS if both a slashing event occurs in the NativeVault and the staker’s validator is penalized

A snapshot update could try to burn more shares than the staker owns when a slashing event plus a beacon chain penalty exceeds the staker's balance, causing the transaction to revert. This permanently blocks snapshot validation for that staker, so they keep receiving rewards despite an empty validator.

KupiaSec Follow

Originally disclosed on Code4rena

Submitted by KupiaSec

https://github.com/code-423n4/2024-07-karak/blob/main/src/NativeVault.sol#L126-L162 https://github.com/code-423n4/2024-07-karak/blob/main/src/NativeVault.sol#L476-L495 https://github.com/code-423n4/2024-07-karak/blob/main/src/NativeVault.sol#L517-L525 https://github.com/code-423n4/2024-07-karak/blob/main/src/NativeVault.sol#L507-L515

Impact

The staker can still receive rewards even if their validators are empty.

Proof of Concept

Let’s consider the following scenario:

  1. Alice has a validator whose balance is 32 ETH.

  2. A slashing event occurs in the NativeVault, resulting in Alice being slashed by 2 ETH, reducing her withdrawable assets to 30 ETH.

  3. Subsequently, Alice’s validator loses all its funds (this can happen within the 7-day snapshot period, even within just 1 hour). A snapshot should then be taken to reduce Alice’s assets by 32 ETH, which requires calling the validateSnapshotProofs() function for Alice’s validator.

        function validateSnapshotProofs(
            address nodeOwner,
            BeaconProofs.BalanceProof[] calldata balanceProofs,
            BeaconProofs.BalanceContainer calldata balanceContainer
        )
            external
            nonReentrant
            nodeExists(nodeOwner)
            whenFunctionNotPaused(Constants.PAUSE_NATIVEVAULT_VALIDATE_SNAPSHOT)
        {
            NativeVaultLib.Storage storage self = _state();
            NativeVaultLib.NativeNode storage node = self.ownerToNode[nodeOwner];
            NativeVaultLib.Snapshot memory snapshot = node.currentSnapshot;
    
            if (node.currentSnapshotTimestamp == 0) revert NoActiveSnapshot();
    
            BeaconProofs.validateBalanceContainer(snapshot.parentBeaconBlockRoot, balanceContainer);
    
            for (uint256 i = 0; i < balanceProofs.length; i++) {
                NativeVaultLib.ValidatorDetails memory validatorDetails =
                    node.validatorPubkeyHashToDetails[balanceProofs[i].pubkeyHash];
    
                if (validatorDetails.status != NativeVaultLib.ValidatorStatus.ACTIVE) revert InactiveValidator();
                if (validatorDetails.lastBalanceUpdateTimestamp >= node.currentSnapshotTimestamp) {
                    revert ValidatorAlreadyProved();
                }
    
    153         int256 balanceDeltaWei = self.validateSnapshotProof(
                    nodeOwner, validatorDetails, balanceContainer.containerRoot, balanceProofs[i]
                );
    
                snapshot.remainingProofs--;
    158         snapshot.balanceDeltaWei += balanceDeltaWei;
            }
    
    161     _updateSnapshot(node, snapshot, nodeOwner);
        }
    

    In this call, snapshot.balanceDeltaWei is set to -32 ETH, and the _updateSnapshot() function is invoked at L161.

  4. In the _updateSnapshot() function, the _updateBalance() function is invoked at L490, with totalDeltaWei = -32 ETH, as noted at L482.

        function _updateSnapshot(
            NativeVaultLib.NativeNode storage node,
            NativeVaultLib.Snapshot memory snapshot,
            address nodeOwner
        ) internal {
            if (snapshot.remainingProofs == 0) {
    482         int256 totalDeltaWei = int256(snapshot.nodeBalanceWei) + snapshot.balanceDeltaWei;
    
                node.withdrawableCreditedNodeETH += snapshot.nodeBalanceWei;
    
                node.lastSnapshotTimestamp = node.currentSnapshotTimestamp;
                delete node.currentSnapshotTimestamp;
                delete node.currentSnapshot;
    
    490         _updateBalance(nodeOwner, totalDeltaWei);
                emit SnapshotFinished(nodeOwner, node.nodeAddress, node.lastSnapshotTimestamp, totalDeltaWei);
            } else {
                node.currentSnapshot = snapshot;
            }
        }
    
  5. Within the _updateBalance() function, the _decreaseBalance() function is called at L521 with a decrease amount of 32 ETH.

        function _updateBalance(address _of, int256 assets) internal {
            if (assets > 0) {
                _increaseBalance(_of, uint256(assets));
            } else if (assets < 0) {
    521         _decreaseBalance(_of, uint256(-assets));
            } else {
                return;
            }
        }
    
  6. In the _decreaseBalance() function, shares are burned at L511.

        function _decreaseBalance(address _of, uint256 assets) internal {
            NativeVaultLib.Storage storage self = _state();
            uint256 shares = previewWithdraw(assets);
            _beforeWithdraw(assets, shares);
    511     _burn(_of, shares);
            self.totalAssets -= assets;
            self.ownerToNode[_of].totalRestakedETH -= assets;
            emit DecreasedBalance(self.ownerToNode[_of].totalRestakedETH);
        }
    

The problem arises in step 6. Here, the shares being burned correspond to 32 ETH, while Alice’s shares only amount to 30 ETH. This discrepancy causes the burn amount to exceed the existing share amount, leading to a reversal of the transaction. As a result, the snapshot for Alice will be permanently DoSed, and her share amount will remain unchanged. Consequently, Alice can still receive rewards even though her validator is empty. In addition, nobody can call validateExpiredSnapshot() for Alice.

A malicious staker could intentionally orchestrate this scenario by creating a validator and engaging in malicious behavior. If the malicious action fails, they would lose all 32 ETH but could still receive rewards.

Recommended Mitigation Steps

The _decreaseBalance() function should be enhanced to properly handle cases where the burning amount exceeds the existing share amount.

For example:

    function _decreaseBalance(address _of, uint256 assets) internal {
        NativeVaultLib.Storage storage self = _state();
-       uint256 shares = convertToShares(assets);
+       uint256 shares = Math.min(convertToShares(assets), balanceOf(nodeOwner));
        _beforeWithdraw(assets, shares);
        _burn(_of, shares);
        self.totalAssets -= assets;
        self.ownerToNode[_of].totalRestakedETH -= assets;
        emit DecreasedBalance(self.ownerToNode[_of].totalRestakedETH);
    }

MiloTruck (judge) decreased severity to Medium and commented:

Subsequently, Alice’s validator loses all its funds (this can happen within the 7-day snapshot period, even within just 1 hour). A snapshot should then be taken to reduce Alice’s assets by 32 ETH

A validator getting slashed for its entire effective balance is only possible due to the correlation penalty, which is extremely unlikely. Historically, most slashing penalties have been around 1 ETH.

The following conditions must be met for this issue to occur:

  • Karak slashes an operator for X amount, followed by beacon chain slashing for Y amount.
  • X +Y must exceed the node owner’s total restaked balance.

I believe this is extremely unlikely to occur, and as such, medium severity is appropriate.

MiloTruck (judge) commented:

According to the C4 severity categorization, the criteria for medium severity is:

2 — Med: Assets not at direct risk, but the function of the protocol or its availability could be impacted, or leak value with a hypothetical attack path with stated assumptions, but external requirements.

As stated in my initial comment, this requires both Karak and beacon chain slashing to occur. The upper limit of how much the DSS can slash an account for is 100%:

    uint256 public constant HUNDRED_PERCENT_WAD = 100e18;
    uint256 public constant MAX_SLASHING_PERCENT_WAD = HUNDRED_PERCENT_WAD;

Therefore, it is possible for the sum of Karak and beacon chain slashing to exceed 100%, however unlikely. I view this as “with stated assumptions, but external requirements”.

Regarding impact, validateSnapshotProofs() and validateExpiredSnapshot() will permanently be DOSed for the user - they can’t stake into the vault in the future even if they would like to. This fulfills “the function of the protocol or its availability could be impacted”.

As such, this remains as medium.

karan-andalusia (Karak) confirmed

Karak mitigated:

This mitigation accounts for the decrease in balance of the users shares before burning.

Status: Mitigation confirmed. Full details in reports from 0xCiphky, sl1 (1, 2) and KupiaSec.


The original report as published on Code4rena, by KupiaSec. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 _decreaseBalance function burns shares for the full asset amount without capping the burn at the staker's actual share balance.

Impact

The snapshot for the affected staker is permanently blocked, so they keep receiving rewards despite an empty validator and cannot stake into the vault in future.

What the attacker needed

Karak slashes the operator; Beacon chain slashing also occurs; Combined slashing exceeds restaked balance

The fix

The _decreaseBalance function should cap the number of shares burned at the staker's actual share balance; the project mitigated this by accounting for the decrease in the user's shares before burning.

How it was found

  1. Alice has a validator with 32 ETH.
  2. A slashing event in the NativeVault reduces her withdrawable assets to 30 ETH.
  3. Her validator then loses all funds within the snapshot period.
  4. validateSnapshotProofs is called and sets the balance delta to -32 ETH.
  5. _updateSnapshot calls _updateBalance with a negative total delta.
  6. _decreaseBalance tries to burn shares worth 32 ETH, which exceeds Alice's 30 ETH of shares, so the transaction reverts.

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 staker's balance is tracked in shares. When a snapshot tries to reduce the balance by more than the staker actually has, the burn operation fails and the whole transaction reverts. Because the snapshot can never complete, the staker's old balance stays in place and they keep earning rewards even though their validator has no funds.

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.

More by KupiaSec

View all

28 more disclosed reports, best first.

More from Karak Restaking

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.