This repository has been archived by the owner on Jan 19, 2025. It is now read-only.
0x3b - coefficients math mistakenly calculates the coefficient diff with the same value #93
Labels
Has Duplicates
A valid issue with 1+ other issues describing the same vulnerability
Medium
A Medium severity issue.
Reward
A payout will be made for this issue
Sponsor Confirmed
The sponsor acknowledged this issue is valid
Will Fix
The sponsor confirmed this issue will be fixed
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.The text was updated successfully, but these errors were encountered: