INonceHolder

Git Source

Author: Matter Labs

Interface of the nonce holder contract -- a contract used by the system to ensure that there is always a unique identifier for a transaction with a particular account (we call it nonce). In other words, the pair of (address, nonce) should always be unique.

Custom accounts should use methods of this contract to store nonces or other possible unique identifiers for the transaction.

Note: security-contact: security@matterlabs.dev

Functions

getMinNonce

Returns the current minimal nonce for account.

function getMinNonce(address _address) external view returns (uint256);

Parameters

NameTypeDescription
_addressaddressThe account to return the minimal nonce for

Returns

NameTypeDescription
<none>uint256The current minimal nonce for this account.

getKeyedNonce

Returns the current keyed nonce for account given its nonce key.

function getKeyedNonce(address _address, uint192 _key)
  external
  view
  returns (uint256);

Parameters

NameTypeDescription
_addressaddressThe account to return the nonce for.
_keyuint192The key of the nonce to return.

Returns

NameTypeDescription
<none>uint256The current keyed nonce with the given key for this account. Returns the full nonce (including the provided key), not just the nonce value.

getRawNonce

Returns the raw version of the current minimal nonce

It is equal to minNonce + 2^128 * deployment nonce.

function getRawNonce(address _address) external view returns (uint256);

Parameters

NameTypeDescription
_addressaddressThe account to return the raw nonce for

Returns

NameTypeDescription
<none>uint256The raw nonce for this account.

increaseMinNonce

Increases the minimal nonce for the msg.sender and returns the previous one.

function increaseMinNonce(uint256 _value) external returns (uint256);

Parameters

NameTypeDescription
_valueuint256The number by which to increase the minimal nonce for msg.sender.

Returns

NameTypeDescription
<none>uint256oldMinNonce The value of the minimal nonce for msg.sender before the increase.

setValueUnderNonce

Sets the nonce value key as used.

function setValueUnderNonce(uint256 _key, uint256 _value) external;

getValueUnderNonce

Gets the value stored inside a custom nonce.

function getValueUnderNonce(uint256 _key) external view returns (uint256);

incrementMinNonceIfEquals

A convenience method to increment the minimal nonce if it is equal to the _expectedNonce.

This function only increments minNonce for nonces with nonceKey == 0. AAs that try to use this method with a keyed nonce will revert. For keyed nonces, incrementMinNonceIfEqualsKeyed should be used. This is to prevent DefaultAccount and other deployed AAs from unintentionally allowing keyed nonces to be used.

function incrementMinNonceIfEquals(uint256 _expectedNonce) external;

Parameters

NameTypeDescription
_expectedNonceuint256The expected minimal nonce for the account.

incrementMinNonceIfEqualsKeyed

A convenience method to increment the minimal nonce if it is equal to the _expectedNonce. This is a keyed counterpart to incrementMinNonceIfEquals.

Reverts for nonces with nonceKey == 0.

function incrementMinNonceIfEqualsKeyed(uint256 _expectedNonce) external;

Parameters

NameTypeDescription
_expectedNonceuint256The expected minimal nonce for the account.

getDeploymentNonce

Returns the deployment nonce for the accounts used for CREATE opcode.

function getDeploymentNonce(address _address) external view returns (uint256);

Parameters

NameTypeDescription
_addressaddressThe address to return the deploy nonce of.

Returns

NameTypeDescription
<none>uint256deploymentNonce The deployment nonce of the account.

incrementDeploymentNonce

Increments the deployment nonce for the account and returns the previous one.

function incrementDeploymentNonce(address _address) external returns (uint256);

Parameters

NameTypeDescription
_addressaddressThe address of the account which to return the deploy nonce for.

Returns

NameTypeDescription
<none>uint256prevDeploymentNonce The deployment nonce at the time this function is called.

validateNonceUsage

Checks and reverts based on whether the nonce is used (or not used).

This method should be used by the bootloader.

function validateNonceUsage(address _address, uint256 _key, bool _shouldBeUsed)
  external
  view;

Parameters

NameTypeDescription
_addressaddressThe address the nonce of which is being checked.
_keyuint256The nonce value which is tested.
_shouldBeUsedboolThe flag for the method. If true, the method checks that whether this nonce is marked as used and reverts if this is not the case. If false, this method will check that the nonce has not been used yet, and revert otherwise.

isNonceUsed

Returns whether a nonce has been used for an account.

function isNonceUsed(address _address, uint256 _nonce)
  external
  view
  returns (bool);

Parameters

NameTypeDescription
_addressaddressThe address the nonce of which is being checked.
_nonceuint256The nonce value which is checked.

Returns

NameTypeDescription
<none>booltrue if the nonce has been used, false otherwise.

Events

ValueSetUnderNonce

event ValueSetUnderNonce(
  address indexed accountAddress, uint256 indexed key, uint256 value
);