diff --git a/contracts/utils/math/Math.sol b/contracts/utils/math/Math.sol index d7fd2f64d15..828b441fc01 100644 --- a/contracts/utils/math/Math.sol +++ b/contracts/utils/math/Math.sol @@ -473,9 +473,14 @@ library Math { /** * @dev Returns whether the provided byte array is zero. */ - function _zeroBytes(bytes memory byteArray) private pure returns (bool) { - for (uint256 i = 0; i < byteArray.length; ++i) { - if (byteArray[i] != 0) { + function _zeroBytes(bytes memory buffer) private pure returns (bool) { + uint256 chunk; + for (uint256 i = 0; i < buffer.length; i += 0x20) { + // See _unsafeReadBytesOffset from utils/Bytes.sol + assembly ("memory-safe") { + chunk := mload(add(add(buffer, 0x20), i)) + } + if (chunk >> (8 * saturatingSub(i + 0x20, buffer.length)) != 0) { return false; } }