Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@ 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want to just include unmodified versions?
Or is the thinking that those were not audited anyway so there's no difference?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that was my thinking, since its not audited might as well improve on error handling


/**
* @notice Reads a uint16 from a bytes array at a given start index
* @param _bytes The bytes array to convert
* @param _start The start index of the uint16
* @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 {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion contracts/external/libraries/MinimalLZOptions.sol
Original file line number Diff line number Diff line change
@@ -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";

/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/libraries/SponsoredCCTPQuoteLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Loading