Omniscia Avant Protocol Audit

SingleAdminAccessControl Code Style Findings

SingleAdminAccessControl Code Style Findings

SAA-01C: Inefficient Duplicate Read of Variable

Description:

The _currentDefaultAdmin variable is read twice from storage redundantly in the SingleAdminAccessControl::_grantRole function.

Example:

contracts/SingleAdminAccessControl.sol
73if (role == DEFAULT_ADMIN_ROLE) {
74 emit AdminTransferred(_currentDefaultAdmin, account);
75 _revokeRole(DEFAULT_ADMIN_ROLE, _currentDefaultAdmin);
76 _currentDefaultAdmin = account;
77 delete _pendingDefaultAdmin;
78}

Recommendation:

We advise it to be read once, and stored to a local address variable which is consequently re-used twice.

Alleviation:

The _currentDefaultAdmin variable is properly stored to a local _currentDefaultAdmin_ variable declaration that is consequently re-used twice, optimizing the code's gas cost.

SAA-02C: Inefficient Initial Ownership

Description:

The SingleAdminAccessControl initial DEFAULT_ADMIN_ROLE allocation will be inefficient as it will revoke the DEFAULT_ADMIN_ROLE from the 0 address inefficiently, and it will delete the _pendingDefaultAdmin data entry which will already be 0.

Example:

contracts/SingleAdminAccessControl.sol
69/**
70 * @notice no way to change admin without removing old admin first
71 */
72function _grantRole(bytes32 role, address account) internal override {
73 if (role == DEFAULT_ADMIN_ROLE) {
74 emit AdminTransferred(_currentDefaultAdmin, account);
75 _revokeRole(DEFAULT_ADMIN_ROLE, _currentDefaultAdmin);
76 _currentDefaultAdmin = account;
77 delete _pendingDefaultAdmin;
78 }
79 super._grantRole(role, account);
80}

Recommendation:

We advise a different initialization function to be introduced that is efficient and skips the aforementioned redundant steps.

This process can also be introduced as part of a SingleAdminAccessControl::constructor.

Alleviation:

The Avant Protocol team evaluated this optimization and opted to acknowledge it as the cost involved is incurred once during the contract's initial role allocation.