Skip to content

Commit 83a5468

Browse files
committed
Merge branch 'develop'
2 parents 9cb61ce + 5d251ad commit 83a5468

9 files changed

+35
-35
lines changed

README.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
# Solidity Bytes Arrays Utils
44

5-
Bytes tightly packed arrays utility library for ethereum contracts written in Solidity.
5+
Bytes tightly packed arrays' utility library for ethereum contracts written in Solidity.
66

77
The library lets you concatenate, slice and type cast bytes arrays both in memory and storage.
88

9-
Given this library has an all-internal collection of methods it doesn't make sense having it reside in the mainnet. Instead it will only be available in EPM as an installable package.
9+
Given this library has an all-internal collection of methods it doesn't make sense to have it reside in the mainnet. Instead it will only be available on EPM as an installable package.
1010

1111
## Important Fixes Changelog
1212

@@ -34,6 +34,17 @@ This made me realize that in permissioned blockchains where gas is also not a li
3434

3535
## _Version Notes_:
3636

37+
* Starting from version `v0.8.0` the versioning will change to follow compatible Solidity's compiler versions.
38+
This means that now the library will only compile on Solidity versions `>=0.8.0` so, if you need `<0.8.0` support for your project just use `v0.1.2` of the library with:
39+
40+
```
41+
$ truffle install [email protected]
42+
```
43+
or
44+
```
45+
$ npm install [email protected]
46+
```
47+
3748
* Version `v0.1.2` has a major bug fix.
3849

3950
* Version `v0.1.1` has a critical bug fix.

contracts/AssertBytes.sol

100755100644
+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* This library is compliant with the test event convention that the Truffle suite uses.
88
*/
99

10-
pragma solidity >=0.5.0 <0.7.0;
10+
pragma solidity >=0.8.0 <0.9.0;
1111

1212

1313
library AssertBytes {
@@ -104,7 +104,7 @@ library AssertBytes {
104104

105105
assembly {
106106
// we know _a_offset is 0
107-
let fslot := sload(_a_slot)
107+
let fslot := sload(_a.slot)
108108
let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2)
109109
let mlength := mload(_b)
110110

@@ -133,7 +133,7 @@ library AssertBytes {
133133
let cb := 1
134134

135135
// get the keccak hash to get the contents of the array
136-
mstore(0x0, _a_slot)
136+
mstore(0x0, _a.slot)
137137
let sc := keccak256(0x0, 0x20)
138138

139139
let mc := add(_b, 0x20)

contracts/BytesLib.sol

100755100644
+9-19
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @dev Bytes tightly packed arrays utility library for ethereum contracts written in Solidity.
77
* The library lets you concatenate, slice and type cast bytes arrays both in memory and storage.
88
*/
9-
pragma solidity >=0.5.0 <0.7.0;
9+
pragma solidity >=0.8.0 <0.9.0;
1010

1111

1212
library BytesLib {
@@ -93,7 +93,7 @@ library BytesLib {
9393
// Read the first 32 bytes of _preBytes storage, which is the length
9494
// of the array. (We don't need to use the offset into the slot
9595
// because arrays use the entire slot.)
96-
let fslot := sload(_preBytes_slot)
96+
let fslot := sload(_preBytes.slot)
9797
// Arrays of 31 bytes or less have an even value in their slot,
9898
// while longer arrays have an odd value. The actual length is
9999
// the slot divided by two for odd values, and the lowest order
@@ -113,7 +113,7 @@ library BytesLib {
113113
// update the contents of the slot.
114114
// uint256(bytes_storage) = uint256(bytes_storage) + uint256(bytes_memory) + new_length
115115
sstore(
116-
_preBytes_slot,
116+
_preBytes.slot,
117117
// all the modifications to the slot are inside this
118118
// next block
119119
add(
@@ -143,11 +143,11 @@ library BytesLib {
143143
// The stored value fits in the slot, but the combined value
144144
// will exceed it.
145145
// get the keccak hash to get the contents of the array
146-
mstore(0x0, _preBytes_slot)
146+
mstore(0x0, _preBytes.slot)
147147
let sc := add(keccak256(0x0, 0x20), div(slength, 32))
148148

149149
// save new length
150-
sstore(_preBytes_slot, add(mul(newlength, 2), 1))
150+
sstore(_preBytes.slot, add(mul(newlength, 2), 1))
151151

152152
// The contents of the _postBytes array start 32 bytes into
153153
// the structure. Our first read should obtain the `submod`
@@ -190,12 +190,12 @@ library BytesLib {
190190
}
191191
default {
192192
// get the keccak hash to get the contents of the array
193-
mstore(0x0, _preBytes_slot)
193+
mstore(0x0, _preBytes.slot)
194194
// Start copying to the last used word of the stored array.
195195
let sc := add(keccak256(0x0, 0x20), div(slength, 32))
196196

197197
// save new length
198-
sstore(_preBytes_slot, add(mul(newlength, 2), 1))
198+
sstore(_preBytes.slot, add(mul(newlength, 2), 1))
199199

200200
// Copy over the first `submod` bytes of the new data as in
201201
// case 1 above.
@@ -235,7 +235,6 @@ library BytesLib {
235235
returns (bytes memory)
236236
{
237237
require(_length + 31 >= _length, "slice_overflow");
238-
require(_start + _length >= _start, "slice_overflow");
239238
require(_bytes.length >= _start + _length, "slice_outOfBounds");
240239

241240
bytes memory tempBytes;
@@ -296,7 +295,6 @@ library BytesLib {
296295
}
297296

298297
function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address) {
299-
require(_start + 20 >= _start, "toAddress_overflow");
300298
require(_bytes.length >= _start + 20, "toAddress_outOfBounds");
301299
address tempAddress;
302300

@@ -308,7 +306,6 @@ library BytesLib {
308306
}
309307

310308
function toUint8(bytes memory _bytes, uint256 _start) internal pure returns (uint8) {
311-
require(_start + 1 >= _start, "toUint8_overflow");
312309
require(_bytes.length >= _start + 1 , "toUint8_outOfBounds");
313310
uint8 tempUint;
314311

@@ -320,7 +317,6 @@ library BytesLib {
320317
}
321318

322319
function toUint16(bytes memory _bytes, uint256 _start) internal pure returns (uint16) {
323-
require(_start + 2 >= _start, "toUint16_overflow");
324320
require(_bytes.length >= _start + 2, "toUint16_outOfBounds");
325321
uint16 tempUint;
326322

@@ -332,7 +328,6 @@ library BytesLib {
332328
}
333329

334330
function toUint32(bytes memory _bytes, uint256 _start) internal pure returns (uint32) {
335-
require(_start + 4 >= _start, "toUint32_overflow");
336331
require(_bytes.length >= _start + 4, "toUint32_outOfBounds");
337332
uint32 tempUint;
338333

@@ -344,7 +339,6 @@ library BytesLib {
344339
}
345340

346341
function toUint64(bytes memory _bytes, uint256 _start) internal pure returns (uint64) {
347-
require(_start + 8 >= _start, "toUint64_overflow");
348342
require(_bytes.length >= _start + 8, "toUint64_outOfBounds");
349343
uint64 tempUint;
350344

@@ -356,7 +350,6 @@ library BytesLib {
356350
}
357351

358352
function toUint96(bytes memory _bytes, uint256 _start) internal pure returns (uint96) {
359-
require(_start + 12 >= _start, "toUint96_overflow");
360353
require(_bytes.length >= _start + 12, "toUint96_outOfBounds");
361354
uint96 tempUint;
362355

@@ -368,7 +361,6 @@ library BytesLib {
368361
}
369362

370363
function toUint128(bytes memory _bytes, uint256 _start) internal pure returns (uint128) {
371-
require(_start + 16 >= _start, "toUint128_overflow");
372364
require(_bytes.length >= _start + 16, "toUint128_outOfBounds");
373365
uint128 tempUint;
374366

@@ -380,7 +372,6 @@ library BytesLib {
380372
}
381373

382374
function toUint256(bytes memory _bytes, uint256 _start) internal pure returns (uint256) {
383-
require(_start + 32 >= _start, "toUint256_overflow");
384375
require(_bytes.length >= _start + 32, "toUint256_outOfBounds");
385376
uint256 tempUint;
386377

@@ -392,7 +383,6 @@ library BytesLib {
392383
}
393384

394385
function toBytes32(bytes memory _bytes, uint256 _start) internal pure returns (bytes32) {
395-
require(_start + 32 >= _start, "toBytes32_overflow");
396386
require(_bytes.length >= _start + 32, "toBytes32_outOfBounds");
397387
bytes32 tempBytes32;
398388

@@ -458,7 +448,7 @@ library BytesLib {
458448

459449
assembly {
460450
// we know _preBytes_offset is 0
461-
let fslot := sload(_preBytes_slot)
451+
let fslot := sload(_preBytes.slot)
462452
// Decode the length of the stored array like in concatStorage().
463453
let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2)
464454
let mlength := mload(_postBytes)
@@ -488,7 +478,7 @@ library BytesLib {
488478
let cb := 1
489479

490480
// get the keccak hash to get the contents of the array
491-
mstore(0x0, _preBytes_slot)
481+
mstore(0x0, _preBytes.slot)
492482
let sc := keccak256(0x0, 0x20)
493483

494484
let mc := add(_postBytes, 0x20)

contracts/Migrations.sol

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// SPDX-License-Identifier: Unlicense
2-
pragma solidity >=0.5.0 <0.7.0;
2+
pragma solidity >=0.8.0;
3+
34

45

56

@@ -11,7 +12,7 @@ contract Migrations {
1112
if (msg.sender == owner) _;
1213
}
1314

14-
constructor () public {
15+
constructor () {
1516
owner = msg.sender;
1617
}
1718

ethpm.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"package_name": "bytes",
3-
"version": "0.1.2",
3+
"version": "0.8.0",
44
"description": "Solidity bytes tightly packed arrays utility library.",
55
"authors": [
66
"Gonçalo Sá <[email protected]>"

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "solidity-bytes-utils",
3-
"version": "0.1.2",
3+
"version": "0.8.0",
44
"description": "Solidity bytes tightly packed arrays utility library.",
55
"main": "truffle.js",
66
"repository": {

test/TestBytesLib1.sol

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: Unlicense
2-
pragma solidity >=0.5.0 <0.7.0;
2+
pragma solidity >=0.8.0 <0.9.0;
33

44
import "truffle/Assert.sol";
55
import "../contracts/AssertBytes.sol";
@@ -21,8 +21,6 @@ contract TestBytesLib1 {
2121
bytes storageBytes65 = hex"f00d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000feed";
2222
bytes storageBytes70 = hex"f00d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000feed";
2323

24-
event LogBytes(bytes loggedBytes);
25-
2624
/**
2725
* Sanity Checks
2826
*/

test/TestBytesLib2.sol

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: Unlicense
2-
pragma solidity >=0.5.0 <0.7.0;
2+
pragma solidity >=0.8.0 <0.9.0;
33

44
import "truffle/Assert.sol";
55
import "../contracts/AssertBytes.sol";
@@ -11,8 +11,8 @@ contract TestBytesLib2 {
1111

1212
bytes storageCheckBytes = hex"aabbccddeeff";
1313
bytes storageCheckBytesZeroLength = hex"";
14-
15-
uint256 constant MAX_UINT = uint256(-1);
14+
15+
uint256 constant MAX_UINT = type(uint256).max;
1616

1717
/**
1818
* Sanity Checks

truffle.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module.exports = {
4343
},
4444
compilers: {
4545
solc: {
46-
version: "0.6.10", // A version or constraint - Ex. "^0.5.0"
46+
version: "0.8.3", // A version or constraint - Ex. "^0.5.0"
4747
}
4848
}
4949
};

0 commit comments

Comments
 (0)