Prechádzať zdrojové kódy

Search the whole checkpoint trace if offset overflows during initial exponential search. (#3662)

Hadrien Croubois 3 rokov pred
rodič
commit
affe2456ea

+ 2 - 2
contracts/utils/Checkpoints.sol

@@ -237,7 +237,7 @@ library Checkpoints {
             offset <<= 1;
         }
 
-        uint256 low = offset < length ? length - offset : 0;
+        uint256 low = 0 < offset && offset < length ? length - offset : 0;
         uint256 high = length - (offset >> 1);
         uint256 pos = _upperBinaryLookup(self._checkpoints, key, low, high);
 
@@ -392,7 +392,7 @@ library Checkpoints {
             offset <<= 1;
         }
 
-        uint256 low = offset < length ? length - offset : 0;
+        uint256 low = 0 < offset && offset < length ? length - offset : 0;
         uint256 high = length - (offset >> 1);
         uint256 pos = _upperBinaryLookup(self._checkpoints, key, low, high);
 

+ 1 - 1
scripts/generate/templates/Checkpoints.js

@@ -83,7 +83,7 @@ function upperLookupRecent(${opts.historyTypeName} storage self, ${opts.keyTypeN
         offset <<= 1;
     }
 
-    uint256 low = offset < length ? length - offset : 0;
+    uint256 low = 0 < offset && offset < length ? length - offset : 0;
     uint256 high = length - (offset >> 1);
     uint256 pos = _upperBinaryLookup(self.${opts.checkpointFieldName}, key, low, high);