README.adoc 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. = Utilities
  2. [.readme-notice]
  3. NOTE: This document is better viewed at https://docs.openzeppelin.com/contracts/api/utils
  4. Miscellaneous contracts and libraries containing utility functions you can use to improve security, work with new data types, or safely use low-level primitives.
  5. * {Math}, {SignedMath}: Implementation of various arithmetic functions.
  6. * {SafeCast}: Checked downcasting functions to avoid silent truncation.
  7. * {ECDSA}, {MessageHashUtils}: Libraries for interacting with ECDSA signatures.
  8. * {P256}: Library for verifying and recovering public keys from secp256r1 signatures.
  9. * {RSA}: Library with RSA PKCS#1 v1.5 signature verification utilities.
  10. * {SignatureChecker}: A library helper to support regular ECDSA from EOAs as well as ERC-1271 signatures for smart contracts.
  11. * {Hashes}: Commonly used hash functions.
  12. * {MerkleProof}: Functions for verifying https://en.wikipedia.org/wiki/Merkle_tree[Merkle Tree] proofs.
  13. * {EIP712}: Contract with functions to allow processing signed typed structure data according to https://eips.ethereum.org/EIPS/eip-712[EIP-712].
  14. * {ReentrancyGuard}: A modifier that can prevent reentrancy during certain functions.
  15. * {ReentrancyGuardTransient}: Variant of {ReentrancyGuard} that uses transient storage (https://eips.ethereum.org/EIPS/eip-1153[EIP-1153]).
  16. * {Pausable}: A common emergency response mechanism that can pause functionality while a remediation is pending.
  17. * {Nonces}: Utility for tracking and verifying address nonces that only increment.
  18. * {NoncesKeyed}: Alternative to {Nonces}, that support keyed nonces following https://eips.ethereum.org/EIPS/eip-4337#semi-abstracted-nonce-support[ERC-4337 specifications].
  19. * {ERC165}, {ERC165Checker}: Utilities for inspecting interfaces supported by contracts.
  20. * {BitMaps}: A simple library to manage boolean value mapped to a numerical index in an efficient way.
  21. * {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`).
  22. * {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.
  23. * {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.
  24. * {CircularBuffer}: A data structure to store the last N values pushed to it.
  25. * {Checkpoints}: A data structure to store values mapped to a strictly increasing key. Can be used for storing and accessing values over time.
  26. * {Heap}: A library that implements a https://en.wikipedia.org/wiki/Binary_heap[binary heap] in storage.
  27. * {MerkleTree}: A library with https://wikipedia.org/wiki/Merkle_Tree[Merkle Tree] data structures and helper functions.
  28. * {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.
  29. * {Address}: Collection of functions for overloading Solidity's https://docs.soliditylang.org/en/latest/types.html#address[`address`] type.
  30. * {Arrays}: Collection of functions that operate on https://docs.soliditylang.org/en/latest/types.html#arrays[`arrays`].
  31. * {Base64}: On-chain base64 and base64URL encoding according to https://datatracker.ietf.org/doc/html/rfc4648[RFC-4648].
  32. * {Bytes}: Common operations on bytes objects.
  33. * {Calldata}: Helpers for manipulating calldata.
  34. * {Strings}: Common operations for strings formatting.
  35. * {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.
  36. * {SlotDerivation}: Methods for deriving storage slot from ERC-7201 namespaces as well as from constructions such as mapping and arrays.
  37. * {StorageSlot}: Methods for accessing specific storage slots formatted as common primitive types.
  38. * {TransientSlot}: Primitives for reading from and writing to transient storage (only value types are currently supported).
  39. * {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.
  40. * {Context}: A utility for abstracting the sender and calldata in the current execution context.
  41. * {Packing}: A library for packing and unpacking multiple values into bytes32
  42. * {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].
  43. * {Comparators}: A library that contains comparator functions to use with the {Heap} library.
  44. * {CAIP2}, {CAIP10}: Libraries for formatting and parsing CAIP-2 and CAIP-10 identifiers.
  45. [NOTE]
  46. ====
  47. Because Solidity does not support generic types, {EnumerableMap} and {EnumerableSet} are specialized to a limited number of key-value types.
  48. ====
  49. == Math
  50. {{Math}}
  51. {{SignedMath}}
  52. {{SafeCast}}
  53. == Cryptography
  54. {{ECDSA}}
  55. {{P256}}
  56. {{RSA}}
  57. {{EIP712}}
  58. {{MessageHashUtils}}
  59. {{SignatureChecker}}
  60. {{Hashes}}
  61. {{MerkleProof}}
  62. == Security
  63. {{ReentrancyGuard}}
  64. {{ReentrancyGuardTransient}}
  65. {{Pausable}}
  66. {{Nonces}}
  67. {{NoncesKeyed}}
  68. == Introspection
  69. 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_.
  70. 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.
  71. {{IERC165}}
  72. {{ERC165}}
  73. {{ERC165Checker}}
  74. == Data Structures
  75. {{BitMaps}}
  76. {{EnumerableMap}}
  77. {{EnumerableSet}}
  78. {{DoubleEndedQueue}}
  79. {{CircularBuffer}}
  80. {{Checkpoints}}
  81. {{Heap}}
  82. {{MerkleTree}}
  83. == Libraries
  84. {{Create2}}
  85. {{Address}}
  86. {{Arrays}}
  87. {{Base64}}
  88. {{Bytes}}
  89. {{Calldata}}
  90. {{Strings}}
  91. {{ShortStrings}}
  92. {{SlotDerivation}}
  93. {{StorageSlot}}
  94. {{TransientSlot}}
  95. {{Multicall}}
  96. {{Context}}
  97. {{Packing}}
  98. {{Panic}}
  99. {{Comparators}}
  100. {{CAIP2}}
  101. {{CAIP10}}