Skip to content

Commit

Permalink
feat: nonces increment optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
deluca-mike committed Mar 1, 2024
1 parent 0da7d2f commit 865cdb0
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/ERC20Extended.sol
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@ abstract contract ERC20Extended is IERC20Extended, ERC3009 {
) internal virtual returns (bytes32 digest_) {
_revertIfExpired(deadline_);

uint256 nonce_ = nonces[owner_]; // Cache `nonce_` to stack.
_approve(owner_, spender_, amount_);

unchecked {
nonces[owner_] = nonce_ + 1; // Nonce realistically cannot overflow.
// Nonce realistically cannot overflow.
return
_getDigest(
keccak256(abi.encode(PERMIT_TYPEHASH, owner_, spender_, amount_, nonces[owner_]++, deadline_))
);
}

_approve(owner_, spender_, amount_);

return _getDigest(keccak256(abi.encode(PERMIT_TYPEHASH, owner_, spender_, amount_, nonce_, deadline_)));
}
}

0 comments on commit 865cdb0

Please sign in to comment.