Skip to content
Business logic Audit finding Intermediate

Observer rewards are less than expected due to not properly accounting for negative rewards

The reward distribution function fails to subtract negative rewards from the total reward units, causing the total to be overstated. As a result, observers receive slightly fewer rewards than they should.

berndartmueller Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-04-zetachain-cross-chain-judging/issues/309

Found by

berndartmueller

Summary

Observers receive slightly fewer rewards than they should due to not correctly accounting for negative rewards in the BuildRewardsDistribution() function.

Root Cause

In BuildRewardsDistribution()#124, if an observer votes against the majority vote, it decrements the reward for that observer. It can even become negative, representing a penalty.

However, the totalRewardUnits is not decremented in this case. This means that the total rewards are calculated incorrectly, as it does not account for the negative rewards accumulated from previous ballots.

Go
094: // BuildRewardsDistribution builds the rewards distribution map for the ballot
095: // It returns the total rewards units which account for the observer block rewards
096: func (m Ballot) BuildRewardsDistribution(rewardsMap map[string]int64) int64 {
...   // [...]
117:
118: 	for _, address := range m.VoterList {
119: 		vote := m.Votes[m.GetVoterIndex(address)]
120: 		if vote == majorityVote {
121: 			rewardsMap[address]++
122: 			totalRewardUnits++
123: 		} else {
124: ❌		    rewardsMap[address]--
125: 		}
126: 	}

As a result, totalRewardsUnits will be larger than the actual votes that will be rewarded. Thus, the rewardPerUnit will be smaller than it should be. This means that observers will receive fewer rewards.

Internal Pre-conditions

  • Multiple matured ballots per block height
  • Some observers who cast the opposite vote to the majority vote, which results in a negative reward for them

External Pre-conditions

N/A

Attack Path

N/A

Impact

Observers receive slightly fewer rewards than they should.

PoC

Add the following test to the end of the file ballot_test.go:

Go
// This test is for the following scenario:
// Two ballots are voted on on the same block height. 4 voters/observers
// Ballot 1: Successful. All voters voted for success.
// Ballot 2: Successful. 3 voters voted for success, 1 voter voted for failure.
func Test_BuildRewardsDistribution_MultipleBallots(t *testing.T) {
	ballot1 := Ballot{
		VoterList: []string{"Observer1", "Observer2", "Observer3", "Observer4"},
		Votes: []VoteType{
			VoteType_SuccessObservation,
			VoteType_SuccessObservation,
			VoteType_SuccessObservation,
			VoteType_SuccessObservation,
		},
		BallotStatus: BallotStatus_BallotFinalized_SuccessObservation,
	}
	ballot2 := Ballot{
		VoterList: []string{"Observer1", "Observer2", "Observer3", "Observer4"},
		Votes: []VoteType{
			VoteType_SuccessObservation,
			VoteType_SuccessObservation,
			VoteType_SuccessObservation,
			VoteType_FailureObservation,
		},
		BallotStatus: BallotStatus_BallotFinalized_SuccessObservation,
	}

	var (
		rewardsDistributeMap = map[string]int64{}
		totalRewardsUnits    = int64(0)
	)

	totalRewardsUnits = ballot1.BuildRewardsDistribution(rewardsDistributeMap)
	totalRewardsUnits += ballot2.BuildRewardsDistribution(rewardsDistributeMap)

	require.Equal(t, rewardsDistributeMap, map[string]int64{
		"Observer1": 2,
		"Observer2": 2,
		"Observer3": 2,
		"Observer4": 0,
	})

	// sum of votes that will be rewarded
	sum := int64(0)
	for _, v := range rewardsDistributeMap {
		sum += v
	}

	require.Equal(t, sum, totalRewardsUnits) // @audit-info Fails. Expected 6, got 7
}

Run the test with the following command:

Bash
go test -timeout 30s -run ^Test_BuildRewardsDistribution_MultipleBallots$ github.com/zeta-chain/node/x/observer/types

It will fail with the following output:

Bash
Error:      	Not equal:
                expected: 6
                actual  : 7
Test:       	Test_BuildRewardsDistribution_MultipleBallots

The test shows that across those two ballots, 6 successful votes were cast, but the total rewards were calculated as 7. This leads to a smaller rewardPerUnit and thus a smaller reward for each observer.

Mitigation

Reconsider the logic in BuildRewardsDistribution() and ensure the total rewards are correctly calculated across multiple ballots.

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/zeta-chain/node/pull/3904

gjaldon

The total rewards units is now summed separately, and the issue is fixed.

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

Root cause

The totalRewardUnits variable is not decremented when an observer's reward is decremented for voting against the majority.

Impact

Observers receive slightly fewer rewards than they should.

What the attacker needed

Multiple matured ballots per block height; Some observers vote against the majority

How it was found

  1. Create two ballots with the same voters, where in the second ballot one voter votes against the majority.
  2. Call BuildRewardsDistribution for each ballot and sum the returned total reward units.
  3. Compare the sum of individual rewards to the total reward units; they do not match.

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 system, observers vote on events and get rewarded. If they vote against the majority, they lose some reward. The bug is that when calculating the total reward pool, the code forgets to subtract those penalties, so the pool is too big and each observer's share is smaller.

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 Cross-Chain

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.