Modifiers have been using the require function most of the time, and I think the “if-revert” pattern would work better for a lower gas cost and allows multiple condition-checking easier in a modifier.
I’m wondering if there is any counter-arugment, potential issue or security concerns. Thanks.
// SPDX-License-Identifier: MIT
pragma solidity 0.8.4;
import "hardhat/console.sol";
contract Test {
function _msgSender() internal view returns (address) {
return msg.sender;
}
address private _owner;
error OnlyOwner();
modifier onlyOwner() {
require(_msgSender() == _owner, "Only Owner");
_;
}
modifier onlyOwner2() {
if (_msgSender() != _owner) revert OnlyOwner();
_;
}
constructor() {
_owner = _msgSender();
}
function getVal() public view onlyOwner returns (uint256) {
return 123;
}
function getVal2() public view onlyOwner2 returns (uint256) {
return 234;
}
}