Skip to main content

NonceManager

The NonceManager contract is responsible for managing and validating nonces for both users and dApp signatories. It ensures the integrity and security of transactions by preventing replay attacks and maintaining the correct sequence of operations. By supporting both sequential and non-sequential nonce systems, the contract provides flexibility and robustness in handling various transaction scenarios within the protocol.

getUserNextNonce

function getUserNextNonce(address user, bool sequential) external view returns (uint256 nextNonce);

Description

Retrieves the next valid nonce for a specified user. Depending on the sequential flag, the function returns either the next sequential nonce or the next available non-sequential nonce. This ensures that transactions are processed in the correct order and that replay attacks are mitigated.

Parameters

NameTypeDescription
useraddressThe address of the user for whom to retrieve the next nonce.
sequentialboolIndicates whether to retrieve a sequential (true) or non-sequential (false) nonce.

Return Values

NameTypeDescription
nextNonceuint256The next valid nonce for the specified user.

Requirements

  • Valid User Address: The user address must be a valid Ethereum address.
  • Nonce Mode: The sequential flag must correctly indicate the desired nonce mode (sequential or non-sequential).

Usage Notes

  • Sequential Nonces: Useful for applications that require strict ordering of transactions, ensuring that each transaction is processed exactly once and in order.
  • Non-Sequential Nonces: Provides flexibility for applications that can handle out-of-order transactions, improving efficiency and scalability.

getUserNextNonSeqNonceAfter

function getUserNextNonSeqNonceAfter(address user, uint256 refNonce) external view returns (uint256);

Description

Fetches the next available non-sequential nonce for a user, starting the search after a specified reference nonce (refNonce). This function is particularly useful for users who operate in non-sequential nonce modes, allowing them to identify the next valid nonce without enforcing strict ordering.

Parameters

NameTypeDescription
useraddressThe address of the user for whom to retrieve the next nonce.
refNonceuint256The nonce from which to start searching for the next available nonce.

Return Values

NameTypeDescription
nonceuint256The next available non-sequential nonce after refNonce.

Requirements

  • Valid User Address: The user address must be a valid Ethereum address.
  • Reference Nonce: The refNonce must be a valid nonce that has been previously used or tracked.

Usage Notes

  • Nonce Tracking: Helps users efficiently manage their non-sequential nonces, especially in scenarios where transactions may not follow a strict order.
  • Replay Protection: Ensures that even in non-sequential modes, each nonce is unique and cannot be reused, maintaining transaction integrity.

getDAppNextNonce

function getDAppNextNonce(address dApp) external view returns (uint256 nextNonce);

Description

Retrieves the next valid sequential nonce for a specified dApp signatory. This function ensures that dApps operate with correctly ordered transactions, maintaining consistency and preventing replay attacks within the protocol.

Parameters

NameTypeDescription
dAppaddressThe address of the dApp signatory for whom to retrieve the next nonce.

Return Values

NameTypeDescription
nextNonceuint256The next valid sequential nonce for the specified dApp signatory.

Requirements

  • Valid dApp Address: The dApp address must be a valid Ethereum address representing a dApp signatory.
  • Sequential Mode: This function is exclusively for sequential nonce management; non-sequential modes are not supported for dApps.

Usage Notes

  • dApp Operations: Ensures that dApps perform operations in a strictly ordered manner, enhancing protocol reliability.
  • Security: Prevents dApps from executing duplicate or out-of-order transactions, safeguarding against potential replay attacks.

userSequentialNonceTrackers

function userSequentialNonceTrackers(address account) external view returns (uint256 lastUsedSeqNonce);

Description

Provides the last used sequential nonce for a specified user. This information is essential for determining the next valid nonce in sequential nonce modes, ensuring that transactions are processed in the correct order.

Parameters

NameTypeDescription
accountaddressThe address of the user for whom to retrieve the last used sequential nonce.

Return Values

NameTypeDescription
lastUsedSeqNonceuint256The last used sequential nonce for the specified user.

Usage Notes

  • Transaction Ordering: Helps in maintaining the correct sequence of transactions by providing the latest used nonce.
  • Nonce Management: Assists users and dApps in tracking and managing their nonce usage effectively.

dAppSequentialNonceTrackers

function dAppSequentialNonceTrackers(address account) external view returns (uint256 lastUsedSeqNonce);

Description

Retrieves the last used sequential nonce for a specified dApp signatory. This function is integral for maintaining the correct order of operations for dApps within the Atlas Protocol.

Parameters

NameTypeDescription
accountaddressThe address of the dApp signatory for whom to retrieve the last used sequential nonce.

Return Values

NameTypeDescription
lastUsedSeqNonceuint256The last used sequential nonce for the specified dApp signatory.

Usage Notes

  • dApp Transaction Management: Ensures that dApps process transactions in a strictly sequential manner, preventing out-of-order executions.
  • Protocol Security: Maintains the integrity of dApp operations by enforcing correct nonce usage, mitigating replay attacks.

userNonSequentialNonceTrackers

function userNonSequentialNonceTrackers(address account, uint248 wordIndex) external view returns (uint256 bitmap);

Description

Fetches the non-sequential nonce bitmap for a specific user and word index. The bitmap represents a set of used non-sequential nonces, allowing efficient tracking and validation of nonce usage without enforcing strict ordering.

Parameters

NameTypeDescription
accountaddressThe address of the user for whom to retrieve the nonce bitmap.
wordIndexuint248The index of the word within the nonce bitmap to query.

Return Values

NameTypeDescription
bitmapuint256The bitmap representing used non-sequential nonces for the specified user and word index.

Usage Notes

  • Efficient Tracking: Utilizes bitmaps to efficiently track non-sequential nonce usage, reducing storage requirements and enabling quick validations.
  • Nonce Validation: Facilitates the verification of nonce uniqueness without enforcing a strict sequence, enhancing flexibility for users.

Events Emitted

NonceManager does not emit any events. All nonce-related state changes and validations are handled internally within the contract, ensuring efficient and secure management without additional logging overhead.

Inherited External Functions

The NonceManager contract inherits from AtlasConstants. However, it does not inherit any external functions from this or any other parent contracts. Instead, it utilizes constants defined in AtlasConstants to manage nonce operations and validations.

From AtlasConstants

The AtlasConstants contract defines a set of constant values used throughout the Atlas Protocol. These constants ensure consistency and prevent the use of magic numbers within the codebase.

Functions: None

Usage Notes

  • Consistent Parameters: Constants from AtlasConstants provide standardized parameters that are used across various contracts within the protocol, promoting uniformity and reducing the risk of errors.
  • Maintainability: Centralizing constants simplifies updates and maintenance, as changes can be made in one location without affecting multiple contracts.

Conclusion

The NonceManager contract is an essential part of the Atlas Protocol, managing nonce validations and tracking for both users and dApp signatories. By supporting both sequential and non-sequential nonce systems, it offers flexibility and security, ensuring that all transactions are processed correctly and preventing replay attacks. The contract's external functions provide necessary interfaces for retrieving nonce information, facilitating efficient transaction management and enhancing the overall integrity of the protocol.

Key features include:

  • Support for both sequential and non-sequential nonce management
  • Efficient nonce tracking using bitmaps for non-sequential nonces
  • Separate nonce management for users and dApp signatories
  • Integration with protocol-wide constants for consistency and maintainability