Skip to content
Business logic Audit finding Intermediate

Signatures for the first batch will be rejected by VerifyVoteExtensionHandler

The first batch's vote extensions are rejected because the code checks for batch number equal to the default sequence start, but batch numbering begins at that value plus one. This prevents validators from signing the first batch.

zxriptor Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-12-seda-protocol-judging/issues/188

Found by

zxriptor

Summary

An incorrect check for the first batch number will result in all vote extensions with batch signatures being rejected.

Root Cause

In the VerifyVoteExtensionHandler, a signature is verified to ensure it was properly signed by an active validator:

GOLANG
	err = h.verifyBatchSignatures(ctx, batch.BatchNumber, batch.BatchId, req.VoteExtension, req.ValidatorAddress)
	if err != nil {
		h.logger.Error("failed to verify batch signature", "req", req, "err", err)
		return nil, err
	}

To ensure the batch was signed with the correct key used by the validator at the time of signing, the public key record is retrieved from the validator tree entry of the previous batch:

GOLANG
	valEntry, err := h.batchingKeeper.GetValidatorTreeEntry(ctx, batchNum-1, valOper)
	if err != nil {
		if errors.Is(err, collections.ErrNotFound) {
			if len(voteExtension) == 0 {
				return nil
			}
			return ErrUnexpectedBatchSignature
		}
		return err
	}
	expectedAddr = valEntry.EthAddress

There is an inherent cold start issue: when the very first batch is signed, there is no previous record to verify the validator's key. In this case, the code defaults to using the current key as stored in the x/pubkey module:

GOLANG
	if batchNum == collections.DefaultSequenceStart {
		pubKey, err := h.pubKeyKeeper.GetValidatorKeyAtIndex(ctx, valOper, utils.SEDAKeyIndexSecp256k1)
		if err != nil {
			return err
		}
		expectedAddr, err = utils.PubKeyToEthAddress(pubKey)
		if err != nil {
			return err
		}
	} else {
               // ... skipped for brevity ...
        }

However, the condition used to check whether it is the first batch is incorrect. The numbering starts from collections.DefaultSequenceStart + 1 and only increments, meaning the condition batchNum == collections.DefaultSequenceStart will never be satisfied:

GOLANG
	if !errors.Is(err, types.ErrBatchingHasNotStarted) {
		return types.Batch{}, types.DataResultTreeEntries{}, nil, err
	}
	newBatchNum = collections.DefaultSequenceStart + 1

This causes the code to follow the default branch, where the validator key is not found, leading to the extension vote being rejected.

Internal Pre-conditions

Happens for the first batch only.

External Pre-conditions

None

Attack Path

See the explanation in the Root Cause section

Impact

Inability to sign the first batch.

PoC

No response

Mitigation

The check for the first batch must be if batchNum == collections.DefaultSequenceStart + 1

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/sedaprotocol/seda-chain/pull/516

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

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

Impact

Validators cannot sign the first batch, causing the vote extension to be rejected.

What the attacker needed

First batch only

The fix

The check for the first batch should be changed to compare against the default sequence start plus one.

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.

In a blockchain, validators sign batches of data. For the very first batch, there is no previous record to check the validator's key, so the code tries to use the current key. But the check for 'first batch' uses the wrong number, so it never triggers, and signatures are rejected.

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 zxriptor

View all

5 more disclosed reports, best first.

More from SEDA Protocol

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.