Ernesto García 53bb34057e Fix ERC165Checker detection (#5880) 1 month ago
..
cryptography 519184ce6b Configure Foundry linter (#5859) 1 month ago
introspection 53bb34057e Fix ERC165Checker detection (#5880) 1 month ago
math d66a0ce63f Add new `clz(bytes)` and `clz(uint256)` functions (#5725) 2 months ago
structs 448538259f Merge release-v5.4 branch (#5802) 2 months ago
types 0034c30224 Merge release-v5.1 branch (#5266) 11 months ago
Address.sol 448538259f Merge release-v5.4 branch (#5802) 2 months ago
Arrays.sol 448538259f Merge release-v5.4 branch (#5802) 2 months ago
Base64.sol 448538259f Merge release-v5.4 branch (#5802) 2 months ago
Blockhash.sol 448538259f Merge release-v5.4 branch (#5802) 2 months ago
Bytes.sol 005c9c9fa7 Add Bytes.concat (#5882) 1 month ago
CAIP10.sol 7b74442c5e Merge release-v5.2 branch (#5424) 9 months ago
CAIP2.sol 7b74442c5e Merge release-v5.2 branch (#5424) 9 months ago
Calldata.sol d183d9b07a Merge release-v5.3 branch (#5632) 6 months ago
Comparators.sol 0034c30224 Merge release-v5.1 branch (#5266) 11 months ago
Context.sol 6ba452dea4 Merge release-v5.0 branch (#4787) 1 year ago
Create2.sol 0034c30224 Merge release-v5.1 branch (#5266) 11 months ago
Errors.sol 0034c30224 Merge release-v5.1 branch (#5266) 11 months ago
Memory.sol 21cd7e8aa3 Add `Memory` utility library (#5189) 2 months ago
Multicall.sol d183d9b07a Merge release-v5.3 branch (#5632) 6 months ago
Nonces.sol 3e6c86392c Merge release-v5.0 branch (#4665) 2 years ago
NoncesKeyed.sol 7b74442c5e Merge release-v5.2 branch (#5424) 9 months ago
Packing.sol 7b74442c5e Merge release-v5.2 branch (#5424) 9 months ago
Panic.sol 0034c30224 Merge release-v5.1 branch (#5266) 11 months ago
Pausable.sol d183d9b07a Merge release-v5.3 branch (#5632) 6 months ago
README.adoc 21cd7e8aa3 Add `Memory` utility library (#5189) 2 months ago
ReentrancyGuard.sol 0134b00956 Add nonReentrantView modifier (#5800) 1 month ago
ReentrancyGuardTransient.sol 0134b00956 Add nonReentrantView modifier (#5800) 1 month ago
ShortStrings.sol d183d9b07a Merge release-v5.3 branch (#5632) 6 months ago
SlotDerivation.sol d183d9b07a Merge release-v5.3 branch (#5632) 6 months ago
StorageSlot.sol 0034c30224 Merge release-v5.1 branch (#5266) 11 months ago
Strings.sol 32e7a6ffbc Add `equal` to Bytes.sol and update pragma to 0.8.24 in String dependencies (#5726) 2 months ago
TransientSlot.sol d183d9b07a Merge release-v5.3 branch (#5632) 6 months ago
draft-InteroperableAddress.sol 2909098755 ERC-7930 (#5736) 3 months ago

README.adoc

= Utilities

[.readme-notice]
NOTE: This document is better viewed at https://docs.openzeppelin.com/contracts/api/utils

Miscellaneous contracts and libraries containing utility functions you can use to improve security, work with new data types, or safely use low-level primitives.

* {Math}, {SignedMath}: Implementation of various arithmetic functions.
* {SafeCast}: Checked downcasting functions to avoid silent truncation.
* {ReentrancyGuard}: A modifier that can prevent reentrancy during certain functions.
* {ReentrancyGuardTransient}: Variant of {ReentrancyGuard} that uses transient storage (https://eips.ethereum.org/EIPS/eip-1153[EIP-1153]).
* {Pausable}: A common emergency response mechanism that can pause functionality while a remediation is pending.
* {Nonces}: Utility for tracking and verifying address nonces that only increment.
* {NoncesKeyed}: Alternative to {Nonces}, that support keyed nonces following https://eips.ethereum.org/EIPS/eip-4337#semi-abstracted-nonce-support[ERC-4337 specifications].
* {ERC165}, {ERC165Checker}: Utilities for inspecting interfaces supported by contracts.
* {BitMaps}: A simple library to manage boolean value mapped to a numerical index in an efficient way.
* {EnumerableMap}: A type like Solidity's https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`], but with key-value _enumeration_: this will let you know how many entries a mapping has, and iterate over them (which is not possible with `mapping`).
* {EnumerableSet}: Like {EnumerableMap}, but for https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets]. Can be used to store privileged accounts, issued IDs, etc.
* {DoubleEndedQueue}: An implementation of a https://en.wikipedia.org/wiki/Double-ended_queue[double ended queue] whose values can be added or removed from both sides. Useful for FIFO and LIFO structures.
* {CircularBuffer}: A data structure to store the last N values pushed to it.
* {Checkpoints}: A data structure to store values mapped to a strictly increasing key. Can be used for storing and accessing values over time.
* {Heap}: A library that implements a https://en.wikipedia.org/wiki/Binary_heap[binary heap] in storage.
* {MerkleTree}: A library with https://wikipedia.org/wiki/Merkle_Tree[Merkle Tree] data structures and helper functions.
* {Create2}: Wrapper around the https://blog.openzeppelin.com/getting-the-most-out-of-create2/[`CREATE2` EVM opcode] for safe use without having to deal with low-level assembly.
* {Address}: Collection of functions for overloading Solidity's https://docs.soliditylang.org/en/latest/types.html#address[`address`] type.
* {Arrays}: Collection of functions that operate on https://docs.soliditylang.org/en/latest/types.html#arrays[`arrays`].
* {Base64}: On-chain base64 and base64URL encoding according to https://datatracker.ietf.org/doc/html/rfc4648[RFC-4648].
* {Bytes}: Common operations on bytes objects.
* {Calldata}: Helpers for manipulating calldata.
* {Strings}: Common operations for strings formatting.
* {ShortStrings}: Library to encode (and decode) short strings into (or from) a single bytes32 slot for optimizing costs. Short strings are limited to 31 characters.
* {SlotDerivation}: Methods for deriving storage slot from ERC-7201 namespaces as well as from constructions such as mapping and arrays.
* {StorageSlot}: Methods for accessing specific storage slots formatted as common primitive types.
* {TransientSlot}: Primitives for reading from and writing to transient storage (only value types are currently supported).
* {Multicall}: Abstract contract with a utility to allow batching together multiple calls in a single transaction. Useful for allowing EOAs to perform multiple operations at once.
* {Context}: A utility for abstracting the sender and calldata in the current execution context.
* {Packing}: A library for packing and unpacking multiple values into bytes32
* {Panic}: A library to revert with https://docs.soliditylang.org/en/v0.8.20/control-structures.html#panic-via-assert-and-error-via-require[Solidity panic codes].
* {Comparators}: A library that contains comparator functions to use with the {Heap} library.
* {CAIP2}, {CAIP10}: Libraries for formatting and parsing CAIP-2 and CAIP-10 identifiers.
* {Memory}: A utility library to manipulate memory.
* {InteroperableAddress}: Library for formatting and parsing ERC-7930 interoperable addresses.
* {Blockhash}: A library for accessing historical block hashes beyond the standard 256 block limit utilizing EIP-2935's historical blockhash functionality.
* {Time}: A library that provides helpers for manipulating time-related objects, including a `Delay` type.

[NOTE]
====
Because Solidity does not support generic types, {EnumerableMap} and {EnumerableSet} are specialized to a limited number of key-value types.
====

== Math

{{Math}}

{{SignedMath}}

{{SafeCast}}

== Security

{{ReentrancyGuard}}

{{ReentrancyGuardTransient}}

{{Pausable}}

{{Nonces}}

{{NoncesKeyed}}

== Introspection

This set of interfaces and contracts deal with https://en.wikipedia.org/wiki/Type_introspection[type introspection] of contracts, that is, examining which functions can be called on them. This is usually referred to as a contract's _interface_.

Ethereum contracts have no native concept of an interface, so applications must usually simply trust they are not making an incorrect call. For trusted setups this is a non-issue, but often unknown and untrusted third-party addresses need to be interacted with. There may even not be any direct calls to them! (e.g. ERC-20 tokens may be sent to a contract that lacks a way to transfer them out of it, locking them forever). In these cases, a contract _declaring_ its interface can be very helpful in preventing errors.

{{IERC165}}

{{ERC165}}

{{ERC165Checker}}

== Data Structures

{{BitMaps}}

{{EnumerableMap}}

{{EnumerableSet}}

{{DoubleEndedQueue}}

{{CircularBuffer}}

{{Checkpoints}}

{{Heap}}

{{MerkleTree}}

== Libraries

{{Create2}}

{{Address}}

{{Arrays}}

{{Base64}}

{{Bytes}}

{{Calldata}}

{{Strings}}

{{ShortStrings}}

{{SlotDerivation}}

{{StorageSlot}}

{{TransientSlot}}

{{Multicall}}

{{Context}}

{{Packing}}

{{Panic}}

{{Comparators}}

{{CAIP2}}

{{CAIP10}}

{{Memory}}

{{InteroperableAddress}}

{{Blockhash}}

{{Time}}