Skip to content
Business logic Audit finding Intermediate

Due to incorrect design in Consortium::setNextValidatorSet the validator set could not be set in certain valid scenarios

The smart contract's setNextValidatorSet function requires the new validator set's epoch to be exactly one greater than the current epoch, so if a validator set remains valid for multiple epochs, a new set cannot be set. This could prevent the protocol from updating its validator set, potentially causing issues if validators become malicious.

mrMorningstar Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#38231 [SC-Low] Due to incorrect design in `Consortium::setNextValidatorSet` the validator set could

Submitted on Dec 28th 2024 at 14:51:40 UTC by @MrMorningstar for Audit Comp | Lombard

Description

Brief/Intro

After the initial validator is set by owner in setInitialValidatorSet , the new validator set can be set via setNextValidatorSet which looks like this:

JavaScript
    function setNextValidatorSet(
        bytes calldata payload,
        bytes calldata proof
    ) external {
        // payload validation
        if (bytes4(payload) != Actions.NEW_VALSET) {
            revert UnexpectedAction(bytes4(payload));
        }
        Actions.ValSetAction memory action = Actions.validateValSet(
            payload[4:]
        );

        ConsortiumStorage storage $ = _getConsortiumStorage();

        // check proof
        bytes32 payloadHash = sha256(payload);
        checkProof(payloadHash, proof);

        if (action.epoch != $.epoch + 1) revert InvalidEpoch();

        _setValidatorSet( // qanswered check this func and input params
            $,
            action.validators,
            action.weights,
            action.weightThreshold,
            action.epoch
        );
    }

Anyone can call the setNextValidatorSet but it requires signatures by the current consortium to be valid.

Vulnerability Details

The new validator set will typically be set every epoch, but there is no obligation to that which means there is possibility that one validator set could be valid for multiple epochs.

The issue arise with this check:

JavaScript
if (action.epoch != $.epoch + 1) revert InvalidEpoch();

This check expect that new set is set every epoch, which means if one set was valid for multiple epochs and it was not changed, it will not be possible to set a new validator set .

Example:

If last validator set is set in epoch 10 and it was valid for 2 epochs so the attempt is to set a new validator set in epoch 12, the function would not allow that.

This is demonstrated in the PoC provided.

Impact Details

New validator set could not be set. Which could cause issues to the protocol and its users (especially if some validators became malleable after some time and misbehave).

Recommendation

Make the following change in setNextValidatorSet:

Diff
    function setNextValidatorSet(
        bytes calldata payload,
        bytes calldata proof
    ) external {
        // payload validation
        if (bytes4(payload) != Actions.NEW_VALSET) {
            revert UnexpectedAction(bytes4(payload));
        }
        Actions.ValSetAction memory action = Actions.validateValSet(
            payload[4:]
        );

        ConsortiumStorage storage $ = _getConsortiumStorage();

        // check proof
        bytes32 payloadHash = sha256(payload);
        checkProof(payloadHash, proof);

-        if (action.epoch != $.epoch + 1) revert InvalidEpoch();
+        if (action.epoch < $.epoch + 1) revert InvalidEpoch();

        _setValidatorSet( // qanswered check this func and input params
            $,
            action.validators,
            action.weights,
            action.weightThreshold,
            action.epoch
        );
    }

Proof of Concept

Proof of Concept

Paste this test in Consortium.ts :

JavaScript
        it('cannot set next set if previous one was valid for multiple epochs', async function () {
            const data = await signNewValSetPayload(
                [signer3, signer1, signer2],
                [true, true, false],
                12, // epoch 12
                [signer1.publicKey, signer2.publicKey],
                [1, 2],
                3,
                1
            );
            await expect(lombard.setNextValidatorSet(data.payload, data.proof))
                .to.revertedWithCustomError(lombard,"InvalidEpoch");
        });

Execute the following command:

yarn hardhat test --grep "cannot set next set if previous one was valid for multiple epochs"

The test will pass which will prove the flaw in the design

  Consortium
    With Initial ValidatorSet
      ✔ cannot set next set if previous one was valid for multiple epochs (168ms)


  1 passing (2s)

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

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

The check requires the new epoch to be exactly current epoch plus one, instead of allowing any later epoch.

Impact

The validator set cannot be updated, which could cause issues for the protocol and its users, especially if validators become malicious.

What the attacker needed

A validator set remains valid for multiple epochs

How it was found

  1. Set an initial validator set at epoch 10.
  2. Attempt to set a new validator set at epoch 12 (skipping epoch 11).
  3. The transaction reverts with InvalidEpoch.

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 manages a list of validators (computers that approve transactions). The contract only allows a new list to be set if the epoch number (a counter) is exactly one higher than the current one. If the current list stays valid for more than one epoch, the contract rejects any new list, so the validators cannot be updated.

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 mrMorningstar

View all

6 more disclosed reports, best first.

More from Lombard

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.