소스 검색

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

Hadrien Croubois 3 년 전
부모
커밋
affe2456ea
2개의 변경된 파일3개의 추가작업 그리고 3개의 파일을 삭제
  1. 2 2
      contracts/utils/Checkpoints.sol
  2. 1 1
      scripts/generate/templates/Checkpoints.js

+ 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);