@@ -28,7 +28,8 @@ library Checkpoints {
2828
2929 /**
3030 * @dev Returns the value at a given block number. If a checkpoint is not available at that block, the closest one
31- * before it is returned, or zero otherwise.
31+ * before it is returned, or zero otherwise. Because the number returned corresponds to that at the end of the
32+ * block, the requested block number must be in the past, excluding the current block.
3233 */
3334 function getAtBlock (History storage self , uint256 blockNumber ) internal view returns (uint256 ) {
3435 require (blockNumber < block .number , "Checkpoints: block not yet mined " );
@@ -143,8 +144,8 @@ library Checkpoints {
143144 // Copying to memory is important here.
144145 Checkpoint memory last = _unsafeAccess (self, pos - 1 );
145146
146- // Checkpoints keys must be increasing .
147- require (last._blockNumber <= key, "Checkpoint: invalid key " );
147+ // Checkpoint keys must be non-decreasing .
148+ require (last._blockNumber <= key, "Checkpoint: decreasing keys " );
148149
149150 // Update or push new checkpoint
150151 if (last._blockNumber == key) {
@@ -205,6 +206,9 @@ library Checkpoints {
205206 return high;
206207 }
207208
209+ /**
210+ * @dev Access an element of the array without performing bounds check. The position is assumed to be within bounds.
211+ */
208212 function _unsafeAccess (Checkpoint[] storage self , uint256 pos ) private pure returns (Checkpoint storage result ) {
209213 assembly {
210214 mstore (0 , self.slot)
@@ -304,8 +308,8 @@ library Checkpoints {
304308 // Copying to memory is important here.
305309 Checkpoint224 memory last = _unsafeAccess (self, pos - 1 );
306310
307- // Checkpoints keys must be increasing .
308- require (last._key <= key, "Checkpoint: invalid key " );
311+ // Checkpoint keys must be non-decreasing .
312+ require (last._key <= key, "Checkpoint: decreasing keys " );
309313
310314 // Update or push new checkpoint
311315 if (last._key == key) {
@@ -366,6 +370,9 @@ library Checkpoints {
366370 return high;
367371 }
368372
373+ /**
374+ * @dev Access an element of the array without performing bounds check. The position is assumed to be within bounds.
375+ */
369376 function _unsafeAccess (Checkpoint224[] storage self , uint256 pos )
370377 private
371378 pure
@@ -469,8 +476,8 @@ library Checkpoints {
469476 // Copying to memory is important here.
470477 Checkpoint160 memory last = _unsafeAccess (self, pos - 1 );
471478
472- // Checkpoints keys must be increasing .
473- require (last._key <= key, "Checkpoint: invalid key " );
479+ // Checkpoint keys must be non-decreasing .
480+ require (last._key <= key, "Checkpoint: decreasing keys " );
474481
475482 // Update or push new checkpoint
476483 if (last._key == key) {
@@ -531,6 +538,9 @@ library Checkpoints {
531538 return high;
532539 }
533540
541+ /**
542+ * @dev Access an element of the array without performing bounds check. The position is assumed to be within bounds.
543+ */
534544 function _unsafeAccess (Checkpoint160[] storage self , uint256 pos )
535545 private
536546 pure
0 commit comments