diff --git a/contracts/utils/contracts/src/LibAddressArray.sol b/contracts/utils/contracts/src/LibAddressArray.sol index aa10ea4945..70b7686df9 100644 --- a/contracts/utils/contracts/src/LibAddressArray.sol +++ b/contracts/utils/contracts/src/LibAddressArray.sol @@ -20,11 +20,11 @@ pragma solidity ^0.5.9; import "./LibAddressArrayRichErrors.sol"; import "./LibBytes.sol"; +import "./LibRichErrors.sol"; library LibAddressArray { - /// @dev Append a new address to an array of addresses. /// The `addressArray` may need to be reallocated to make space /// for the new address. Because of this we return the resulting @@ -54,10 +54,10 @@ library LibAddressArray { // `freeMemPtr` > `addressArrayEndPtr`: Some value occupies memory after `addressArray` // `freeMemPtr` < `addressArrayEndPtr`: Memory has not been managed properly. if (freeMemPtr < addressArrayEndPtr) { - LibAddressArrayRichErrors.MismanagedMemoryErrorRevert( + LibRichErrors._rrevert(LibAddressArrayRichErrors.MismanagedMemoryError( freeMemPtr, addressArrayEndPtr - ); + )); } // If free memory begins at the end of `addressArray` diff --git a/contracts/utils/contracts/src/LibAddressArrayRichErrors.sol b/contracts/utils/contracts/src/LibAddressArrayRichErrors.sol index 304d8036b3..82b99c6a2c 100644 --- a/contracts/utils/contracts/src/LibAddressArrayRichErrors.sol +++ b/contracts/utils/contracts/src/LibAddressArrayRichErrors.sol @@ -18,29 +18,26 @@ pragma solidity ^0.5.9; -import "./LibRichErrors.sol"; - library LibAddressArrayRichErrors { - using LibRichErrors for *; - // bytes4(keccak256("MismanagedMemoryError(uint256,uint256)")) bytes4 internal constant MISMANAGED_MEMORY_ERROR_SELECTOR = 0x5fc83722; // solhint-disable func-name-mixedcase - function MismanagedMemoryErrorRevert( + function MismanagedMemoryError( uint256 freeMemPtr, uint256 addressArrayEndPtr ) internal pure + returns (bytes memory) { - abi.encodeWithSelector( + return abi.encodeWithSelector( MISMANAGED_MEMORY_ERROR_SELECTOR, freeMemPtr, addressArrayEndPtr - )._rrevert(); + ); } } diff --git a/contracts/utils/contracts/src/LibBytes.sol b/contracts/utils/contracts/src/LibBytes.sol index d955494682..7dc5a6dc8a 100644 --- a/contracts/utils/contracts/src/LibBytes.sol +++ b/contracts/utils/contracts/src/LibBytes.sol @@ -19,6 +19,7 @@ pragma solidity ^0.5.9; import "./LibBytesRichErrors.sol"; +import "./LibRichErrors.sol"; library LibBytes { @@ -179,18 +180,18 @@ library LibBytes { // Ensure that the from and to positions are valid positions for a slice within // the byte array that is being used. if (from > to) { - LibBytesRichErrors.InvalidByteOperationErrorRevert( + LibRichErrors._rrevert(LibBytesRichErrors.InvalidByteOperationError( LibBytesRichErrors.InvalidByteOperationErrorCodes.FromLessThanOrEqualsToRequired, from, to - ); + )); } if (to > b.length) { - LibBytesRichErrors.InvalidByteOperationErrorRevert( + LibRichErrors._rrevert(LibBytesRichErrors.InvalidByteOperationError( LibBytesRichErrors.InvalidByteOperationErrorCodes.ToLessThanOrEqualsLengthRequired, to, b.length - ); + )); } // Create a new bytes structure and copy contents @@ -221,18 +222,18 @@ library LibBytes { // Ensure that the from and to positions are valid positions for a slice within // the byte array that is being used. if (from > to) { - LibBytesRichErrors.InvalidByteOperationErrorRevert( + LibRichErrors._rrevert(LibBytesRichErrors.InvalidByteOperationError( LibBytesRichErrors.InvalidByteOperationErrorCodes.FromLessThanOrEqualsToRequired, from, to - ); + )); } if (to > b.length) { - LibBytesRichErrors.InvalidByteOperationErrorRevert( + LibRichErrors._rrevert(LibBytesRichErrors.InvalidByteOperationError( LibBytesRichErrors.InvalidByteOperationErrorCodes.ToLessThanOrEqualsLengthRequired, to, b.length - ); + )); } // Create a new bytes structure around [from, to) in-place. @@ -252,11 +253,11 @@ library LibBytes { returns (bytes1 result) { if (b.length == 0) { - LibBytesRichErrors.InvalidByteOperationErrorRevert( + LibRichErrors._rrevert(LibBytesRichErrors.InvalidByteOperationError( LibBytesRichErrors.InvalidByteOperationErrorCodes.LengthGreaterThanZeroRequired, b.length, 0 - ); + )); } // Store last byte. @@ -279,11 +280,11 @@ library LibBytes { returns (address result) { if (b.length < 20) { - LibBytesRichErrors.InvalidByteOperationErrorRevert( + LibRichErrors._rrevert(LibBytesRichErrors.InvalidByteOperationError( LibBytesRichErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsTwentyRequired, b.length, 20 // 20 is length of address - ); + )); } // Store last 20 bytes. @@ -328,11 +329,11 @@ library LibBytes { returns (address result) { if (b.length < index + 20) { - LibBytesRichErrors.InvalidByteOperationErrorRevert( + LibRichErrors._rrevert(LibBytesRichErrors.InvalidByteOperationError( LibBytesRichErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsTwentyRequired, b.length, index + 20 // 20 is length of address - ); + )); } // Add offset to index: @@ -363,11 +364,11 @@ library LibBytes { pure { if (b.length < index + 20) { - LibBytesRichErrors.InvalidByteOperationErrorRevert( + LibRichErrors._rrevert(LibBytesRichErrors.InvalidByteOperationError( LibBytesRichErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsTwentyRequired, b.length, index + 20 // 20 is length of address - ); + )); } // Add offset to index: @@ -412,11 +413,11 @@ library LibBytes { returns (bytes32 result) { if (b.length < index + 32) { - LibBytesRichErrors.InvalidByteOperationErrorRevert( + LibRichErrors._rrevert(LibBytesRichErrors.InvalidByteOperationError( LibBytesRichErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsThirtyTwoRequired, b.length, index + 32 - ); + )); } // Arrays are prefixed by a 256 bit length parameter @@ -442,11 +443,11 @@ library LibBytes { pure { if (b.length < index + 32) { - LibBytesRichErrors.InvalidByteOperationErrorRevert( + LibRichErrors._rrevert(LibBytesRichErrors.InvalidByteOperationError( LibBytesRichErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsThirtyTwoRequired, b.length, index + 32 - ); + )); } // Arrays are prefixed by a 256 bit length parameter @@ -502,11 +503,11 @@ library LibBytes { returns (bytes4 result) { if (b.length < index + 4) { - LibBytesRichErrors.InvalidByteOperationErrorRevert( + LibRichErrors._rrevert(LibBytesRichErrors.InvalidByteOperationError( LibBytesRichErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsFourRequired, b.length, index + 4 - ); + )); } // Arrays are prefixed by a 32 byte length field @@ -543,12 +544,12 @@ library LibBytes { // Assert length of is valid, given // length of nested bytes if (b.length < index + nestedBytesLength) { - LibBytesRichErrors.InvalidByteOperationErrorRevert( + LibRichErrors._rrevert(LibBytesRichErrors.InvalidByteOperationError( LibBytesRichErrors .InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsNestedBytesLengthRequired, b.length, index + nestedBytesLength - ); + )); } // Return a pointer to the byte array as it exists inside `b` @@ -573,12 +574,12 @@ library LibBytes { // Assert length of is valid, given // length of input if (b.length < index + 32 + input.length) { - LibBytesRichErrors.InvalidByteOperationErrorRevert( + LibRichErrors._rrevert(LibBytesRichErrors.InvalidByteOperationError( LibBytesRichErrors .InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsNestedBytesLengthRequired, b.length, index + 32 + input.length // 32 bytes to store length - ); + )); } // Copy into @@ -602,12 +603,12 @@ library LibBytes { uint256 sourceLen = source.length; // Dest length must be >= source length, or some bytes would not be copied. if (dest.length < sourceLen) { - LibBytesRichErrors.InvalidByteOperationErrorRevert( + LibRichErrors._rrevert(LibBytesRichErrors.InvalidByteOperationError( LibBytesRichErrors .InvalidByteOperationErrorCodes.DestinationLengthGreaterThanOrEqualSourceLengthRequired, dest.length, sourceLen - ); + )); } memCopy( dest.contentAddress(), diff --git a/contracts/utils/contracts/src/LibBytesRichErrors.sol b/contracts/utils/contracts/src/LibBytesRichErrors.sol index a175c50425..cd0f4f6e56 100644 --- a/contracts/utils/contracts/src/LibBytesRichErrors.sol +++ b/contracts/utils/contracts/src/LibBytesRichErrors.sol @@ -18,13 +18,9 @@ pragma solidity ^0.5.9; -import "./LibRichErrors.sol"; - library LibBytesRichErrors { - using LibRichErrors for *; - enum InvalidByteOperationErrorCodes { FromLessThanOrEqualsToRequired, ToLessThanOrEqualsLengthRequired, @@ -41,19 +37,20 @@ library LibBytesRichErrors { 0x28006595; // solhint-disable func-name-mixedcase - function InvalidByteOperationErrorRevert( + function InvalidByteOperationError( InvalidByteOperationErrorCodes errorCode, uint256 endpoint, uint256 required ) internal pure + returns (bytes memory) { - abi.encodeWithSelector( + return abi.encodeWithSelector( INVALID_BYTE_OPERATION_ERROR_SELECTOR, errorCode, endpoint, required - )._rrevert(); + ); } } diff --git a/contracts/utils/contracts/src/MixinOwnableRichErrors.sol b/contracts/utils/contracts/src/LibOwnableRichErrors.sol similarity index 85% rename from contracts/utils/contracts/src/MixinOwnableRichErrors.sol rename to contracts/utils/contracts/src/LibOwnableRichErrors.sol index ecfe8abeb1..f16c49e9d1 100644 --- a/contracts/utils/contracts/src/MixinOwnableRichErrors.sol +++ b/contracts/utils/contracts/src/LibOwnableRichErrors.sol @@ -1,11 +1,8 @@ pragma solidity ^0.5.9; -import "./RichErrors.sol"; +library LibOwnableRichErrors { -contract MixinOwnableRichErrors is - RichErrors -{ // bytes4(keccak256("OnlyOwnerError(address,address)")) bytes4 internal constant ONLY_OWNER_SELECTOR = 0x1de45ad1; diff --git a/contracts/utils/contracts/src/MixinReentrancyGuardRichErrors.sol b/contracts/utils/contracts/src/LibReentrancyGuardRichErrors.sol similarity index 91% rename from contracts/utils/contracts/src/MixinReentrancyGuardRichErrors.sol rename to contracts/utils/contracts/src/LibReentrancyGuardRichErrors.sol index de7b7ee64c..dd42c7d249 100644 --- a/contracts/utils/contracts/src/MixinReentrancyGuardRichErrors.sol +++ b/contracts/utils/contracts/src/LibReentrancyGuardRichErrors.sol @@ -18,12 +18,9 @@ pragma solidity ^0.5.9; -import "./RichErrors.sol"; +library LibReentrancyGuardRichErrors { -contract MixinReentrancyGuardRichErrors is - RichErrors -{ // bytes4(keccak256("IllegalReentrancyError()")) bytes internal constant ILLEGAL_REENTRANCY_ERROR_SELECTOR_BYTES = hex"0c3b823f"; diff --git a/contracts/utils/contracts/src/MixinSafeMathRichErrors.sol b/contracts/utils/contracts/src/LibSafeMathRichErrors.sol similarity index 84% rename from contracts/utils/contracts/src/MixinSafeMathRichErrors.sol rename to contracts/utils/contracts/src/LibSafeMathRichErrors.sol index 85a46320e0..a1f39cc41d 100644 --- a/contracts/utils/contracts/src/MixinSafeMathRichErrors.sol +++ b/contracts/utils/contracts/src/LibSafeMathRichErrors.sol @@ -1,11 +1,8 @@ pragma solidity ^0.5.9; -import "./RichErrors.sol"; +library LibSafeMathRichErrors { -contract MixinSafeMathRichErrors is - RichErrors -{ // bytes4(keccak256("SafeMathError(uint8,uint256,uint256)")) bytes4 internal constant SAFE_MATH_ERROR = 0x35a51a70; @@ -23,7 +20,8 @@ contract MixinSafeMathRichErrors is uint256 b ) internal - pure returns (bytes memory) + pure + returns (bytes memory) { return abi.encodeWithSelector( SAFE_MATH_ERROR, diff --git a/contracts/utils/contracts/src/Ownable.sol b/contracts/utils/contracts/src/Ownable.sol index f6d0b46ee0..36af8f37da 100644 --- a/contracts/utils/contracts/src/Ownable.sol +++ b/contracts/utils/contracts/src/Ownable.sol @@ -1,11 +1,11 @@ pragma solidity ^0.5.9; import "./interfaces/IOwnable.sol"; -import "./MixinOwnableRichErrors.sol"; +import "./LibOwnableRichErrors.sol"; +import "./LibRichErrors.sol"; contract Ownable is - MixinOwnableRichErrors, IOwnable { address public owner; @@ -18,7 +18,7 @@ contract Ownable is modifier onlyOwner() { if (msg.sender != owner) { - _rrevert(OnlyOwnerError( + LibRichErrors._rrevert(LibOwnableRichErrors.OnlyOwnerError( msg.sender, owner )); diff --git a/contracts/utils/contracts/src/ReentrancyGuard.sol b/contracts/utils/contracts/src/ReentrancyGuard.sol index f890023cc9..99b1ced1cb 100644 --- a/contracts/utils/contracts/src/ReentrancyGuard.sol +++ b/contracts/utils/contracts/src/ReentrancyGuard.sol @@ -18,12 +18,12 @@ pragma solidity ^0.5.9; -import "./MixinReentrancyGuardRichErrors.sol"; +import "./LibReentrancyGuardRichErrors.sol"; +import "./LibRichErrors.sol"; -contract ReentrancyGuard is - MixinReentrancyGuardRichErrors -{ +contract ReentrancyGuard { + // Mutex counter. // Starts at 1 and increases whenever a nonReentrant function is called. uint256 private reentrancyGuardCounter = 1; @@ -37,7 +37,9 @@ contract ReentrancyGuard is // If the counter value is different from what we remember, the function // was called more than once and an illegal reentrancy occured. if (localCounter != reentrancyGuardCounter) { - _rrevert(IllegalReentrancyError()); + LibRichErrors._rrevert( + LibReentrancyGuardRichErrors.IllegalReentrancyError() + ); } } } diff --git a/contracts/utils/contracts/src/SafeMath.sol b/contracts/utils/contracts/src/SafeMath.sol index f8c57fca31..ed22105a9a 100644 --- a/contracts/utils/contracts/src/SafeMath.sol +++ b/contracts/utils/contracts/src/SafeMath.sol @@ -1,11 +1,10 @@ pragma solidity ^0.5.9; -import "./MixinSafeMathRichErrors.sol"; +import "./LibRichErrors.sol"; +import "./LibSafeMathRichErrors.sol"; -contract SafeMath is - MixinSafeMathRichErrors -{ +contract SafeMath { function _safeMul(uint256 a, uint256 b) internal @@ -17,8 +16,8 @@ contract SafeMath is } uint256 c = a * b; if (c / a != b) { - _rrevert(SafeMathError( - SafeMathErrorCodes.UINT256_MULTIPLICATION_OVERFLOW, + LibRichErrors._rrevert(LibSafeMathRichErrors.SafeMathError( + LibSafeMathRichErrors.SafeMathErrorCodes.UINT256_MULTIPLICATION_OVERFLOW, a, b )); @@ -41,8 +40,8 @@ contract SafeMath is returns (uint256) { if (b > a) { - _rrevert(SafeMathError( - SafeMathErrorCodes.UINT256_SUBTRACTION_UNDERFLOW, + LibRichErrors._rrevert(LibSafeMathRichErrors.SafeMathError( + LibSafeMathRichErrors.SafeMathErrorCodes.UINT256_SUBTRACTION_UNDERFLOW, a, b )); @@ -57,8 +56,8 @@ contract SafeMath is { uint256 c = a + b; if (c < a) { - _rrevert(SafeMathError( - SafeMathErrorCodes.UINT256_ADDITION_OVERFLOW, + LibRichErrors._rrevert(LibSafeMathRichErrors.SafeMathError( + LibSafeMathRichErrors.SafeMathErrorCodes.UINT256_ADDITION_OVERFLOW, a, b ));