Omniscia Kanpeki Finance Audit
ContractRegistry Code Style Findings
ContractRegistry Code Style Findings
CRY-01C: Pre-Calculated Key Lookups
Type | Severity | Location |
---|---|---|
Gas Optimization | Informational | ContractRegistry.sol:L56-L62 |
Description:
The keccak256
instructions included in getCoordinatingContracts
can be pre-calculated to achieve a lower execution gas cost.
Example:
52function getCoordinatingContracts () external view override returns (Contracts memory)53{54 return Contracts55 ({56 oracle: _implementation[keccak256("Oracle")],57 coordinator: _implementation[keccak256("Coordinator")],58 tokenRegistry: _implementation[keccak256("TokenRegistry")],59 stakingManager: _implementation[keccak256("StakingManager")],60 feeManager: _implementation[keccak256("FeeManager")],61 rewardManager: _implementation[keccak256("RewardManager")],62 collateralizationManager: _implementation[keccak256("CollateralizationManager")]63 });64}
Recommendation:
We advise them to be done so by declaring and storing them to private
/ internal
and constant
variables that are consequently used for the _implementation
lookups.
Alleviation:
All instances were replaced by constant
values declared as private
, alleviating this exhibit.
CRY-02C: Redundant Duplicate Mapping Lookups
Type | Severity | Location |
---|---|---|
Gas Optimization | Informational | ContractRegistry.sol:L45, L48 |
Description:
The getContract
function performs two redundant mapping
lookup operations that will incur the gas cost of an SLOAD
as well as keccak256
operation twice redundantly.
Example:
43function getContract (bytes32 key) external view override returns (address)44{45 require(_implementation[key] != address(0), "!exist impl");46
47
48 return _implementation[key];49}
Recommendation:
We advise the first lookup's result to be stored to an in-memory address
variable that will consequently be used for the require
and return
statements.
Alleviation:
The variable is now properly cached in-memory avoiding the duplicate redundant lookups.