Omniscia Tokemak Network Audit
Manager Code Style Findings
Manager Code Style Findings
MAN-01C: Inefficient Hash Specification
Type | Severity | Location |
---|---|---|
Gas Optimization | Informational | Manager.sol:L27-L30 |
Description:
The linked variable is assigned to a keccak256
instruction and is declared as constant
.
Example:
contracts/manager/Manager.sol
27bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");28bytes32 public constant ROLLOVER_ROLE = keccak256("ROLLOVER_ROLE");29bytes32 public constant MID_CYCLE_ROLE = keccak256("MID_CYCLE_ROLE");30bytes32 public constant START_ROLLOVER_ROLE = keccak256("START_ROLLOVER_ROLE");
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.
MAN-02C: Inefficient length
Querying
Type | Severity | Location |
---|---|---|
Gas Optimization | Informational | Manager.sol:L145, L146, L153, L154 |
Description:
The linked invocations of the length
argument are redundantly invoked repeatedly instead of being cached in memory.
Example:
contracts/manager/Manager.sol
144function getPools() external view override returns (address[] memory) {145 address[] memory returnData = new address[](pools.length());146 for (uint256 i = 0; i < pools.length(); i++) {147 returnData[i] = pools.at(i);148 }149 return returnData;150}151
152function getControllers() external view override returns (bytes32[] memory) {153 bytes32[] memory returnData = new bytes32[](controllerIds.length());154 for (uint256 i = 0; i < controllerIds.length(); i++) {155 returnData[i] = controllerIds.at(i);156 }157 return returnData;158}
Recommendation:
We advise an in-memory variable to be declared and assigned to the length
value to optimize the codebase.
Alleviation:
The length
call result in both instances is now properly cached to an in-memory variable that is consequently utilized.