Skip to content

Commit

Permalink
chore: Standardization and cleanup (#31)
Browse files Browse the repository at this point in the history
* chore: Standardization and cleanup

* feat: add testFuzz to all fuzz tests

* chore: improved tests

Co-authored-by: Lucas Manuel <[email protected]>
  • Loading branch information
deluca-mike and Lucas Manuel authored Mar 16, 2022
1 parent ab76d12 commit 5f5d6c7
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 210 deletions.
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_) <= uint256(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) &&
(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.
*/
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

0 comments on commit 5f5d6c7

Please sign in to comment.