Open sherlock-admin3 opened 4 months ago
1 comment(s) were left on this issue during the judging contest.
0xmystery commented:
coeffDiff
is always zero
The protocol team fixed this issue in the following PRs/commits: https://github.com/allora-network/allora-chain/pull/516
0x3b
High
coefficients math mistakenly calculates the coefficient diff with the same value
Summary
GetAllReputersOutput
, calculates each reputer scores and coefficients, however while doing that calculation it mistakenly calculated the coeff diff between the new and old coefficients using the same old value, meaning that the diff will be always 0.Vulnerability Detail
When calculating the coefficient
GetAllReputersOutput
has a customif
where iflistenedStakeFraction < minStakeFraction
it will do some math and increase the coefficients bycoefDiffTimesListenedDiffOverStakedFracDiff
.https://github.com/sherlock-audit/2024-06-allora/blob/main/allora-chain/x/emissions/module/rewards/rewards_internal.go#L563-L574
However that will never happen as before that when we calculate the
coeffDiff
between our new and old coefficients, we use 2 different arrays, but they are copied with the same parameters - our old coeff. Essentially calculating thecoeffDiff
between our old and old coefficient, resulting in 0 diff 100% of the time.It will make
coeffDiffTimesListenedDiff == 0
andcoefDiffTimesListenedDiffOverStakedFracDiff == 0
, making ourcoefficient == oldCoefficients
.This can be seen here where we calculate our diff: https://github.com/sherlock-audit/2024-06-allora/blob/main/allora-chain/x/emissions/module/rewards/rewards_internal.go#L548-L551
And in here where we set the
coefficients
andoldCoefficients
arrays:https://github.com/sherlock-audit/2024-06-allora/blob/main/allora-chain/x/emissions/module/rewards/rewards_internal.go#L448-L458
Impact
The custom math for adjusting coeff when
listenedStakeFraction < minStakeFraction
won't actually change anything, as it will set the coeff to it's old value. This is dangerous as our new coeff could have been way smaller or bigger than our old one. This change will impact reputer rewards, as they are calculated based on scores, and score math includes coefficients.Code Snippet
Tool used
Manual Review
Recommendation
Change the math to get the difference (preferably absolute -
.abs()
) between the new and old coefficients.