<!-- canonical: https://0xsimao.com/findings/keyring-ii-placed-readability-reduce-duplication -->

# Admin checks in KeyringCoreV2Base could be placed in a modifier to increase readability and reduce code duplication

Low/Info · Three Sigma · Zero-knowledge compliance · 10th July, 2024

Finding 3S-Keyring-N03 of the Keyring Credentials security review.

- Protocol: https://www.keyring.network/
- Report: /reports/keyring-ii
- Source: https://cdn.sanity.io/files/qoqld077/production/75b68b74f4b0dc6fbcd94892d934547d8259b57a.pdf

---

### Description

Usually access control is performed in modifiers, as is the case with onlyOwner, for example.
The same could be applied to the admin check in each permissioned function to increase
readability and decrease code duplication.

### Recommendation

Create a modifier and implement the body of a function to reduce deployment costs
(modifier's code is duplicated into each function which increases deployment costs
significantly).

```solidity
modifier onlyAdmin() {
    _onlyAdmin();
    _;
}
function _onlyAdmin() internal {
    if (msg.sender != _admin) {
        revert ErrCallerNotAdmin(msg.sender);
    }
}
```

### Status

Acknowledged

---

Related findings:

- [Constants should be placed as constants and not hardcoded for better readability](https://0xsimao.com/findings/fuji-finance-constants-hardcoded-better-readability): Fuji Finance
- [Throughout code base, implement using SafeERC20 for IERC20 for better readability](https://0xsimao.com/findings/fuji-finance-erc20-ierc20-better-readability): Fuji Finance
- [If statements can be inverted to increase readability](https://0xsimao.com/findings/glacier-statements-inverted-increase-readability): Glacier
- [Admin will not be able to upgrade the smart contracts, breaking core functionality and rendering the upgradeable contracts useless](https://0xsimao.com/findings/cork-protocol-upgrade-functionality-rendering-upgradeable): Cork Protocol
