Submitted by erebus
When calculating the amount of CANTO per share in update_market, dividing by 1e18 in cantoReward and multiplying by the same value in accCantoPerShare rounds down the final value, making the amount of rewards users will receive be less than expected.
Its well known that Solidity rounds down when doing an integer division, and because of that, it is always recommended to multiply before dividing to avoid that precision loss. However, if we go to:
LendingLedger, function update_market
and we expand the maths behind accCantoPerShare and cantoReward:
like follows:
$(cantoReward \* 1e18) \ / \ marketSupply$
$(((blockDelta \* cantoPerBlock\[epoch] \* gaugeController.gauge_relative_weight_write(\_market, epoch)) \ / \ 1e18) \ \* \ 1e18) \ / \ marketSupply$
$((stuff \ / \ 1e18) \ \* \ 1e18) \ / \ marketSupply$
we see there is a hidden division before a multiplication that is rounding down the whole expression. This is bad as the precision loss can be significant, which leads to the given market having less rewards to offer to its users. Run the next test inside a foundry project to see such a divergence in the precision if we multiply before dividing:
Some examples:
Change the update_market function to:
OpenCoreCH (Canto) confirmed and commented:
Alex the Entreprenerd (Judge) commented:
OpenCoreCH (Canto) commented
For this audit, 5 reports were submitted by wardens detailing low risk and non-critical issues. The report highlighted below by rvierdiiev received the top score from the judge.
The following wardens also submitted reports: erebus, bin2chen, Stormy, and xuwinnie.
