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
- Open
x/oracle/types/ballot.go
- Look at the
NewClaim function
- Notice
Weight: power instead of Weight: weight
- 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.
Bug Description
In
NewClaim(), theWeightfield is incorrectly set topowerinstead ofweight. The function takes bothpowerandweightas separate parameters, but the struct initialization usespowerfor bothPowerandWeight.File:
x/oracle/types/ballot.go, around line 25The
weightparameter is accepted but never used — it's shadowed bypowerbeing assigned to both fields. This means whoever callsNewClaimwith different values for power and weight will get wrong claim data.Steps to Reproduce
x/oracle/types/ballot.goNewClaimfunctionWeight: powerinstead ofWeight: weightpower=100andweight=50would end up withWeight=100instead ofWeight=50Expected Behavior
Actual Behavior
Weightis set topower, making theweightparameter completely unused. The compiler doesn't catch this because both areint64.Impact
Medium - Currently the main caller in
tally.gocallsNewClaim(power, 0, ...)and then modifiesclaim.Weightdirectly via+=, so it mostly works in practice. But the function signature is misleading and anyone callingNewClaimwith a non-zero weight value would get incorrect results. This is a pretty clear copy-paste bug.Fix is available in PR #288.