Open code423n4 opened 1 year ago
Nice find, but I think this would lead to a loss of only 31,536,000 wei in the example above, which is only 3.1e-11 wad and not that significant
No, rounding trims only up to one. Meaning loss per second can be maximum 1 wei (the trimmed variable is perSecondReward
which holds the dimension of wei), therefore the total loss is maximum 31e6 wei per year.
mattt21 marked the issue as sponsor confirmed
As @0xA5DF points out, the loss of precision is of 1 * some timestamp
so is < 31e6
. However, as the contract uses an ERC20 which may have any decimal and value, Med severity seems appropriate.
Picodes marked the issue as satisfactory
However, as the contract uses an ERC20 which may have any decimal and value
I think this issue impacts only the reward token, which is dMute that has 18 decimals.
Agree with @0xA5DF. In the case of the 18 decimal token the loss is only a dust amount
You have a point. So considering the amount cannot be significant, I'll downgrade to Low. Thanks for flagging.
Picodes changed the severity to QA (Quality Assurance)
I agree with the decision.
Lines of code
https://github.com/code-423n4/2023-03-mute/blob/4d8b13add2907b17ac14627cfa04e0c3cc9a2bed/contracts/amplifier/MuteAmplifier.sol#L88-L121
Vulnerability details
Impact
Detailed description of the impact of this finding. There is a division-before-multiplication precision loss issue for update().
Proof of Concept
Provide direct links to all referenced code in GitHub. Add screenshots, logs, or any other relevant proof that illustrates the concept.
The update() function has a division-before-multiplication precision loss issue.
First, the calculation of
perSecondReward
uses a division:Then, the calculation of
value
uses a multiplication.Suppose that the total reward time is one year = 31,536,000 seconds, then the precision loss could be up to 31,536,000, which is significant for
perSecondReward
.Tools Used
VScode
Recommended Mitigation Steps
Use the multiplication-after-division pattern
Mitigation: use multiplication-before-division instead