diff --git a/contracts/utils/contracts/src/Authorizable.sol b/contracts/utils/contracts/src/Authorizable.sol index e14832d48b..e5132219b8 100644 --- a/contracts/utils/contracts/src/Authorizable.sol +++ b/contracts/utils/contracts/src/Authorizable.sol @@ -30,9 +30,7 @@ contract Authorizable is { /// @dev Only authorized addresses can invoke functions with this modifier. modifier onlyAuthorized { - if (!authorized[msg.sender]) { - LibRichErrors.rrevert(LibAuthorizableRichErrors.SenderNotAuthorizedError(msg.sender)); - } + _assertSenderIsAuthorized(); _; } @@ -122,4 +120,14 @@ contract Authorizable is { return authorities; } + + /// @dev Reverts if msg.sender is not authorized. + function _assertSenderIsAuthorized() + internal + view + { + if (!authorized[msg.sender]) { + LibRichErrors.rrevert(LibAuthorizableRichErrors.SenderNotAuthorizedError(msg.sender)); + } + } } diff --git a/contracts/utils/contracts/src/Ownable.sol b/contracts/utils/contracts/src/Ownable.sol index 05aed815a4..c03fac3b24 100644 --- a/contracts/utils/contracts/src/Ownable.sol +++ b/contracts/utils/contracts/src/Ownable.sol @@ -17,12 +17,7 @@ contract Ownable is } modifier onlyOwner() { - if (msg.sender != owner) { - LibRichErrors.rrevert(LibOwnableRichErrors.OnlyOwnerError( - msg.sender, - owner - )); - } + _assertSenderIsOwner(); _; } @@ -36,4 +31,16 @@ contract Ownable is owner = newOwner; } } + + function _assertSenderIsOwner() + internal + view + { + if (msg.sender != owner) { + LibRichErrors.rrevert(LibOwnableRichErrors.OnlyOwnerError( + msg.sender, + owner + )); + } + } } diff --git a/contracts/utils/contracts/src/ReentrancyGuard.sol b/contracts/utils/contracts/src/ReentrancyGuard.sol index 550e94ac90..78dc68e0ea 100644 --- a/contracts/utils/contracts/src/ReentrancyGuard.sol +++ b/contracts/utils/contracts/src/ReentrancyGuard.sol @@ -30,20 +30,28 @@ contract ReentrancyGuard { /// @dev Functions with this modifer cannot be reentered. The mutex will be locked /// before function execution and unlocked after. modifier nonReentrant() { + _lockMutexOrThrowIfAlreadyLocked(); + _; + _unlockMutex(); + } + + function _lockMutexOrThrowIfAlreadyLocked() + internal + { // Ensure mutex is unlocked. if (locked) { LibRichErrors.rrevert( LibReentrancyGuardRichErrors.IllegalReentrancyError() ); } - - // Lock mutex before function call + // Lock mutex. locked = true; + } - // Perform function call - _; - - // Unlock mutex after function call + function _unlockMutex() + internal + { + // Unlock mutex. locked = false; } }