diff --git a/contracts/libraries/BytesLib.sol b/contracts/external/libraries/BytesLib.sol similarity index 88% rename from contracts/libraries/BytesLib.sol rename to contracts/external/libraries/BytesLib.sol index fe83d77c7..31777de49 100644 --- a/contracts/libraries/BytesLib.sol +++ b/contracts/external/libraries/BytesLib.sol @@ -6,13 +6,15 @@ library BytesLib { * ERRORS * **************************************/ error OutOfBounds(); - error InvalidBytes(); - error InvalidStart(); /************************************** * FUNCTIONS * **************************************/ + // The following 4 functions are copied from solidity-bytes-utils library + // https://github.com/GNSPS/solidity-bytes-utils/blob/fc502455bb2a7e26a743378df042612dd50d1eb9/contracts/BytesLib.sol#L323C5-L398C6 + // Code was copied, and slightly modified to use revert instead of require + /** * @notice Reads a uint16 from a bytes array at a given start index * @param _bytes The bytes array to convert @@ -20,7 +22,9 @@ library BytesLib { * @return result The uint16 result */ function toUint16(bytes memory _bytes, uint256 _start) internal pure returns (uint16 result) { - require(_bytes.length >= _start + 2, "toUint16_outOfBounds"); + if (_bytes.length < _start + 2) { + revert OutOfBounds(); + } // solhint-disable-next-line no-inline-assembly assembly { @@ -81,6 +85,8 @@ library BytesLib { /** * @notice Reads a bytes array from a bytes array at a given start index and length + * Source: https://github.com/Vectorized/solady/blob/21202175063a0010826bf42697b5aa2ff0c27f9f/src/utils/LibBytes.sol#L369C5-L396C6 + * Code was copied, was not modified * @param _bytes The bytes array to convert * @param _start The start index of the bytes array * @param _end The end index of the bytes array diff --git a/contracts/external/libraries/MinimalLZOptions.sol b/contracts/external/libraries/MinimalLZOptions.sol index ecf495ea9..350da7591 100644 --- a/contracts/external/libraries/MinimalLZOptions.sol +++ b/contracts/external/libraries/MinimalLZOptions.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.23; -import { BytesLib } from "../../libraries/BytesLib.sol"; +import { BytesLib } from "../../external/libraries/BytesLib.sol"; import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol"; /** diff --git a/contracts/libraries/SponsoredCCTPQuoteLib.sol b/contracts/libraries/SponsoredCCTPQuoteLib.sol index 251060312..db19790a8 100644 --- a/contracts/libraries/SponsoredCCTPQuoteLib.sol +++ b/contracts/libraries/SponsoredCCTPQuoteLib.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; import { SignatureChecker } from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol"; import { SponsoredCCTPInterface } from "../interfaces/SponsoredCCTPInterface.sol"; -import { BytesLib } from "./BytesLib.sol"; +import { BytesLib } from "../external/libraries/BytesLib.sol"; import { Bytes32ToAddress } from "./AddressConverters.sol"; /** diff --git a/contracts/periphery/mintburn/sponsored-oft/ComposeMsgCodec.sol b/contracts/periphery/mintburn/sponsored-oft/ComposeMsgCodec.sol index df11de58d..bb24ef646 100644 --- a/contracts/periphery/mintburn/sponsored-oft/ComposeMsgCodec.sol +++ b/contracts/periphery/mintburn/sponsored-oft/ComposeMsgCodec.sol @@ -1,6 +1,6 @@ // SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.23; -import { BytesLib } from "../../../libraries/BytesLib.sol"; +import { BytesLib } from "../../../external/libraries/BytesLib.sol"; /// @notice Codec for params passed in OFT `composeMsg`. library ComposeMsgCodec {