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

chore: Standardization and cleanup #31

Merged
merged 3 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
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
20 changes: 11 additions & 9 deletions contracts/ERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ contract ERC20 is IERC20 {
/****************/

// PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 amount,uint256 nonce,uint256 deadline)");
bytes32 public constant override PERMIT_TYPEHASH = 0xfc77c2b9d30fe91687fd39abb7d16fcdfe1472d065740051ab8b13e4bf4a617f;
bytes32 public constant override PERMIT_TYPEHASH = bytes32(0xfc77c2b9d30fe91687fd39abb7d16fcdfe1472d065740051ab8b13e4bf4a617f);

mapping(address => uint256) public override nonces;

Expand Down Expand Up @@ -63,14 +63,14 @@ contract ERC20 is IERC20 {
return true;
}

function permit(address owner, address spender, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external override {
require(deadline >= block.timestamp, "ERC20:P:EXPIRED");
function permit(address owner_, address spender_, uint256 amount_, uint256 deadline_, uint8 v_, bytes32 r_, bytes32 s_) external override {
require(deadline_ >= block.timestamp, "ERC20:P:EXPIRED");

// Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}.
require(
uint256(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0 &&
(v == 27 || v == 28),
uint256(s_) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0 &&
Copy link
Contributor

@vbidin vbidin Mar 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also mark the limit explicitly as a uint256.

(v_ == 27 || v_ == 28),
"ERC20:P:MALLEABLE"
);

Expand All @@ -80,14 +80,16 @@ contract ERC20 is IERC20 {
abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR(),
keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, amount, nonces[owner]++, deadline))
keccak256(abi.encode(PERMIT_TYPEHASH, owner_, spender_, amount_, nonces[owner_]++, deadline_))
)
);
address recoveredAddress = ecrecover(digest, v, r, s);
require(recoveredAddress == owner && owner != address(0), "ERC20:P:INVALID_SIGNATURE");

address recoveredAddress = ecrecover(digest, v_, r_, s_);

require(recoveredAddress == owner_ && owner_ != address(0), "ERC20:P:INVALID_SIGNATURE");
}

_approve(owner, spender, amount);
_approve(owner_, spender_, amount_);
}

function transfer(address recipient_, uint256 amount_) external override returns (bool success_) {
Expand Down
20 changes: 10 additions & 10 deletions contracts/interfaces/IERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ interface IERC20 {
/*** Events ***/
/**************/

/**
* @dev Emits an event indicating that tokens have moved from one account to another.
* @param owner_ Account that tokens have moved from.
* @param recipient_ Account that tokens have moved to.
* @param amount_ Amount of tokens that have been transferred.
*/
event Transfer(address indexed owner_, address indexed recipient_, uint256 amount_);

/**
* @dev Emits an event indicating that one account has set the allowance of another account over their tokens.
* @param owner_ Account that tokens are approved from.
Expand All @@ -24,6 +16,14 @@ interface IERC20 {
*/
event Approval(address indexed owner_, address indexed spender_, uint256 amount_);

/**
* @dev Emits an event indicating that tokens have moved from one account to another.
* @param owner_ Account that tokens have moved from.
* @param recipient_ Account that tokens have moved to.
* @param amount_ Amount of tokens that have been transferred.
*/
event Transfer(address indexed owner_, address indexed recipient_, uint256 amount_);

/**************************/
/*** External Functions ***/
/**************************/
Expand Down Expand Up @@ -133,9 +133,9 @@ interface IERC20 {

/**
* @dev Returns the permit type hash.
* @return hash_ The permit type hash.
* @return permitTypeHash_ The permit type hash.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, should this be permitTypehash instead? Based on the name of the function.

*/
function PERMIT_TYPEHASH() external view returns (bytes32 hash_);
function PERMIT_TYPEHASH() external view returns (bytes32 permitTypeHash_);

/**
* @dev Returns the symbol of the token.
Expand Down
Loading