INonceHolder
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
Name | Type | Description |
---|---|---|
_address | address | The account to return the minimal nonce for |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The 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
Name | Type | Description |
---|---|---|
_address | address | The account to return the nonce for. |
_key | uint192 | The key of the nonce to return. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The 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
Name | Type | Description |
---|---|---|
_address | address | The account to return the raw nonce for |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The 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
Name | Type | Description |
---|---|---|
_value | uint256 | The number by which to increase the minimal nonce for msg.sender. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | oldMinNonce 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
Name | Type | Description |
---|---|---|
_expectedNonce | uint256 | The 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
Name | Type | Description |
---|---|---|
_expectedNonce | uint256 | The 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
Name | Type | Description |
---|---|---|
_address | address | The address to return the deploy nonce of. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | deploymentNonce 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
Name | Type | Description |
---|---|---|
_address | address | The address of the account which to return the deploy nonce for. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | prevDeploymentNonce 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
Name | Type | Description |
---|---|---|
_address | address | The address the nonce of which is being checked. |
_key | uint256 | The nonce value which is tested. |
_shouldBeUsed | bool | The 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
Name | Type | Description |
---|---|---|
_address | address | The address the nonce of which is being checked. |
_nonce | uint256 | The nonce value which is checked. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | true if the nonce has been used, false otherwise. |
Events
ValueSetUnderNonce
event ValueSetUnderNonce(
address indexed accountAddress, uint256 indexed key, uint256 value
);