The formula for forecast normalization differs from the one in the whitepaper
Source: https://github.com/sherlock-audit/2024-06-allora-judging/issues/16
Found by
volodya
Summary
The formula for forecast normalization differs from the one in the whitepaper.
Vulnerability Detail
According to docs
We ask that auditors look for both typical security vulnerabilities, but also departures of the codebase from the intentions defined in the whitepaper. This includes but is not limited to functions not correctly implemented or tied together as defined in the whitepaper. This requires an understanding of the math of the whitepaper, which we urge auditors to develop. Here is the code for formula below
medianRegrets, err := alloraMath.Median(regrets)
if err != nil {
return RegretInformedWeights{}, errorsmod.Wrapf(err, "Error calculating median of regrets")
}
medianTimesFTolerance, err := medianRegrets.Mul(p.Tolerance)
if err != nil {
return RegretInformedWeights{}, errorsmod.Wrapf(err, "Error calculating median times tolerance")
}
// Add tolerance to standard deviation
stdDevRegretsPlusMedianTimesFTolerance, err := stdDevRegrets.Abs().Add(medianTimesFTolerance)
if err != nil {
return RegretInformedWeights{}, errorsmod.Wrapf(err, "Error adding tolerance to standard deviation of regrets")
}
stdDevRegretsPlusMedianTimesFTolerancePlusEpsilon, err := stdDevRegretsPlusMedianTimesFTolerance.Add(p.Epsilon)
if err != nil {
return RegretInformedWeights{}, errorsmod.Wrapf(err, "Error adding epsilon to standard deviation of regrets")
}
// Normalize the regrets and find the max normalized regret among them
normalizedInfererRegrets := make(map[Worker]Regret)
maxRegret := alloraMath.ZeroDec()
maxRegretInitialized := false
for address, worker := range p.InfererRegrets {
regretFrac, err := worker.regret.Quo(stdDevRegretsPlusMedianTimesFTolerancePlusEpsilon)
if err != nil {
return RegretInformedWeights{}, errorsmod.Wrapf(err, "Error calculating regret fraction")
}
normalizedInfererRegrets[address] = regretFrac
if !maxRegretInitialized {
maxRegretInitialized = true
maxRegret = regretFrac
} else if regretFrac.Gt(maxRegret) {
maxRegret = regretFrac
}
}
synth_palette_weight.go#L33 Which results in
\hat{R}_{ijk} = \frac{R_{ijk}}{\sigma_j(R_{ijk}) + \mu(R_{ijk}) \cdot \text{Tolerance} + \epsilon}
while in whitepaper its this one, equation (8)
\hat{R}_{ijk} = \frac{R_{ijk}}{\sigma_j(R_{ijk}) + \epsilon}
Impact
The incorrect base formula for calculating weights based on regrets
Code Snippet
Tool used
Manual Review
Recommendation
Implement from whitepaper or change whitepaper to one in code
Discussion
sherlock-admin2
1 comment(s) were left on this issue during the judging contest.
0xmystery commented:
Whitepaper differs from code
relyt29
quoting @guilherme-brandao who is not on this repo
This addition of the median was something suggested by the research team but they changed their minds. This addition was reverted in this PR: https://github.com/allora-network/allora-chain/pull/395
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/allora-network/allora-chain/pull/395
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A medium-severity business logic bug in Allora. Sherlock made it public on 10 August 2024. Found in the 454 audit contest (finding M-4).
About Business logic
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
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.