Omniscia 0xPhase Audit

ERC20VotesUpgradeable Code Style Findings

ERC20VotesUpgradeable Code Style Findings

ERV-01C: Ineffectual Usage of Safe Arithmetics

TypeSeverityLocation
Language SpecificERC20VotesUpgradeable.sol:L101, L234, L237-L238, L279

Description:

The linked mathematical operations are guaranteed to be performed safely by surrounding conditionals evaluated in either require checks or if-else constructs.

Example:

lib/token/ERC20/ERC20VotesUpgradeable.sol
97function getVotes(
98 address account
99) public view virtual override returns (uint256) {
100 uint256 pos = _checkpoints[account].length;
101 return pos == 0 ? 0 : _checkpoints[account][pos - 1].votes;
102}

Recommendation:

Given that safe arithmetics are toggled on by default in pragma versions of 0.8.X, we advise the linked statements to be wrapped in unchecked code blocks thereby optimizing their execution cost.

Alleviation (3dd3d7bf0c2693b2f9c23bacedfa420393f7ea84):

All referenced arithmetic statements have been optimally wrapped in unchecked code blocks safely, addressing this exhibit.

ERV-02C: Redundant In-Memory Variable

TypeSeverityLocation
Gas OptimizationERC20VotesUpgradeable.sol:L55, L57

Description:

The referenced success variable is declared and utilized in the immediate ensuing statement.

Example:

lib/token/ERC20/ERC20VotesUpgradeable.sol
55bool success = SignatureChecker.isValidSignatureNow(delegator, hash, sig);
56
57require(success, "ERC20VotesUpgradeable: invalid signature");

Recommendation:

We advise the function invocation itself to be performed within the require check, rendering the local success variable redundant.

Alleviation (3dd3d7bf0c2693b2f9c23bacedfa420393f7ea84):

The SignatureChecker::isValidSignatureNow function is directly evaluated within the require check referenced, optimizing the code's gas cost.