Introducing OpenZeppelin Contracts v5.1

We are excited to release Contracts 5.1, one of our largest minor releases with more than 40+ changelog entries. This new version pushes the boundaries of cryptography, data structures, and utilities for developers to innovate in smart contract development. 

Contracts 5.1 marks the beginning of several exciting roadmap initiatives, including account abstraction and cross-chain libraries. These advancements will empower developers to create more dynamic and innovative on-chain applications.

In addition, this release enhances and extends the functionality of libraries introduced in earlier versions.

https://github.com/OpenZeppelin/openzeppelin-contracts/releases/tag/v5.1.0

What’s New

  • New cryptographic primitives for smart contracts and smart accounts
  • Added a new MerkleTree contract and updated our Merkle Tree Typescript library to support custom hashing functions
  • More data structures optimized for the upcoming Verkle EVM transition and other use cases
  • Added new token standards like ERC1363 to expand ERC20 capabilities
  • New transient storage utilities; including ERC20TemporaryAllowance and ReentrancyGuardTransient

Efficient and secure cryptography

Given the rising demand for new cryptographic primitives among the development community, OpenZeppelin Contracts is incorporating well-known algorithms that enable builders to create applications on top of real-world infrastructure.

Some examples of these use cases include enhancing Account Abstraction using consumer hardware (e.g. Apple’s Secure Enclave), developing ZK applications, or using corporate Public Key Infrastructure (PKIs) in smart contracts.

Among the new contracts, users can find the P256 and RSA libraries for signature validation, a new MerkleTree library to construct on-chain trees, and an updated MerkleProof library with support for custom hash functions.

Codigo 1

codigo 2

Unique data structures

This release brings significant advancements in data structures with enhanced performance and functionality. One key addition is the MerkleTree library, a cryptographic structure supporting custom hashing algorithms for efficient verification of large data sets, giving developers greater flexibility in complex verification processes. We’ve also updated the merkle-tree library to integrate this new structure.

The new CircularBuffer enables constant-time insertion and deletion in fixed-size queues, making it ideal for tracking recent events or managing time-sensitive data with minimal gas costs, especially in DeFi applications. Additionally, the Heap structure optimizes priority-based tasks, making it useful for auctions or gas optimization where dynamic ordering is essential.

codigo 3

carbon-6

The EnumerableMap utility has also been improved for better gas efficiency and compatibility with Ethereum’s future upgrades, such as the Verkle tree structure.

Cutting-edge utilities

This release introduces new cutting-edge utilities, leveraging the latest Ethereum upgrades. The new StorageSlot utility provides helpers for temporary storage slots, offering greater flexibility by enabling the management of ephemeral data without the need for long-term storage. Complementing this, the Packing utility optimizes data storage by tightly packing variables, reducing gas costs and improving contract efficiency. ReentrancyGuardTransient offers a more gas efficient approach to ReentrancyGuard using transient storage. Additionally, SlotDerivation simplifies the process of deriving storage slots, streamlining storage management.

codigo 5

Several existing utilities have also been refined for better performance and usability. Arrays have been updated with additional methods for easier manipulation and access. Base64 encoding has been optimized and the CREATE2 function, essential for deploying contracts at predictable addresses, has been improved to clean dirty addresses. Meanwhile, Strings and Math libraries have been enhanced to offer more robust and efficient operations, including new functions like invMod, modExp, ternary, and toChecksumHexString

What’s Next

We're already working on our next release, Contracts 5.2, which will introduce initial frameworks for both account abstraction and cross-chain development. As always, security is our top priority, and we'll continue to evolve and improve our internal and external testing processes.

Here’s how you can get involved with the latest improvements to the most trusted smart contract libraries: