Skip to content

Commit 0f5566d

Browse files
authored
Merge branch 'master' into typo-fixes
2 parents 2bb691a + c3961a4 commit 0f5566d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+523
-195
lines changed

.changeset/fast-beans-pull.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openzeppelin-solidity': minor
3+
---
4+
5+
`Bytes`: Add a `clz` function to count the leading zero bits in a `bytes` buffer.

.changeset/whole-cats-find.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openzeppelin-solidity': minor
3+
---
4+
5+
`Math`: Add a `clz` function to count the leading zero bits in a `uint256` value.

contracts/utils/Bytes.sol

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ library Bytes {
128128
return buffer;
129129
}
130130

131-
/*
131+
/**
132132
* @dev Returns true if the two byte buffers are equal.
133133
*/
134134
function equal(bytes memory a, bytes memory b) internal pure returns (bool) {
@@ -187,6 +187,20 @@ library Bytes {
187187
return (value >> 8) | (value << 8);
188188
}
189189

190+
/**
191+
* @dev Counts the number of leading zero bits a bytes array. Returns `8 * buffer.length`
192+
* if the buffer is all zeros.
193+
*/
194+
function clz(bytes memory buffer) internal pure returns (uint256) {
195+
for (uint256 i = 0; i < buffer.length; i += 32) {
196+
bytes32 chunk = _unsafeReadBytesOffset(buffer, i);
197+
if (chunk != bytes32(0)) {
198+
return Math.min(8 * i + Math.clz(uint256(chunk)), 8 * buffer.length);
199+
}
200+
}
201+
return 8 * buffer.length;
202+
}
203+
190204
/**
191205
* @dev Reads a bytes32 from a bytes array without bounds checking.
192206
*

contracts/utils/math/Math.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,4 +746,11 @@ library Math {
746746
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
747747
return uint8(rounding) % 2 == 1;
748748
}
749+
750+
/**
751+
* @dev Counts the number of leading zero bits in a uint256.
752+
*/
753+
function clz(uint256 x) internal pure returns (uint256) {
754+
return ternary(x == 0, 256, 255 - log2(x));
755+
}
749756
}

foundry.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ out = 'out'
88
libs = ['node_modules', 'lib']
99
test = 'test'
1010
cache_path = 'cache_forge'
11-
fs_permissions = [{ access = "read", path = "./test/bin" }]
11+
fs_permissions = [{ access = "read", path = "./node_modules/hardhat-predeploy/bin" }]
1212

1313
[fuzz]
1414
runs = 5000

fv-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
certora-cli==4.13.1
22
# File uses a custom name (fv-requirements.txt) so that it isn't picked by Netlify's build
33
# whose latest Python version is 0.3.8, incompatible with most recent versions of Halmos
4-
halmos==0.3.0
4+
halmos==0.3.1

hardhat.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ require('@nomicfoundation/hardhat-ethers');
6161
require('hardhat-exposed');
6262
require('hardhat-gas-reporter');
6363
require('hardhat-ignore-warnings');
64+
require('hardhat-predeploy');
6465
require('solidity-coverage');
6566
require('solidity-docgen');
6667

hardhat/common-contracts.js

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)