Repository: thrackle-io/float128
Pull request #29: Preaudit finding
Author: login: oscarsernarosero
Created: 2025-03-31T17:35:45Z | Merged: 2025-03-31T18:13:37Z



Diff:
diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml
index bbdfee4..e2f0b8e 100644
--- a/.github/workflows/coverage.yml
+++ b/.github/workflows/coverage.yml
@@ -51,7 +51,7 @@ jobs:
           sudo apt-get update
           sudo apt-get install -y python3-pip
           pip3 install -r requirements.txt
-          
+
       - name: Install Foundry
         run: |
           curl -sSL https://raw.githubusercontent.com/thrackle-io/foundry/refs/heads/master/foundryup/foundryup -o $HOME/foundryup
@@ -66,7 +66,7 @@ jobs:
       - name: Run tests with coverage option
         shell: bash
         run: |
-          forge coverage --ffi --report lcov --no-match-path "*invariant*" --fuzz-runs 1
+          forge coverage --ffi --report lcov --no-match-path "*invariant*" --fuzz-runs 1 --no-match-coverage test
 
       - name: Filter the coverage reports and reformat them
         shell: bash
diff --git a/README.md b/README.md
index 5d8177a..5bea4fd 100644
--- a/README.md
+++ b/README.md
@@ -62,7 +62,7 @@ The library's arithmetic operations' error have been calculated against results
 | Multiplication (mul)   | 0                |
 | Division (div/divL)    | 0                |
 | Square root (sqrt)     | 0                |
-| Natural Logarithm (ln) | 9                |
+| Natural Logarithm (ln) | 40               |
 
 ### Types
 
@@ -170,14 +170,16 @@ Here are the current Gas Results:
 
 | Function (and scenario)                | Min  | Average | Max  |
 | -------------------------------------- | ---- | ------- | ---- |
-| Addition                               | 596  | 1174    | 1778 |
-| Addition (matching exponents)          | 499  | 941     | 1556 |
-| Addition (subtraction via addition)    | 609  | 1331    | 1791 |
-| Subtraction                            | 577  | 1175    | 1769 |
-| Subtraction (matching exponents)       | 491  | 928     | 1567 |
-| Subtraction (addition via subtraction) | 604  | 1018    | 1784 |
-| Multiplication                         | 295  | 575     | 856  |
-| Multiplication (by zero)               | 295  | 576     | 858  |
-| Division                               | 296  | 590     | 886  |
-| Division (numerator is zero)           | 295  | 577     | 860  |
-| Square Root                            | 1247 | 1416    | 1588 |
+| Addition                               | 881  | 1237    | 1528 |
+| Addition (matching exponents)          | 739  | 1052    | 1457 |
+| Addition (subtraction via addition)    | 1354 | 1472    | 1528 |
+| Subtraction                            | 878  | 1230    | 1526 |
+| Subtraction (matching exponents)       | 736  | 1028    | 1392 |
+| Subtraction (addition via subtraction) | 878  | 962     | 994  |
+| Multiplication                         | 550  | 957     | 1124 |
+| Multiplication (by zero)               | 171  | 171     | 171  |
+| Division                               | 585  | 1125    | 1238 |
+| Division (numerator is zero)           | 189  | 189     | 189  |
+| Division Large                         | 1149 | 1194    | 1239 |
+| Division Large (numerator is zero)     | 190  | 190     | 190  |
+| Square Root                            | 1320 | 2178    | 3108 |
diff --git a/test/Float128Fuzz.t.sol b/test/Float128Fuzz.t.sol
index a490a5b..702809e 100644
--- a/test/Float128Fuzz.t.sol
+++ b/test/Float128Fuzz.t.sol
@@ -253,7 +253,7 @@ contract Float128FuzzTest is FloatCommon {
         console2.log("rMan", rMan);
         console2.log("rExp", rExp);
 
-        checkResults(retVal, rMan, rExp, pyMan, pyExp, 9);
+        checkResults(retVal, rMan, rExp, pyMan, pyExp, 40);
     }
 
     function testToPackedFloatFuzz(int256 man, int256 exp) public pure {
@@ -277,7 +277,7 @@ contract Float128FuzzTest is FloatCommon {
         while (comparison <= man) {
             comparison *= 10;
             iter += 1;
-            if (comparison == 1e77 && comparison < man) {
+            if (comparison == 1e77 && comparison <= man) {
                 iter += 1;
                 break;
             }
diff --git a/test/gasReport/GasReport.json b/test/gasReport/GasReport.json
index eb732fd..a62bede 100644
--- a/test/gasReport/GasReport.json
+++ b/test/gasReport/GasReport.json
@@ -1,90 +1,33 @@
 {
-  "Float": {
-    "add": {
-      "matchingexponents": {
-        "min": 499,
-        "avg": 941,
-        "max": 1556
-      },
-      "addsub": {
-        "min": 609,
-        "avg": 1331,
-        "max": 1791
-      },
-      "min": 596,
-      "avg": 1174,
-      "max": 1778
-    },
-    "sub": {
-      "matchingexponents": {
-        "min": 491,
-        "avg": 928,
-        "max": 1567
-      },
-      "subadd": {
-        "min": 604,
-        "avg": 1018,
-        "max": 1784
-      },
-      "min": 577,
-      "avg": 1175,
-      "max": 1769
-    },
-    "mul": {
-      "mulbyzero": {
-        "min": 295,
-        "avg": 576,
-        "max": 858
-      },
-      "min": 295,
-      "avg": 575,
-      "max": 856
-    },
-    "div": {
-      "numeratorzero": {
-        "min": 295,
-        "avg": 577,
-        "max": 860
-      },
-      "min": 296,
-      "avg": 590,
-      "max": 886
-    },
-    "sqrt": {
-      "min": 1247,
-      "avg": 1416,
-      "max": 1588
-    }
-  },
   "Packed": {
     "add": {
       "matchingexponents": {
         "min": 739,
-        "avg": 1052,
+        "avg": 1060,
         "max": 1457
       },
       "addsub": {
         "min": 1354,
-        "avg": 1472,
+        "avg": 1475,
         "max": 1528
       },
       "min": 881,
-      "avg": 1237,
+      "avg": 1227,
       "max": 1528
     },
     "sub": {
       "matchingexponents": {
         "min": 736,
-        "avg": 1028,
+        "avg": 1023,
         "max": 1392
       },
       "subadd": {
         "min": 878,
-        "avg": 962,
+        "avg": 960,
         "max": 994
       },
       "min": 878,
-      "avg": 1230,
+      "avg": 1241,
       "max": 1526
     },
     "mul": {
@@ -94,7 +37,7 @@
         "max": 171
       },
       "min": 550,
-      "avg": 957,
+      "avg": 954,
       "max": 1124
     },
     "div": {
@@ -104,12 +47,22 @@
         "max": 189
       },
       "min": 585,
-      "avg": 1125,
+      "avg": 1128,
       "max": 1238
     },
+    "divL": {
+      "numeratorzero": {
+        "min": 190,
+        "avg": 190,
+        "max": 190
+      },
+      "min": 1149,
+      "avg": 1194,
+      "max": 1239
+    },
     "sqrt": {
       "min": 1320,
-      "avg": 2178,
+      "avg": 2156,
       "max": 3108
     }
   },
diff --git a/test/gasReport/GasReport.t.sol b/test/gasReport/GasReport.t.sol
index 2f7be9f..1221676 100644
--- a/test/gasReport/GasReport.t.sol
+++ b/test/gasReport/GasReport.t.sol
@@ -251,6 +251,32 @@ contract GasReport is Test, GasHelpers, FloatUtils {
         _writeJson(".Packed.div.", min, avg / runs, max);
     }
 
+    function test_gasUsedPacked_divL() public {
+        vm.sleep(delay * 19);
+        _primer();
+        _resetGasUsed();
+
+        for (uint i = 0; i < runs; ++i) {
+            (int aMan, int aExp, int bMan, int bExp) = setBounds(vm.randomInt(), vm.randomInt(), vm.randomInt(), vm.randomInt());
+            // This is simply ensuring no division by zero revert
+            if (bMan == 0) {
+                bMan = 1;
+            }
+            packedFloat a = Float128.toPackedFloat(aMan, aExp);
+            packedFloat b = Float128.toPackedFloat(bMan, bExp);
+
+            startMeasuringGas("Packed - Div");
+            Float128.divL(a, b);
+
+            gasUsed = stopMeasuringGas();
+            if (gasUsed > max) max = gasUsed;
+            if (gasUsed < min) min = gasUsed;
+            avg += gasUsed;
+        }
+
+        _writeJson(".Packed.divL.", min, avg / runs, max);
+    }
+
     function test_gasUsedPacked_div_numerator_zero() public {
         vm.sleep(delay * 20);
         _primer();
@@ -274,6 +300,29 @@ contract GasReport is Test, GasHelpers, FloatUtils {
         _writeJson(".Packed.div.numeratorzero.", min, avg / runs, max);
     }
 
+    function test_gasUsedPacked_divL_numerator_zero() public {
+        vm.sleep(delay * 20);
+        _primer();
+        _resetGasUsed();
+
+        packedFloat a = Float128.toPackedFloat(0, -8192);
+
+        for (uint i = 0; i < runs; ++i) {
+            (, , int bMan, int bExp) = setBounds(vm.randomInt(), vm.randomInt(), vm.randomInt(), vm.randomInt());
+            packedFloat b = Float128.toPackedFloat(bMan, bExp);
+
+            startMeasuringGas("Packed - Div - Numerator Zero");
+            Float128.divL(a, b);
+
+            gasUsed = stopMeasuringGas();
+            if (gasUsed > max) max = gasUsed;
+            if (gasUsed < min) min = gasUsed;
+            avg += gasUsed;
+        }
+
+        _writeJson(".Packed.divL.numeratorzero.", min, avg / runs, max);
+    }
+
     function test_gasUsedPacked_sqrt() public {
         vm.sleep(delay * 21);
         _primer();


Reviews:
user: login: Palmerg4
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-31T17:41:41Z
user: login: Palmerg4
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-31T17:42:08Z
user: login: Palmerg4
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-31T17:43:03Z
user: login: Palmerg4
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-03-31T17:48:22Z

Review comments:
diff_hunk: @@ -170,14 +170,16 @@ Here are the current Gas Results:
 
 | Function (and scenario)                | Min  | Average | Max  |
 | -------------------------------------- | ---- | ------- | ---- |
-| Addition                               | 596  | 1174    | 1778 |
-| Addition (matching exponents)          | 499  | 941     | 1556 |
-| Addition (subtraction via addition)    | 609  | 1331    | 1791 |
-| Subtraction                            | 577  | 1175    | 1769 |
-| Subtraction (matching exponents)       | 491  | 928     | 1567 |
-| Subtraction (addition via subtraction) | 604  | 1018    | 1784 |
-| Multiplication                         | 295  | 575     | 856  |
-| Multiplication (by zero)               | 295  | 576     | 858  |
-| Division                               | 296  | 590     | 886  |
-| Division (numerator is zero)           | 295  | 577     | 860  |
-| Square Root                            | 1247 | 1416    | 1588 |
+| Addition                               | 881  | 1237    | 1528 |
+| Addition (matching exponents)          | 739  | 1052    | 1457 |
+| Addition (subtraction via addition)    | 1354 | 1472    | 1528 |
+| Subtraction                            | 878  | 1230    | 1526 |
+| Subtraction (matching exponents)       | 736  | 1028    | 1392 |
+| Subtraction (addition via subtraction) | 878  | 962     | 994  |
+| Multiplication                         | 550  | 957     | 1124 |
+| Multiplication (by zero)               | 171  | 171     | 171  |
+| Division                               | 585  | 1125    | 1238 |
+| Division (numerator is zero)           | 189  | 189     | 189  |
+| Division Large                         | 190  | 190     | 190  |
path: README.md
user: login: Palmerg4
body: Not sure what this field is
created_at: 2025-03-31T17:41:41Z
author_association: CONTRIBUTOR
diff_hunk: @@ -170,14 +170,16 @@ Here are the current Gas Results:
 
 | Function (and scenario)                | Min  | Average | Max  |
 | -------------------------------------- | ---- | ------- | ---- |
-| Addition                               | 596  | 1174    | 1778 |
-| Addition (matching exponents)          | 499  | 941     | 1556 |
-| Addition (subtraction via addition)    | 609  | 1331    | 1791 |
-| Subtraction                            | 577  | 1175    | 1769 |
-| Subtraction (matching exponents)       | 491  | 928     | 1567 |
-| Subtraction (addition via subtraction) | 604  | 1018    | 1784 |
-| Multiplication                         | 295  | 575     | 856  |
-| Multiplication (by zero)               | 295  | 576     | 858  |
-| Division                               | 296  | 590     | 886  |
-| Division (numerator is zero)           | 295  | 577     | 860  |
-| Square Root                            | 1247 | 1416    | 1588 |
+| Addition                               | 881  | 1237    | 1528 |
+| Addition (matching exponents)          | 739  | 1052    | 1457 |
+| Addition (subtraction via addition)    | 1354 | 1472    | 1528 |
+| Subtraction                            | 878  | 1230    | 1526 |
+| Subtraction (matching exponents)       | 736  | 1028    | 1392 |
+| Subtraction (addition via subtraction) | 878  | 962     | 994  |
+| Multiplication                         | 550  | 957     | 1124 |
+| Multiplication (by zero)               | 171  | 171     | 171  |
+| Division                               | 585  | 1125    | 1238 |
+| Division (numerator is zero)           | 189  | 189     | 189  |
+| Division Large                         | 190  | 190     | 190  |
+| Division Large (numerator is zero)     | 1149 | 1194    | 1239 |
+| Square Root                            | 1380 | 2178    | 3180 |
path: README.md
user: login: Palmerg4
body: max should be 3108, not 3180
created_at: 2025-03-31T17:42:08Z
author_association: CONTRIBUTOR
diff_hunk: @@ -170,14 +170,16 @@ Here are the current Gas Results:
 
 | Function (and scenario)                | Min  | Average | Max  |
 | -------------------------------------- | ---- | ------- | ---- |
-| Addition                               | 596  | 1174    | 1778 |
-| Addition (matching exponents)          | 499  | 941     | 1556 |
-| Addition (subtraction via addition)    | 609  | 1331    | 1791 |
-| Subtraction                            | 577  | 1175    | 1769 |
-| Subtraction (matching exponents)       | 491  | 928     | 1567 |
-| Subtraction (addition via subtraction) | 604  | 1018    | 1784 |
-| Multiplication                         | 295  | 575     | 856  |
-| Multiplication (by zero)               | 295  | 576     | 858  |
-| Division                               | 296  | 590     | 886  |
-| Division (numerator is zero)           | 295  | 577     | 860  |
-| Square Root                            | 1247 | 1416    | 1588 |
+| Addition                               | 881  | 1237    | 1528 |
+| Addition (matching exponents)          | 739  | 1052    | 1457 |
+| Addition (subtraction via addition)    | 1354 | 1472    | 1528 |
+| Subtraction                            | 878  | 1230    | 1526 |
+| Subtraction (matching exponents)       | 736  | 1028    | 1392 |
+| Subtraction (addition via subtraction) | 878  | 962     | 994  |
+| Multiplication                         | 550  | 957     | 1124 |
+| Multiplication (by zero)               | 171  | 171     | 171  |
+| Division                               | 585  | 1125    | 1238 |
+| Division (numerator is zero)           | 189  | 189     | 189  |
+| Division Large                         | 190  | 190     | 190  |
path: README.md
user: login: Palmerg4
body: nvm I see it. The Division Large fields are switched with the Division Large (numerator is zero) fields
created_at: 2025-03-31T17:43:03Z
author_association: CONTRIBUTOR

PR comments:
user: login: github-actions[bot]
created_at: 2025-03-31T17:38:28Z
body: <details><summary>Slither report</summary>

**THIS CHECKLIST IS NOT COMPLETE**. Use `--show-ignored-findings` to show all the results.
Summary
</details>
author_association: NONE
user: login: github-actions[bot]
created_at: 2025-03-31T17:41:14Z
body: ### [LCOV](https://github.com/marketplace/actions/report-lcov) of commit [<code>45950c4</code>](29/commits/45950c46ecae4de6c645f638c8740272a2a9290d) during [Code coverage evaluation #88](../actions/runs/14177742486)
<pre>Summary coverage rate:
  lines......: 76.2% (694 of 911 lines)
  functions..: 81.0% (17 of 21 functions)
  branches...: 64.6% (155 of 240 branches)

Files changed coverage rate: n/a</pre>
author_association: NONE
user: login: github-actions[bot]
created_at: 2025-03-31T17:43:42Z
body: ### [LCOV](https://github.com/marketplace/actions/report-lcov) of commit [<code>c8c54c2</code>](29/commits/c8c54c2337dae4c3de66a277d791e8c9f3309343) during [Code coverage evaluation #89](../actions/runs/14177759846)
<pre>Summary coverage rate:
  lines......: 76.2% (694 of 911 lines)
  functions..: 81.0% (17 of 21 functions)
  branches...: 64.6% (155 of 240 branches)

Files changed coverage rate: n/a</pre>
author_association: NONE
user: login: github-actions[bot]
created_at: 2025-03-31T17:48:42Z
body: ### [LCOV](https://github.com/marketplace/actions/report-lcov) of commit [<code>5702ea4</code>](29/commits/5702ea439dbea9876f089a4f6910d3fe41dc5830) during [Code coverage evaluation #90](../actions/runs/14177931659)
<pre>Summary coverage rate:
  lines......: 76.2% (694 of 911 lines)
  functions..: 81.0% (17 of 21 functions)
  branches...: 64.6% (155 of 240 branches)

Files changed coverage rate: n/a</pre>
author_association: NONE
user: login: github-actions[bot]
created_at: 2025-03-31T18:04:06Z
body: ### [LCOV](https://github.com/marketplace/actions/report-lcov) of commit [<code>e0ca553</code>](29/commits/e0ca553297ac64de9a8ee4e627c545336e2a16ef) during [Code coverage evaluation #91](../actions/runs/14178169111)
<pre>Summary coverage rate:
  lines......: 76.2% (694 of 911 lines)
  functions..: 81.0% (17 of 21 functions)
  branches...: 64.6% (155 of 240 branches)

Files changed coverage rate: n/a</pre>
author_association: NONE
user: login: github-actions[bot]
created_at: 2025-03-31T18:09:49Z
body: ### [LCOV](https://github.com/marketplace/actions/report-lcov) of commit [<code>c9f0a2e</code>](29/commits/c9f0a2eab6dd0939c1d2ef7e4dabeb2aa44b1cfa) during [Code coverage evaluation #92](../actions/runs/14178304614)
<pre>Summary coverage rate:
  lines......: 76.2% (694 of 911 lines)
  functions..: 81.0% (17 of 21 functions)
  branches...: 64.6% (155 of 240 branches)

Files changed coverage rate: n/a</pre>
author_association: NONE