Skip to content
Business logic Audit finding Intermediate

Functions withdrawWithConfirm and depositWithConfirm incorrectly update genesisValidators state

The staking library fails to keep the genesisValidators list in sync before a subnet is bootstrapped: a validator who adds stake keeps an outdated weight, and a validator who leaves is not removed from the list. This leaves the genesis validator set and weights incorrect.

sin1st3r__ Follow

Originally disclosed on Code4rena

Submitted by sin1st3r__

https://github.com/code-423n4/2025-02-recall/blob/ab5f90b9b0322016ecce6dd71c528a935544bec5/contracts/contracts/lib/LibStaking.sol#L505

Finding description and impact

The vulnerable functions are LibStaking::withdrawWithConfirm() and LibStaking::depositWithConfirm().

When the subnet is not yet bootstrapped and a validator has joined the subnet and staked funds, LibStaking::depositWithConfirm() does not update the weight of the validator if he increased his stake by calling addStake(). This will lead to the validator having an outdated weight (less than the weight he should have).

    function depositWithConfirm(address validator, uint256 amount) internal {
        ..........

        if (!s.bootstrapped) {
            // add to initial validators avoiding duplicates if it
            // is a genesis validator.
            bool alreadyValidator;
            uint256 length = s.genesisValidators.length;
            for (uint256 i; i < length; ) {
                if (s.genesisValidators[i].addr == validator) {
                    alreadyValidator = true;
                    break;
                }
                unchecked {
                    ++i;
                }
            }
     -----> if (!alreadyValidator) {
                uint256 collateral = s.validatorSet.validators[validator].confirmedCollateral;
                Validator memory val = Validator({
                    addr: validator,
                    weight: collateral,
                    metadata: s.validatorSet.validators[validator].metadata
                });
                s.genesisValidators.push(val);
            }
        }
    }

When the subnet is not yet bootstrapped and a validator has joined the subnet and staked funds and then left before the subnet is bootstrapped by calling the function leave(), LibStaking::withdrawWithConfirm() does not update the genesisValidators state in a subnet which is not yet bootstrapped, which will lead to genesisValidators reflecting an incorrect list of genesis validators.

    function withdrawWithConfirm(address validator, uint256 amount) internal {
        SubnetActorStorage storage s = LibSubnetActorStorage.appStorage();

        // record deposit that updates the total collateral
        s.validatorSet.recordWithdraw(validator, amount);
        // confirm deposit that updates the confirmed collateral
        s.validatorSet.confirmWithdraw(validator, amount);
    }

Recommended mitigation steps

Ensure that the genesisValidators state is updated in the function withdrawWithConfirm to ensure that changes are reflected properly if validators leave pre-bootstrap. Additionally, update the weight of the validator who increases his stake in depositWithConfirm


The original report as published on Code4rena, by sin1st3r__. 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 genesisValidators list is only appended to on first deposit and is never updated on later stake increases or withdrawals before bootstrap.

Impact

The genesis validator set and weights could be inaccurate before bootstrap, which may affect how the subnet is initialised.

What the attacker needed

Subnet not yet bootstrapped; validator has joined and staked

The fix

The genesisValidators state should be updated on withdrawal and the validator's weight updated on deposit before bootstrap.

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 subnet collects a list of founding validators before it starts running. This code adds a validator to that list once but never updates their weight when they stake more, and never removes them if they leave. So the founding list can show wrong weights or people who are no longer there.

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.

More by sin1st3r__

View all

11 more disclosed reports, best first.

More from Recall

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.