Skip to content

Commit

Permalink
Fix up nonce comments; allow type(uint96).max as nonce (#98)
Browse files Browse the repository at this point in the history
Change comments now that 0 nonce is a valid nonce. We also allow type(uint96).max to be returned as a nonce in `nextNonce`.
  • Loading branch information
kevincheng96 authored Nov 27, 2023
1 parent e231c9b commit 05b94db
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/QuarkStateManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ contract QuarkStateManager {

/**
* @notice Return whether a nonce has been exhausted; note that if a nonce is not set, that does not mean it has not been used before
* @dev `0` is not a valid nonce
* @param wallet Address of the wallet owning the nonce
* @param nonce Nonce to check
* @return Whether the nonce has been exhausted
Expand All @@ -57,14 +56,14 @@ contract QuarkStateManager {
}

/**
* @notice Returns the next valid unset nonce for a given wallet (note that 0 is not a valid nonce)
* @dev Any unset nonce > 0 is valid to use, but using this method
* @notice Returns the next valid unset nonce for a given wallet
* @dev Any unset nonce is valid to use, but using this method
* increases the likelihood that the nonce you use will be in a bucket that
* has already been written to, which costs less gas
* @return The next unused nonce
*/
function nextNonce(address wallet) external view returns (uint96) {
for (uint96 i = 0; i < type(uint96).max;) {
for (uint96 i = 0; i <= type(uint96).max;) {
if (!isNonceSet(wallet, i) && (nonceScriptAddress[wallet][i] == address(0))) {
return i;
}
Expand Down

0 comments on commit 05b94db

Please sign in to comment.