Skip to content
Request an audit

‹ All findings

Multiplication after division in StableEarnerRateModel leads to loss of precision

Low/InfoM^0 Minter Gateway·Three Sigma · Stablecoin framework · 8th January, 2024Codebase3S-M^0-L01

Description

In the StableEarnerRateModel.getSafeEarnerRate function, there's a log calculation detailed in a comment:

solidity
// 6. ln(1 + (totalActive * (delta_minterIndex - 1) / totalEarning)) * SECONDS_PER_YEAR / dt = earnerRate

The code implementation of the log argument calculation follows the comment, but using fixed point arithmetic with 12 decimals. The problem is that a division by 1e12 is immediately followed by a 1e12 multiplication: 1e12 + ((((uint256(totalActiveOwedM_) * (deltaMinterIndex_ - 1e12)) / 1e12) * 1e12) / totalEarningSupply_) That division combined with the multiplication should cancel out in real world math.

But because of integer division, this sets the first 12 decimals to zero.

Recommendation

Remove the division and multiplication by 1e12.

Status

Addressed in #cac3c24.