Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

NoncesKeyedUpgradeable

Inherits: Initializable, NoncesUpgradeable

Alternative to {Nonces}, that supports key-ed nonces. Follows the https://eips.ethereum.org/EIPS/eip-4337#semi-abstracted-nonce-support[ERC-4337's semi-abstracted nonce system]. NOTE: This contract inherits from {Nonces} and reuses its storage for the first nonce key (i.e. 0). This makes upgrading from {Nonces} to {NoncesKeyed} safe when using their upgradeable versions (e.g. NoncesKeyedUpgradeable). Doing so will NOT reset the current state of nonces, avoiding replay attacks where a nonce is reused after the upgrade.

State Variables

NoncesKeyedStorageLocation

bytes32 private constant NoncesKeyedStorageLocation = 0x06e302b11020b9cca26edb75da0d4c952e2c49f7ac00d8954230e81bd5769c00;

Functions

_getNoncesKeyedStorage

function _getNoncesKeyedStorage() private pure returns (NoncesKeyedStorage storage $);

__NoncesKeyed_init

function __NoncesKeyed_init() internal onlyInitializing;

__NoncesKeyed_init_unchained

function __NoncesKeyed_init_unchained() internal onlyInitializing;

nonces

Returns the next unused nonce for an address and key. Result contains the key prefix.

function nonces(address owner, uint192 key) public view virtual returns (uint256);

_useNonce

Consumes the next unused nonce for an address and key. Returns the current value without the key prefix. Consumed nonce is increased, so calling this function twice with the same arguments will return different (sequential) results.

function _useNonce(address owner, uint192 key) internal virtual returns (uint256);

_useCheckedNonce

*Same as _useNonce but checking that nonce is the next valid for owner. This version takes the key and the nonce in a single uint256 parameter:

  • use the first 24 bytes for the key
  • use the last 8 bytes for the nonce*
function _useCheckedNonce(address owner, uint256 keyNonce) internal virtual override;

_useCheckedNonce

Same as _useNonce but checking that nonce is the next valid for owner. This version takes the key and the nonce as two different parameters.

function _useCheckedNonce(address owner, uint192 key, uint64 nonce) internal virtual;

_pack

Pack key and nonce into a keyNonce

function _pack(uint192 key, uint64 nonce) private pure returns (uint256);

_unpack

Unpack a keyNonce into its key and nonce components

function _unpack(uint256 keyNonce) private pure returns (uint192 key, uint64 nonce);

Structs

NoncesKeyedStorage

Note: storage-location: erc7201:openzeppelin.storage.NoncesKeyed

struct NoncesKeyedStorage {
    mapping(address owner => mapping(uint192 key => uint64)) _nonces;
}