averageMagnitude
math issue allows early Depositors to decides the max duration against everyone else in a disproportionate way
#56
Labels
bug
Something isn't working
disagree with severity
Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments)
downgraded by judge
Judge downgraded the risk level of this issue
grade-a
QA (Quality Assurance)
Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
sponsor acknowledged
Technically the issue is correct, but we're not going to resolve it for XYZ reasons
Lines of code
https://github.com/Tapioca-DAO/tap-token/blob/050e666142e61018dbfcba64d295f9c458c69700/contracts/governance/twTAP.sol#L323
Vulnerability details
Impact
As I flagged on the Spearbit report
averageMagnitude
is not a real averagehttps://github.com/Tapioca-DAO/tap-token/blob/050e666142e61018dbfcba64d295f9c458c69700/contracts/governance/twTAP.sol#L323
The logic for moving the pool.cumulative is as follows:
https://github.com/Tapioca-DAO/tap-token/blob/050e666142e61018dbfcba64d295f9c458c69700/contracts/governance/twTAP.sol#L328-L337
Which uses this distorted average
This means that as more lockers lock their tokens, the average will be harder to move.
More specifically, the first 100 or so lockers have a disproportionally high impact on the max duration of locks
To the point where, the first 100 depositors will determine the max and min duration practically forever
That's because the math is not moving the cumulative by the delta against the averageMagnitude, but by the absolute value of averageMagnitude
When we have
!divergenceForce
that number is extremely smallWhen we have
divergenceForce
the number is big, but because we are dividing the Previous Average by the total number of lockers, then the growth ofaverageMagnitude
is tamperedThis allows the first few depositors or a malicious deposit to sabotage the lock duration and force it to either be:
Fundamental issues with the formula
The formula is snappy at first and then becomes very slow to change
Once 100 lockers are there, it's basically impossible to move it
This means that
When we have 10 lockers we can move it a bit
In conclusion
The formula is extremely elastic initially
And it reaches a point where changes become exponentially more expensive too fast
I believe that once a value is set by the first 10 or so people
Everyone else will be forced into that and the formula will no longer be adaptable
Since the average is not changed on
releaseTap
(dangerous change imo), this means that the first 10 or so depositors can choose for everyone else, in perpetuity as the next avg change is too miniscule to have any drastic impactMitigation
It's worth determining whether the logic for shifting max lock duration is necessary, or if it's better to opt for a simpler max and then using the logic simply to determine the multiplier.
Overall, the amount of multiplications makes the math a lot more complicated without a clear benefit
I would recommend:
Assessed type
Math
The text was updated successfully, but these errors were encountered: