Skip to content

NewClaim() assigns power to Weight field instead of weight parameter #293

@giwaov

Description

@giwaov

Bug Description

In NewClaim(), the Weight field is incorrectly set to power instead of weight. The function takes both power and weight as separate parameters, but the struct initialization uses power for both Power and Weight.

File: x/oracle/types/ballot.go, around line 25

func NewClaim(power, weight int64, winCount int64, voterAddress sdk.ValAddress) Claim {
    return Claim{
        Power:       power,
        Weight:      power,   // BUG: should be 'weight', not 'power'
        WinCount:    winCount,
        Recipient:   voterAddress,
    }
}

The weight parameter is accepted but never used — it's shadowed by power being assigned to both fields. This means whoever calls NewClaim with different values for power and weight will get wrong claim data.

Steps to Reproduce

  1. Open x/oracle/types/ballot.go
  2. Look at the NewClaim function
  3. Notice Weight: power instead of Weight: weight
  4. Any caller passing power=100 and weight=50 would end up with Weight=100 instead of Weight=50

Expected Behavior

func NewClaim(power, weight int64, winCount int64, voterAddress sdk.ValAddress) Claim {
    return Claim{
        Power:       power,
        Weight:      weight,    // use the correct parameter
        WinCount:    winCount,
        Recipient:   voterAddress,
    }
}

Actual Behavior

Weight is set to power, making the weight parameter completely unused. The compiler doesn't catch this because both are int64.

Impact

Medium - Currently the main caller in tally.go calls NewClaim(power, 0, ...) and then modifies claim.Weight directly via +=, so it mostly works in practice. But the function signature is misleading and anyone calling NewClaim with a non-zero weight value would get incorrect results. This is a pretty clear copy-paste bug.

Fix is available in PR #288.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions