Submitted by bronze_pickaxe, also found by VAD37, ether_sky, and Krace
updateTranscoderWtihFees can underflow because MathUtils is used instead of PreciseMathUtils.
According to LIP-92 the initial treasuryRewardCutRate will be set to 10%.
treasuryRewardCutRate is set with the setTreasuryRewardCutRate()function, which calls the internal function _setTreasuryRewardCutRate().
In this function the value will be checked if its a valid PreciseMathUtils percentage (<100% specified with 27-digits precision):
However, in updateTranscoderWithFees, to calculate treasuryRewards, MathUtils is used instead of PreciseMathUtils.
MathUtils uses a PREC_DIVISOR of 1000000 instead of 10 ** 27 from the PreciseMathUtils:
This leads to treasuryRewards value being bigger than expected. Here is a gist of the POC. Running the POC it shows that the current usage of MathUtils when calculating treasuryRewards will always cause an underflow in the next line of code.
updateTranscoderWithFees is called every time a winning ticket is redeemed. Whenever the transcoder has skipped the previous round reward call, this function has to re-calculate the rewards, as documented in LIP-92. This re-calculation will always fail due to the underflow shown above.
This will lead to accounting errors, unexpected behaviours and can cause a loss of winning tickets.
Firstly, the accounting errors and unexpected behaviours: these are all the storage values getting updated in updateTranscoderWithFees:
During currentRound() it wont be possible to update the Transcoder storage or earningsPool.data storage because of the underflow that will happen because currentRound() - 1 reward call has been skipped by the transcoder.
During currentRound() + 1 it will be possible to call updateTranscoderWithFees, however, L382 will only update the prevEarningsPool, which in this case will be currentRound(), not currentRound - 1. Therefor, the EarningsPool.data.cumulativeRewardFactor wont be updated for currentRound() - 1.
Lastly, the validity of a ticket is two rounds as per the specs. This means that a transcoder that receives a winning ticket in currentRound() - 1 should be able to redeem it in currentRound() - 1 and currentRound(). However, a transcoder that receives a winning ticket in currentRound() - 1 wont be able to redeem it in currentRound() because of the underflow that happens while redeeming a winning ticket in currentRound(). The transcoder wont be able to redeem it after currentRound + 1..N because the ticket will be expired.
Use PreciseMathLib instead of MathLib:
Library
victorges (Livepeer) commented:
victorges (Livepeer) mitigated:
