Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
This article summarizes the changes in OpenZeppelin version 5.1.
The summary is based on the following release notes on GitHub, for v5.1.0-rc.0.
ERC1967Utils
Duplicate declarations of the Upgraded, AdminChanged, and BeaconUpgraded events have been removed.
These events are available through the IERC1967 interface in the contracts/interfaces/ directory.
The minimum pragma version is now 0.8.21.
Governance module changes
The _countVotes function in the Governor and GovernorCountingSimple contracts now returns a uint256 representing the total votes counted.
This supports partial and fractional voting.
Existing users can resolve compilation errors by adding a return statement to their _countVotes function.
Custom error changes
Custom error identifiers have changed.
Address.FailedInnerCall→Errors.FailedCallAddress.AddressInsufficientBalance→Errors.InsufficientBalanceClones.Create2InsufficientBalance→Errors.InsufficientBalanceClones.ERC1167FailedCreateClone→Errors.FailedDeploymentClones.Create2FailedDeployment→Errors.FailedDeployment
SafeERC20 has changed as follows.
- If the token address has no code,
Address.AddressEmptyCode→SafeERC20FailedOperation - If the returned data cannot be decoded as a
bool, the genericError(string)→SafeERC20FailedOperation - If the contract call fails, a
revertmessage is added to the genericSafeERC20FailedOperation.
Changes by category
General
Initializer functions for upgradeable deployments have been added to AccessManager, VestingWallet, TimelockController, and ERC2771Forwarder.
Access
It is now possible to retrieve the addresses holding a particular role and apply stricter access control.
AccessControlEnumerable
The getRoleMembers function has been added, allowing callers to retrieve all accounts holding a particular role.
function getRoleMembers(bytes32 role) public view virtual returns (address[] memory) {
return _roleMembers[role].values();
}AccessManager
The onlyAuthorized modifier has been added to enable stricter access control.
Finance
VestingWalletCliff
An extension has been introduced that adds a cliff to a vesting wallet.
This sets a vesting period during which the wallet's tokens remain locked until the period has elapsed.
Governance
GovernorCountingFractional
A new governance vote-counting module lets voters split their voting power across for, against, and abstain.
Votes
The visibility of the _moveDelegateVotes function has changed from private to internal, allowing derived contracts to access it.
Proxy
Clones
New versions of clone and cloneDeterministic support sending value at contract creation.
This makes it possible to send ETH in the transaction that creates a clone.
TransparentUpgradeableProxy
The _proxyAdmin() function has been changed from internal to view.
ProxyAdmin
The documentation for UPGRADE_INTERFACE_VERSION has been corrected.
Tokens
ERC1363
An implementation of the token payment standard has been added. It allows contract code to run after a token transfer or approve, enabling more advanced token operations.
ERC20TemporaryApproval
An ERC20 extension that implements temporary approve has been added.
It is based on ERC7674 and provides temporary token approvals.
https://ethereum-magicians.org/t/erc-7674-temporary-approval-extension-for-erc-20/19521
SafeERC20
A function described as relaxrd in the original article has been added. It handles operations differently depending on whether the receiving address is an EOA or a contract. It also appears to be compatible with ERC1363 functionality.
ERC721Utils and ERC1155Utils
Reusable libraries have been added for performing acceptance checks on contracts implementing IERC721Receiver and IERC1155Receiver.
ERC1363Utils
Helper functions similar to those in ERC721Utils and ERC1155Utils have been added to support ERC1363 tokens.
Utils
Arrays
Sorting functions for address[], bytes32[], and uint256[] have been added to make array operations easier.
Arrays
The lowerBound and upperBound functions and their memory variants have been added. They speed up searches in sorted arrays and support duplicate values.
findUpperBound is deprecated in favor of lowerBound.
Base64
The encodeURL function has been added for URL-safe encoding.
Comparator
A library of comparison functions has been added to help implement custom behavior for heap data structures.
Create2
When contract creation triggers a revert, the return data is now bubbled up.
Create2, Clones
Masks have been added so that the outputs of computeAddress and cloneDeterministic are clean address values using only 20 bytes.
Errors
A new library collects common custom errors.
Hashes
A library containing commonly used hash functions has been added.
Packing
New utilities have been added for packing, extracting, and replacing bytesXX values.
Panic
A library has been added to revert with panic codes.
ReentrancyGuardTransient
A variant that uses transient storage (a new temporary storage mechanism) has been added.
Strings
A utility function has been added to convert an address to a checksummed string.
SlotDerivation
A library has been added to derive storage slots.
StorageSlot
Functions have been added to manipulate transient storage using typed slot representations.
Cryptography
SignatureChecker
isValidSignatureNow has been refactored to skip ECDSA signature verification when code is deployed at the signer's address.
This improves efficiency.
MerkleProof
Variants of verify, processProof, and multiProofVerify have been added to support custom hash functions.
P256
A library has been added for P256 (secp256r1) signature verification and public key recovery.
RSA
A library has been added to verify signatures according to the signature verification operation in RFC 8017.
Math
Math
The invMod function has been added to compute the modular multiplicative inverse of a number in Z/nZ.
Math
The modExp function has been added to make use of the EIP198 precompile.
It includes uint256 and bytes memory versions.
Math
Custom errors have been replaced with native panic codes.
- Panic codes
library Panic {
/// @dev generic / unspecified error
uint256 internal constant GENERIC = 0x00;
/// @dev used by the assert() builtin
uint256 internal constant ASSERT = 0x01;
/// @dev arithmetic underflow or overflow
uint256 internal constant UNDER_OVERFLOW = 0x11;
/// @dev division or modulo by zero
uint256 internal constant DIVISION_BY_ZERO = 0x12;
/// @dev enum conversion error
uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;
/// @dev invalid encoding in storage
uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;
/// @dev empty array pop
uint256 internal constant EMPTY_ARRAY_POP = 0x31;
/// @dev array out of bounds access
uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;
/// @dev resource error (too large allocation or too large array)
uint256 internal constant RESOURCE_ERROR = 0x41;
/// @dev calling invalid internal function
uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;
}Math, SignedMath
A branchless ternary function has been added to compute cond ? a : b at a constant gas cost.
SafeCast
The toUint(bool) function has been added to treat a bool as a uint256.
Structures
CircularBuffer
A data structure has been added to store the last N values inserted. This makes it easier to maintain a history.
DoubleEndedQueue
Custom errors have been replaced with native panic codes.
EnumerableMap
New enumerable mapping types have been added, including UintToBytes32Map, AddressToAddressMap, AddressToBytes32Map, and Bytes32ToAddressMap.
Heap
A data structure implementing a heap-based priority queue has been added.
MerkleTree
A data structure has been added for inserting elements into a Merkle tree and updating its root hash.
Further details
For more information about each change, see the following release notes.
Conclusion
This article summarized the changes in OpenZeppelin version 5.1.
I also publish content on the following platforms. Feel free to explore any articles that interest you.





