Skip to content

Commit 79f658f

Browse files
authored
Merge pull request #16 from thesis/compliance
EIP-2612 compliance fix: n/nonce/nonces The ERC20WithPermit implements EIP-2612 but used mapping `nonce` (singular) instead of `nonces`. This might create an issue when third-party libraries (that support EIP-2612) try to interact with the token and assume that nonces are tracked with `nonces` instead of `nonce`. Fixed it by renaming `nonce` mapping to `nonces`.
2 parents 0aa49a2 + e1f1419 commit 79f658f

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

contracts/token/ERC20WithPermit.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ contract ERC20WithPermit is IERC20WithPermit, Ownable {
2727
/// @notice Returns the current nonce for EIP2612 permission for the
2828
/// provided token owner for a replay protection. Used to construct
2929
/// EIP2612 signature provided to `permit` function.
30-
mapping(address => uint256) public override nonce;
30+
mapping(address => uint256) public override nonces;
3131

3232
uint256 public immutable cachedChainId;
3333
bytes32 public immutable cachedDomainSeparator;
@@ -141,7 +141,7 @@ contract ERC20WithPermit is IERC20WithPermit, Ownable {
141141
owner,
142142
spender,
143143
amount,
144-
nonce[owner]++,
144+
nonces[owner]++,
145145
deadline
146146
)
147147
)

contracts/token/IERC20WithPermit.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ interface IERC20WithPermit is IERC20, IERC20Metadata, IApproveAndCall {
5151
/// @notice Returns the current nonce for EIP2612 permission for the
5252
/// provided token owner for a replay protection. Used to construct
5353
/// EIP2612 signature provided to `permit` function.
54-
function nonce(address owner) external view returns (uint256);
54+
function nonces(address owner) external view returns (uint256);
5555

5656
/// @notice Returns EIP2612 Permit message hash. Used to construct EIP2612
5757
/// signature provided to `permit` function.

test/token/ERC20WithPermit.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ describe("ERC20WithPermit", () => {
904904

905905
const domainSeparator = await token.DOMAIN_SEPARATOR()
906906
const permitTypehash = await token.PERMIT_TYPEHASH()
907-
const nonce = await token.nonce(permittingHolder.address)
907+
const nonce = await token.nonces(permittingHolder.address)
908908

909909
const approvalDigest = ethers.utils.keccak256(
910910
ethers.utils.solidityPack(
@@ -1101,7 +1101,7 @@ describe("ERC20WithPermit", () => {
11011101
deadline
11021102
)
11031103

1104-
const initialNonce = await token.nonce(permittingHolder.address)
1104+
const initialNonce = await token.nonces(permittingHolder.address)
11051105

11061106
await token
11071107
.connect(anotherAccount)
@@ -1115,11 +1115,11 @@ describe("ERC20WithPermit", () => {
11151115
signature.s
11161116
)
11171117

1118-
expect(await token.nonce(permittingHolder.address)).to.equal(
1118+
expect(await token.nonces(permittingHolder.address)).to.equal(
11191119
initialNonce.add(1)
11201120
)
1121-
expect(await token.nonce(anotherAccount.address)).to.equal(0)
1122-
expect(await token.nonce(recipient.address)).to.equal(0)
1121+
expect(await token.nonces(anotherAccount.address)).to.equal(0)
1122+
expect(await token.nonces(recipient.address)).to.equal(0)
11231123
})
11241124

11251125
context("when there was no approved amount before", () => {

0 commit comments

Comments
 (0)