Skip to content

Commit

Permalink
Merge branch 'master' into feature/SignatureChecker
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx committed Mar 15, 2021
2 parents e661c0a + d519472 commit dd12291
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 161 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,7 @@

* `IERC20Metadata`: add a new extended interface that includes the optional `name()`, `symbol()` and `decimals()` functions. ([#2561](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2561))
* `ERC777`: make reception acquirement optional in `_mint`. ([#2552](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2552))
* `ERC20Permit`: add a `_useNonce` to enable further usage of ERC712 signatures. ([#2565](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2565))
* `SignatureChecker`: add a signature verification library that supports both EOA and ERC1271 compliant contracts as signers. ([#2532](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2532))

## Unreleased
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/ERC20/ERC20.sol
Expand Up @@ -46,7 +46,7 @@ contract ERC20 is Context, IERC20, IERC20Metadata {
* The defaut value of {decimals} is 18. To select a different value for
* {decimals} you should overload it.
*
* All three of these values are immutable: they can only be set once during
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name_, string memory symbol_) {
Expand Down
14 changes: 11 additions & 3 deletions contracts/token/ERC20/extensions/draft-ERC20Permit.sol
Expand Up @@ -47,7 +47,7 @@ abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 {
owner,
spender,
value,
_nonces[owner].current(),
_useNonce(owner),
deadline
)
);
Expand All @@ -57,14 +57,13 @@ abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 {
address signer = ECDSA.recover(hash, v, r, s);
require(signer == owner, "ERC20Permit: invalid signature");

_nonces[owner].increment();
_approve(owner, spender, value);
}

/**
* @dev See {IERC20Permit-nonces}.
*/
function nonces(address owner) public view override returns (uint256) {
function nonces(address owner) public view virtual override returns (uint256) {
return _nonces[owner].current();
}

Expand All @@ -75,4 +74,13 @@ abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 {
function DOMAIN_SEPARATOR() external view override returns (bytes32) {
return _domainSeparatorV4();
}

/**
* @dev "Consume a nonce": return the current value and increment.
*/
function _useNonce(address owner) internal virtual returns (uint256 current) {
Counters.Counter storage nonce = _nonces[owner];
current = nonce.current();
nonce.increment();
}
}
8 changes: 4 additions & 4 deletions contracts/token/ERC20/extensions/draft-IERC20Permit.sol
Expand Up @@ -7,13 +7,13 @@ pragma solidity ^0.8.0;
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over `owner`'s tokens,
* given `owner`'s signed approval.
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
Expand Down Expand Up @@ -44,7 +44,7 @@ interface IERC20Permit {
function nonces(address owner) external view returns (uint256);

/**
* @dev Returns the domain separator used in the encoding of the signature for `permit`, as defined by {EIP712}.
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
Expand Down
8 changes: 7 additions & 1 deletion contracts/utils/cryptography/MerkleProof.sol
Expand Up @@ -3,7 +3,13 @@
pragma solidity ^0.8.0;

/**
* @dev These functions deal with verification of Merkle trees (hash trees),
* @dev These functions deal with verification of Merkle Trees proofs.
*
* The proofs can be generated using the JavaScript library
* https://github.com/miguelmota/merkletreejs[merkletreejs].
* Note: the hashing algorithm should be keccak256 and pair sorting should be enabled.
*
* See `test/utils/cryptography/MerkleProof.test.js` for some examples.
*/
library MerkleProof {
/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/utils/structs/EnumerableSet.sol
Expand Up @@ -89,7 +89,7 @@ library EnumerableSet {
// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastvalue;
// Update the index for the moved value
set._indexes[lastvalue] = toDeleteIndex + 1; // All indexes are 1-based
set._indexes[lastvalue] = valueIndex; // Replace lastvalue's index to valueIndex

// Delete the slot where the moved value was stored
set._values.pop();
Expand Down
173 changes: 172 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -66,15 +66,16 @@
"ethereumjs-wallet": "^1.0.1",
"hardhat": "^2.0.6",
"hardhat-gas-reporter": "^1.0.4",
"keccak256": "^1.0.2",
"lodash.startcase": "^4.4.0",
"lodash.zip": "^4.2.0",
"merkletreejs": "^0.2.13",
"micromatch": "^4.0.2",
"mocha": "^8.0.1",
"rimraf": "^3.0.2",
"solhint": "^3.2.0",
"solidity-coverage": "^0.7.11",
"solidity-docgen": "^0.5.3",
"web3": "^1.3.0"
},
"dependencies": {}
}
}

0 comments on commit dd12291

Please sign in to comment.