Omniscia Tokemak Network Audit

VoteTracker Code Style Findings

VoteTracker Code Style Findings

VTR-01C: Inefficient Hash Specification

TypeSeverityLocation
Gas OptimizationInformationalVoteTracker.sol:L34, L39, L44, L47, L48

Description:

The linked variable is assigned to a keccak256 instruction and is declared as constant.

Example:

contracts/vote/VoteTracker.sol
34bytes32 public constant EIP712_DOMAIN_TYPEHASH =
35 keccak256(
36 "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
37 );

Recommendation:

We advise it to be set as immutable instead to cache the result of the keccak256 instruction as otherwise it is performed each time redundantly.

Alleviation:

All linked variables were properly set to immutable from constant to take advantage of the gas optimization.

VTR-02C: Inefficient Loop Halt

TypeSeverityLocation
Gas OptimizationInformationalVoteTracker.sol:L407, L408, L412

Description:

The linked guard variable used to terminate the while loop can be entirely omitted.

Example:

contracts/vote/VoteTracker.sol
405function _removeUserVoteKey(address account, bytes32 reactorKey) internal whenNotPaused {
406 uint256 i = 0;
407 bool deleted = false;
408 while (i < userVoteKeys[account].length && !deleted) {
409 if (userVoteKeys[account][i] == reactorKey) {
410 userVoteKeys[account][i] = userVoteKeys[account][userVoteKeys[account].length - 1];
411 userVoteKeys[account].pop();
412 deleted = true;
413 }
414 i++;
415 }
416}

Recommendation:

We advise it to be omitted so by replacing the deleted = true statement with a break one instead.

Alleviation:

The break statement has been properly introduced optimizing the code.