Skip to content

Commit bd3c77a

Browse files
authored
improve: Move BytesLib to external folder (#1153)
* improve: Move BytesLib to external folder Signed-off-by: Faisal Usmani <[email protected]> * Undo var scoping Signed-off-by: Faisal Usmani <[email protected]> --------- Signed-off-by: Faisal Usmani <[email protected]>
1 parent da90282 commit bd3c77a

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

contracts/libraries/BytesLib.sol renamed to contracts/external/libraries/BytesLib.sol

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,25 @@ library BytesLib {
66
* ERRORS *
77
**************************************/
88
error OutOfBounds();
9-
error InvalidBytes();
10-
error InvalidStart();
119

1210
/**************************************
1311
* FUNCTIONS *
1412
**************************************/
1513

14+
// The following 4 functions are copied from solidity-bytes-utils library
15+
// https://github.com/GNSPS/solidity-bytes-utils/blob/fc502455bb2a7e26a743378df042612dd50d1eb9/contracts/BytesLib.sol#L323C5-L398C6
16+
// Code was copied, and slightly modified to use revert instead of require
17+
1618
/**
1719
* @notice Reads a uint16 from a bytes array at a given start index
1820
* @param _bytes The bytes array to convert
1921
* @param _start The start index of the uint16
2022
* @return result The uint16 result
2123
*/
2224
function toUint16(bytes memory _bytes, uint256 _start) internal pure returns (uint16 result) {
23-
require(_bytes.length >= _start + 2, "toUint16_outOfBounds");
25+
if (_bytes.length < _start + 2) {
26+
revert OutOfBounds();
27+
}
2428

2529
// solhint-disable-next-line no-inline-assembly
2630
assembly {
@@ -81,6 +85,8 @@ library BytesLib {
8185

8286
/**
8387
* @notice Reads a bytes array from a bytes array at a given start index and length
88+
* Source: https://github.com/Vectorized/solady/blob/21202175063a0010826bf42697b5aa2ff0c27f9f/src/utils/LibBytes.sol#L369C5-L396C6
89+
* Code was copied, was not modified
8490
* @param _bytes The bytes array to convert
8591
* @param _start The start index of the bytes array
8692
* @param _end The end index of the bytes array

contracts/external/libraries/MinimalLZOptions.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.23;
33

4-
import { BytesLib } from "../../libraries/BytesLib.sol";
4+
import { BytesLib } from "../../external/libraries/BytesLib.sol";
55
import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";
66

77
/**

contracts/libraries/SponsoredCCTPQuoteLib.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pragma solidity ^0.8.0;
44
import { SignatureChecker } from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";
55

66
import { SponsoredCCTPInterface } from "../interfaces/SponsoredCCTPInterface.sol";
7-
import { BytesLib } from "./BytesLib.sol";
7+
import { BytesLib } from "../external/libraries/BytesLib.sol";
88
import { Bytes32ToAddress } from "./AddressConverters.sol";
99

1010
/**

contracts/periphery/mintburn/sponsored-oft/ComposeMsgCodec.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: BUSL-1.1
22
pragma solidity ^0.8.23;
3-
import { BytesLib } from "../../../libraries/BytesLib.sol";
3+
import { BytesLib } from "../../../external/libraries/BytesLib.sol";
44

55
/// @notice Codec for params passed in OFT `composeMsg`.
66
library ComposeMsgCodec {

0 commit comments

Comments
 (0)