Skip to content

Commit

Permalink
Merge pull request #16 from thesis/compliance
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
nkuba authored Sep 6, 2022
2 parents 0aa49a2 + e1f1419 commit 79f658f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions contracts/token/ERC20WithPermit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ contract ERC20WithPermit is IERC20WithPermit, Ownable {
/// @notice Returns the current nonce for EIP2612 permission for the
/// provided token owner for a replay protection. Used to construct
/// EIP2612 signature provided to `permit` function.
mapping(address => uint256) public override nonce;
mapping(address => uint256) public override nonces;

uint256 public immutable cachedChainId;
bytes32 public immutable cachedDomainSeparator;
Expand Down Expand Up @@ -141,7 +141,7 @@ contract ERC20WithPermit is IERC20WithPermit, Ownable {
owner,
spender,
amount,
nonce[owner]++,
nonces[owner]++,
deadline
)
)
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/IERC20WithPermit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ interface IERC20WithPermit is IERC20, IERC20Metadata, IApproveAndCall {
/// @notice Returns the current nonce for EIP2612 permission for the
/// provided token owner for a replay protection. Used to construct
/// EIP2612 signature provided to `permit` function.
function nonce(address owner) external view returns (uint256);
function nonces(address owner) external view returns (uint256);

/// @notice Returns EIP2612 Permit message hash. Used to construct EIP2612
/// signature provided to `permit` function.
Expand Down
10 changes: 5 additions & 5 deletions test/token/ERC20WithPermit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ describe("ERC20WithPermit", () => {

const domainSeparator = await token.DOMAIN_SEPARATOR()
const permitTypehash = await token.PERMIT_TYPEHASH()
const nonce = await token.nonce(permittingHolder.address)
const nonce = await token.nonces(permittingHolder.address)

const approvalDigest = ethers.utils.keccak256(
ethers.utils.solidityPack(
Expand Down Expand Up @@ -1101,7 +1101,7 @@ describe("ERC20WithPermit", () => {
deadline
)

const initialNonce = await token.nonce(permittingHolder.address)
const initialNonce = await token.nonces(permittingHolder.address)

await token
.connect(anotherAccount)
Expand All @@ -1115,11 +1115,11 @@ describe("ERC20WithPermit", () => {
signature.s
)

expect(await token.nonce(permittingHolder.address)).to.equal(
expect(await token.nonces(permittingHolder.address)).to.equal(
initialNonce.add(1)
)
expect(await token.nonce(anotherAccount.address)).to.equal(0)
expect(await token.nonce(recipient.address)).to.equal(0)
expect(await token.nonces(anotherAccount.address)).to.equal(0)
expect(await token.nonces(recipient.address)).to.equal(0)
})

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

0 comments on commit 79f658f

Please sign in to comment.