Release v5.2 audit fixes (#5330)
Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com> Co-authored-by: Sam Bugs <101145325+0xsambugs@users.noreply.github.com> Co-authored-by: Ernesto García <ernestognw@gmail.com> Co-authored-by: Arr00 <13561405+arr00@users.noreply.github.com> Co-authored-by: wizard <112275929+famouswizard@users.noreply.github.com> Co-authored-by: leopardracer <136604165+leopardracer@users.noreply.github.com> Co-authored-by: cairo <cairoeth@protonmail.com>
This commit is contained in:
@ -71,6 +71,15 @@ abstract contract Votes is Context, EIP712, Nonces, IERC5805 {
|
||||
return "mode=blocknumber&from=default";
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Validate that a timepoint is in the past, and return it as a uint48.
|
||||
*/
|
||||
function _validateTimepoint(uint256 timepoint) internal view returns (uint48) {
|
||||
uint48 currentTimepoint = clock();
|
||||
if (timepoint >= currentTimepoint) revert ERC5805FutureLookup(timepoint, currentTimepoint);
|
||||
return SafeCast.toUint48(timepoint);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the current amount of votes that `account` has.
|
||||
*/
|
||||
@ -87,11 +96,7 @@ abstract contract Votes is Context, EIP712, Nonces, IERC5805 {
|
||||
* - `timepoint` must be in the past. If operating using block numbers, the block must be already mined.
|
||||
*/
|
||||
function getPastVotes(address account, uint256 timepoint) public view virtual returns (uint256) {
|
||||
uint48 currentTimepoint = clock();
|
||||
if (timepoint >= currentTimepoint) {
|
||||
revert ERC5805FutureLookup(timepoint, currentTimepoint);
|
||||
}
|
||||
return _delegateCheckpoints[account].upperLookupRecent(SafeCast.toUint48(timepoint));
|
||||
return _delegateCheckpoints[account].upperLookupRecent(_validateTimepoint(timepoint));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -107,11 +112,7 @@ abstract contract Votes is Context, EIP712, Nonces, IERC5805 {
|
||||
* - `timepoint` must be in the past. If operating using block numbers, the block must be already mined.
|
||||
*/
|
||||
function getPastTotalSupply(uint256 timepoint) public view virtual returns (uint256) {
|
||||
uint48 currentTimepoint = clock();
|
||||
if (timepoint >= currentTimepoint) {
|
||||
revert ERC5805FutureLookup(timepoint, currentTimepoint);
|
||||
}
|
||||
return _totalCheckpoints.upperLookupRecent(SafeCast.toUint48(timepoint));
|
||||
return _totalCheckpoints.upperLookupRecent(_validateTimepoint(timepoint));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user