Omniscia Evergon Labs Audit
ERC721Mintable Code Style Findings
ERC721Mintable Code Style Findings
ERN-01C: Inefficient Application of Modifier
| Type | Severity | Location |
|---|---|---|
| Gas Optimization | ![]() | ERC721Mintable.sol:L23, L43, L51 |
Description:
The ERC721Mintable::onlyMinter modifier is redundantly re-applied on each nested call of the ERC721Mintable::safeMint variants as they all ultimately invoke the ERC721Mintable::mint function that applies it.
Example:
contracts/dataManagers/ERC721/ERC721Mintable.sol
17/**18 * @notice Mint token of `id` to `to`19 * @param to Address to mint token to20 * @param tokenId Token id to mint21 * @dev The caller must be allowed to mint22 */23function mint(address to, uint256 tokenId) public virtual onlyMinter {24 if (to == address(0)) {25 revert ERC721InvalidReceiver(address(0));26 }27 address previousOwner = _update(to, tokenId, address(0));28 if (previousOwner != address(0)) {29 revert ERC721InvalidSender(address(0));30 }31}32
33/**34 * @dev Mints `tokenId`, transfers it to `to` and checks for `to` acceptance.35 *36 * Requirements:37 *38 * - `tokenId` must not exist.39 * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.40 *41 * Emits a {Transfer} event.42 */43function safeMint(address to, uint256 tokenId) public onlyMinter {44 safeMint(to, tokenId, "");45}46
47/**48 * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is49 * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.50 */51function safeMint(address to, uint256 tokenId, bytes memory data) public onlyMinter {52 mint(to, tokenId);53 _checkOnERC721Received(_msgSender(), to, tokenId, data);54}Recommendation:
We advise the modifier to be removed from the ERC721Mintable::safeMint variants, optimizing their gas cost.
Alleviation (c6b23c23d8bcd8cce85049ad959cbd711a37126b):
The relevant modifier has been omitted as advised, optimizing the gas cost of each function.
