Omniscia Metavisor Audit

MetavisorRegistry Code Style Findings

MetavisorRegistry Code Style Findings

MRY-01C: Inefficient mapping Lookups

TypeSeverityLocation
Gas OptimizationMetavisorRegistry.sol:L98, L113

Description:

The linked statements perform key-based lookup operations on mapping declarations from storage multiple times for the same key redundantly.

Example:

contracts/MetavisorRegistry.sol
98if (deployedVaults[_pool][_vaultType] != address(0)) {
99 revert Errors.AlreadyDeployed();
100}
101
102address _newVault = Clones.cloneDeterministic(
103 vaultMaster,
104 keccak256(abi.encodePacked(_pool, _vaultType))
105);
106setVaultSpec(_newVault, _vaultSpec);
107
108MetavisorManagedVault(payable(_newVault)).__MetavisorManagedVault__init(
109 address(this),
110 _pool,
111 _vaultType
112);
113deployedVaults[_pool][_vaultType] = _newVault;

Recommendation:

As the lookups internally perform an expensive keccak256 operation, we advise the lookups to be cached wherever possible to a single local declaration that either holds the value of the mapping in case of primitive types or holds a storage pointer to the struct contained.

Alleviation:

The Metavisor team evaluated this exhibit and opted not to apply a remediation for it in the current iteration of the codebase as it is inconsequential.

MRY-02C: Simplification of Conditional

TypeSeverityLocation
Gas OptimizationMetavisorRegistry.sol:L131-L134

Description:

The referenced conditionals can be simplified by merging them into a single return statement.

Example:

contracts/MetavisorRegistry.sol
130function isAllowedToRescale(address _sender) external view returns (bool) {
131 if (openRescale) {
132 return true;
133 }
134 return isOperator[_sender];
135}

Recommendation:

We advise this to be done so, adjusting the function to instead yield openRescale || isOperator[_sender] and optimizing the code's gas cost in the process.

Alleviation:

The conditional has been simplified as advised, optimizing the isAllowedToRescale function's gas cost.

MRY-03C: Variable Mutability Specifiers (Immutable)

TypeSeverityLocation
Gas OptimizationMetavisorRegistry.sol:L46, L47, L50

Description:

The linked variables are assigned to only once during the contract's constructor.

Example:

contracts/MetavisorRegistry.sol
45constructor(address _uniswapFactory, address _weth, uint256 _swapPercentage) {
46 uniswapFactory = IUniswapV3Factory(_uniswapFactory);
47 weth = IWETH9(_weth);
48 swapPercentage = _swapPercentage;
49
50 vaultMaster = address(new MetavisorManagedVault());
51
52 isOperator[msg.sender] = true;
53}

Recommendation:

We advise them to be set as immutable greatly optimizing their read-access gas cost.

Alleviation:

The weth and uniswapFactory have been adequately set as immutable similarly to the vaultMaster variable that was highlighted in the exhibit, optimizing their read-access gas costs significantly.