Skip to content

Commit d53ed64

Browse files
TomAFrenchJulissaDantes
authored andcommitted
Reduce gas in log256 (OpenZeppelin#3745)
1 parent d2e856c commit d53ed64

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
* `Math` and `SignedMath`: optimize function `max` by using `>` instead of `>=`. ([#3679](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3679))
3636
* `Math`: Add `log2`, `log10` and `log256`. ([#3670](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3670))
3737
* Arbitrum: Update the vendored arbitrum contracts to match the nitro upgrade. ([#3692](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3692))
38+
* `Math`: optimize `log256` rounding check. ([#3745](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3745))
3839

3940
### Breaking changes
4041

contracts/utils/math/Math.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ library Math {
339339
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
340340
unchecked {
341341
uint256 result = log256(value);
342-
return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
342+
return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
343343
}
344344
}
345345
}

0 commit comments

Comments
 (0)