Skip to content

Add equal to Bytes.sol and update pragma to 0.8.24 in String dependencies #5726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jul 18, 2025
Merged
5 changes: 5 additions & 0 deletions .changeset/khaki-hats-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': minor
---

`Bytes`: Add a `nibbles` function to split each byte into two nibbles.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### Breaking changes

- Update minimum pragma to 0.8.24 in `SignatureChecker`, `Governor` and Governor's extensions. ([#5716](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/5716)).
- Update minimum pragma to 0.8.24 in `SignatureChecker`, `Votes`, `VotesExtended`, `ERC20Votes`, `Strings`, `ERC1155URIStorage`, `MessageHashUtils`, `ERC721URIStorage`, `ERC721Votes`, `ERC721Wrapper`, `ERC721Burnable`, `ERC721Consecutive`, `ERC721Enumerable`, `ERC721Pausable`, `ERC721Royalty`, `ERC721Wrapper`, `EIP712`, `ERC7739`, `Governor` and its extensions. ([#5716](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/5716)), ([#5680](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/5680))

## 5.3.0 (2025-04-09)

Expand Down
2 changes: 1 addition & 1 deletion contracts/governance/utils/Votes.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.2.0) (governance/utils/Votes.sol)
pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {IERC5805} from "../../interfaces/IERC5805.sol";
import {Context} from "../../utils/Context.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/governance/utils/VotesExtended.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.2.0) (governance/utils/VotesExtended.sol)
pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {Checkpoints} from "../../utils/structs/Checkpoints.sol";
import {Votes} from "./Votes.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/metatx/ERC2771Forwarder.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (metatx/ERC2771Forwarder.sol)

pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {ERC2771Context} from "./ERC2771Context.sol";
import {ECDSA} from "../utils/cryptography/ECDSA.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/EIP712Verifier.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {ECDSA} from "../utils/cryptography/ECDSA.sol";
import {EIP712} from "../utils/cryptography/EIP712.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/VotesExtendedMock.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {VotesExtended} from "../governance/utils/VotesExtended.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/VotesMock.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {Votes} from "../governance/utils/Votes.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/docs/MyNFT.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// contracts/MyNFT.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {ERC721} from "../../token/ERC721/ERC721.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/docs/governance/MyToken.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {ERC20} from "../../../token/ERC20/ERC20.sol";
import {ERC20Permit} from "../../../token/ERC20/extensions/ERC20Permit.sol";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {ERC20} from "../../../token/ERC20/ERC20.sol";
import {ERC20Permit} from "../../../token/ERC20/extensions/ERC20Permit.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/docs/governance/MyTokenWrapped.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {IERC20, ERC20} from "../../../token/ERC20/ERC20.sol";
import {ERC20Permit} from "../../../token/ERC20/extensions/ERC20Permit.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/docs/token/ERC721/GameItem.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// contracts/GameItem.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {ERC721URIStorage, ERC721} from "../../../../token/ERC721/extensions/ERC721URIStorage.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/docs/utilities/Base64NFT.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {ERC721} from "../../../token/ERC721/ERC721.sol";
import {Strings} from "../../../utils/Strings.sol";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {ERC20Votes} from "../../token/ERC20/extensions/ERC20Votes.sol";
import {VotesExtended, Votes} from "../../governance/utils/VotesExtended.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/token/ERC20VotesLegacyMock.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {ERC20Permit} from "../../token/ERC20/extensions/ERC20Permit.sol";
import {Math} from "../../utils/math/Math.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/token/ERC20VotesTimestampMock.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {ERC20Votes} from "../../token/ERC20/extensions/ERC20Votes.sol";
import {ERC721Votes} from "../../token/ERC721/extensions/ERC721Votes.sol";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {ERC721} from "../../token/ERC721/ERC721.sol";
import {ERC721Consecutive} from "../../token/ERC721/extensions/ERC721Consecutive.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/token/ERC721ConsecutiveMock.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {ERC721} from "../../token/ERC721/ERC721.sol";
import {ERC721Consecutive} from "../../token/ERC721/extensions/ERC721Consecutive.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/token/ERC721URIStorageMock.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {ERC721URIStorage} from "../../token/ERC721/extensions/ERC721URIStorage.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/utils/cryptography/ERC7739Mock.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {ECDSA} from "../../../utils/cryptography/ECDSA.sol";
import {EIP712} from "../../../utils/cryptography/EIP712.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/ERC1155/extensions/ERC1155URIStorage.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC1155/extensions/ERC1155URIStorage.sol)

pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {Strings} from "../../../utils/Strings.sol";
import {ERC1155} from "../ERC1155.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/ERC20/extensions/ERC20Permit.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/extensions/ERC20Permit.sol)

pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {IERC20Permit} from "./IERC20Permit.sol";
import {ERC20} from "../ERC20.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/ERC20/extensions/ERC20Votes.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/extensions/ERC20Votes.sol)

pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {ERC20} from "../ERC20.sol";
import {Votes} from "../../../governance/utils/Votes.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/ERC721/ERC721.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/ERC721.sol)

pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {IERC721} from "./IERC721.sol";
import {IERC721Metadata} from "./extensions/IERC721Metadata.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/ERC721/extensions/ERC721Burnable.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/extensions/ERC721Burnable.sol)

pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {ERC721} from "../ERC721.sol";
import {Context} from "../../../utils/Context.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/ERC721/extensions/ERC721Consecutive.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC721/extensions/ERC721Consecutive.sol)

pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {ERC721} from "../ERC721.sol";
import {IERC2309} from "../../../interfaces/IERC2309.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/ERC721/extensions/ERC721Enumerable.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/extensions/ERC721Enumerable.sol)

pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {ERC721} from "../ERC721.sol";
import {IERC721Enumerable} from "./IERC721Enumerable.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/ERC721/extensions/ERC721Pausable.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/extensions/ERC721Pausable.sol)

pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {ERC721} from "../ERC721.sol";
import {Pausable} from "../../../utils/Pausable.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/ERC721/extensions/ERC721Royalty.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/extensions/ERC721Royalty.sol)

pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {ERC721} from "../ERC721.sol";
import {IERC165} from "../../../utils/introspection/ERC165.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/ERC721/extensions/ERC721URIStorage.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC721/extensions/ERC721URIStorage.sol)

pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {ERC721} from "../ERC721.sol";
import {IERC721Metadata} from "./IERC721Metadata.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/ERC721/extensions/ERC721Votes.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/extensions/ERC721Votes.sol)

pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {ERC721} from "../ERC721.sol";
import {Votes} from "../../../governance/utils/Votes.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/ERC721/extensions/ERC721Wrapper.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/extensions/ERC721Wrapper.sol)

pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {IERC721, ERC721} from "../ERC721.sol";
import {IERC721Receiver} from "../IERC721Receiver.sol";
Expand Down
7 changes: 7 additions & 0 deletions contracts/utils/Bytes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ library Bytes {
return result;
}

/**
* @dev Returns true if the two byte buffers are equal.
*/
function equal(bytes memory a, bytes memory b) internal pure returns (bool) {
return a.length == b.length && keccak256(a) == keccak256(b);
}

/**
* @dev Reads a bytes32 from a bytes array without bounds checking.
*
Expand Down
5 changes: 3 additions & 2 deletions contracts/utils/Strings.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/Strings.sol)

pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {Math} from "./math/Math.sol";
import {SafeCast} from "./math/SafeCast.sol";
import {SignedMath} from "./math/SignedMath.sol";
import {Bytes} from "./Bytes.sol";

/**
* @dev String operations.
Expand Down Expand Up @@ -132,7 +133,7 @@ library Strings {
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
return Bytes.equal(bytes(a), bytes(b));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/utils/cryptography/EIP712.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/cryptography/EIP712.sol)

pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {MessageHashUtils} from "./MessageHashUtils.sol";
import {ShortStrings, ShortString} from "../ShortStrings.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/utils/cryptography/MessageHashUtils.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/cryptography/MessageHashUtils.sol)

pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {Strings} from "../Strings.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/utils/cryptography/signers/ERC7739.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {AbstractSigner} from "./AbstractSigner.sol";
import {EIP712} from "../EIP712.sol";
Expand Down
10 changes: 10 additions & 0 deletions test/utils/Bytes.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pragma solidity ^0.8.20;

import {Test} from "forge-std/Test.sol";
import {Bytes} from "@openzeppelin/contracts/utils/Bytes.sol";

contract BytesTest is Test {
function testSymbolicEqual(bytes memory a, bytes memory b) public pure {
assertEq(Bytes.equal(a, b), Bytes.equal(a, b));
}
}