Submitted by montecristo
Library has mantissa size auto-scaling rule to achieve the following:
However, there is a discrepancy between auto-scaling rule of encoding (i.e. toPackedFloat) and other calculations (add, sub, mul, div).
packedFloat encoding has the following rule:
However, all arithmetic operations enforce the following auto-scaling rule:
For example, check how auto-scaling rule is implemented in mul function:
File: 2025-04-forte/src/Float128.sol
The implementation just checks rExp is greater than maxExp and decide mantissa L flag on rExp > maxExp condition. (This condition is equal to -18 < exp + digitsMantissa - 38 in rule #3).
So clearly, arithmetic operations use only #3 of auto-scaling rule for encoding, while encoding also has additional #1 and #2 rules.
This means the following:
This can lead to the following problems:
Enforce the same auto-scaling rule between encoding and calculation operations. i.e.:
NOTE: Basically rule #1 and rule #3.1 are equivalent. So the fix just needs to handle the case of rule #2.
Scenario:
Put the following content in test/poc.t.sol and run forge test --match-test testM03POC -vvv:
Console output:
oscarserna (Forte) disputed
For this audit, 7 reports were submitted by wardens detailing low risk and non-critical issues. The report highlighted below by eternal1328 received the top score from the judge.
The following wardens also submitted reports: 0x23r0, CodexBugmenot, K42, montecristo, PabloPerez, and unique.
