|
1 | 1 | // SPDX-License-Identifier: BUSL-1.1 |
2 | 2 | pragma solidity ^0.8.0; |
3 | 3 |
|
| 4 | +import { Bytes } from "@openzeppelin/contracts-v5/utils/Bytes.sol"; |
| 5 | + |
4 | 6 | library BytesLib { |
5 | 7 | /************************************** |
6 | 8 | * ERRORS * |
@@ -85,43 +87,13 @@ library BytesLib { |
85 | 87 |
|
86 | 88 | /** |
87 | 89 | * @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 |
| 90 | + * Source: OpenZeppelin Contracts v5 (utils/Bytes.sol) |
90 | 91 | * @param _bytes The bytes array to convert |
91 | 92 | * @param _start The start index of the bytes array |
92 | 93 | * @param _end The end index of the bytes array |
93 | 94 | * @return result The bytes array result |
94 | 95 | */ |
95 | 96 | function slice(bytes memory _bytes, uint256 _start, uint256 _end) internal pure returns (bytes memory result) { |
96 | | - // solhint-disable-next-line no-inline-assembly |
97 | | - assembly { |
98 | | - let l := mload(_bytes) // _bytes length. |
99 | | - if iszero(gt(l, _end)) { |
100 | | - _end := l |
101 | | - } |
102 | | - if iszero(gt(l, _start)) { |
103 | | - _start := l |
104 | | - } |
105 | | - if lt(_start, _end) { |
106 | | - result := mload(0x40) |
107 | | - let n := sub(_end, _start) |
108 | | - let i := add(_bytes, _start) |
109 | | - let w := not(0x1f) |
110 | | - // Copy the `_bytes` one word at a time, backwards. |
111 | | - for { |
112 | | - let j := and(add(n, 0x1f), w) |
113 | | - } 1 {} { |
114 | | - mstore(add(result, j), mload(add(i, j))) |
115 | | - j := add(j, w) // `sub(j, 0x20)`. |
116 | | - if iszero(j) { |
117 | | - break |
118 | | - } |
119 | | - } |
120 | | - let o := add(add(result, 0x20), n) |
121 | | - mstore(o, 0) // Zeroize the slot after the bytes. |
122 | | - mstore(0x40, add(o, 0x20)) // Allocate memory. |
123 | | - mstore(result, n) // Store the length. |
124 | | - } |
125 | | - } |
| 97 | + return Bytes.slice(_bytes, _start, _end); |
126 | 98 | } |
127 | 99 | } |
0 commit comments