Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an internal _useNonce(address) function in ERC20Permit #2565

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
_incrementNonces → _useNonce
Amxx committed Mar 10, 2021
commit 23619af5954bc21f08c1f38fdff39bbd1c659c7f
11 changes: 6 additions & 5 deletions contracts/token/ERC20/extensions/draft-ERC20Permit.sol
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 {
owner,
spender,
value,
nonces(owner),
_useNonce(owner),
deadline
)
);
@@ -57,7 +57,6 @@ abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 {
address signer = ECDSA.recover(hash, v, r, s);
require(signer == owner, "ERC20Permit: invalid signature");

_incrementNonces(owner);
_approve(owner, spender, value);
}

@@ -77,9 +76,11 @@ abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 {
}

/**
* @dev internal: increment the nonce of a user.
* @dev "Consume a nonce": return the current value and increment.
*/
function _incrementNonces(address owner) internal virtual {
_nonces[owner].increment();
function _useNonce(address owner) internal virtual returns (uint256 current) {
Counters.Counter storage nonce = _nonces[owner];
current = nonce.current();
nonce.increment();
}
}