tweak erc20
This commit is contained in:
@ -16,13 +16,11 @@ interface IERC20 {
|
|||||||
function nonces(address owner) external view returns (uint);
|
function nonces(address owner) external view returns (uint);
|
||||||
|
|
||||||
function transfer(address to, uint value) external returns (bool);
|
function transfer(address to, uint value) external returns (bool);
|
||||||
|
function burn(uint value) external;
|
||||||
function approve(address spender, uint value) external returns (bool);
|
function approve(address spender, uint value) external returns (bool);
|
||||||
function transferFrom(address from, address to, uint value) external returns (bool);
|
function transferFrom(address from, address to, uint value) external returns (bool);
|
||||||
|
|
||||||
function burn(uint value) external;
|
|
||||||
function burnFrom(address from, uint value) external;
|
function burnFrom(address from, uint value) external;
|
||||||
|
|
||||||
|
|
||||||
function approveMeta(
|
function approveMeta(
|
||||||
address owner, address spender, uint value, uint nonce, uint expiration, uint8 v, bytes32 r, bytes32 s
|
address owner, address spender, uint value, uint nonce, uint expiration, uint8 v, bytes32 r, bytes32 s
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
pragma solidity 0.5.13;
|
pragma solidity 0.5.13;
|
||||||
|
|
||||||
import "../interfaces/IERC20.sol";
|
import "../interfaces/IERC20.sol";
|
||||||
|
|
||||||
import "../libraries/SafeMath.sol";
|
import "../libraries/SafeMath.sol";
|
||||||
|
|
||||||
contract ERC20 is IERC20 {
|
contract ERC20 is IERC20 {
|
||||||
@ -16,7 +15,7 @@ contract ERC20 is IERC20 {
|
|||||||
|
|
||||||
bytes32 public DOMAIN_SEPARATOR;
|
bytes32 public DOMAIN_SEPARATOR;
|
||||||
// keccak256("Approve(address owner,address spender,uint256 value,uint256 nonce,uint256 expiration)");
|
// keccak256("Approve(address owner,address spender,uint256 value,uint256 nonce,uint256 expiration)");
|
||||||
bytes32 public constant APPROVE_TYPEHASH = hex'25a0822e8c2ed7ff64a57c55df37ff176282195b9e0c9bb770ed24a300c89762';
|
bytes32 public constant APPROVE_TYPEHASH = hex"25a0822e8c2ed7ff64a57c55df37ff176282195b9e0c9bb770ed24a300c89762";
|
||||||
mapping (address => uint) public nonces;
|
mapping (address => uint) public nonces;
|
||||||
|
|
||||||
event Transfer(address indexed from, address indexed to, uint value);
|
event Transfer(address indexed from, address indexed to, uint value);
|
||||||
@ -30,7 +29,9 @@ contract ERC20 is IERC20 {
|
|||||||
name = _name;
|
name = _name;
|
||||||
symbol = _symbol;
|
symbol = _symbol;
|
||||||
decimals = _decimals;
|
decimals = _decimals;
|
||||||
if (_totalSupply > 0) mint(msg.sender, _totalSupply);
|
if (_totalSupply > 0) {
|
||||||
|
mint(msg.sender, _totalSupply);
|
||||||
|
}
|
||||||
DOMAIN_SEPARATOR = keccak256(abi.encode(
|
DOMAIN_SEPARATOR = keccak256(abi.encode(
|
||||||
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
|
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
|
||||||
keccak256(bytes(name)),
|
keccak256(bytes(name)),
|
||||||
@ -84,27 +85,18 @@ contract ERC20 is IERC20 {
|
|||||||
{
|
{
|
||||||
require(nonce == nonces[owner]++, "ERC20: INVALID_NONCE");
|
require(nonce == nonces[owner]++, "ERC20: INVALID_NONCE");
|
||||||
// solium-disable-next-line security/no-block-members
|
// solium-disable-next-line security/no-block-members
|
||||||
require(expiration > block.timestamp, "ERC20: EXPIRED_SIGNATURE");
|
require(expiration > block.timestamp, "ERC20: EXPIRED");
|
||||||
require(v == 27 || v == 28, "ECDSA: INVALID_V");
|
require(v == 27 || v == 28, "ERC20: INVALID_V");
|
||||||
require(uint(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0, "ECDSA: INVALID_S");
|
require(uint(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0, "ERC20: INVALID_S");
|
||||||
|
|
||||||
bytes32 digest = keccak256(abi.encodePacked(
|
bytes32 digest = keccak256(abi.encodePacked(
|
||||||
hex'19',
|
hex"19",
|
||||||
hex'01',
|
hex"01",
|
||||||
DOMAIN_SEPARATOR,
|
DOMAIN_SEPARATOR,
|
||||||
keccak256(abi.encode(
|
keccak256(abi.encode(APPROVE_TYPEHASH, owner, spender, value, nonce, expiration))
|
||||||
APPROVE_TYPEHASH, owner, spender, value, nonce, expiration
|
|
||||||
))
|
|
||||||
));
|
));
|
||||||
address recoveredAddress = ecrecover(digest, v, r, s);
|
address recoveredAddress = ecrecover(digest, v, r, s);
|
||||||
if (recoveredAddress != owner) {
|
require(recoveredAddress != address(0), "ERC20: INVALID_SIGNATURE");
|
||||||
recoveredAddress = ecrecover(
|
require(recoveredAddress == owner, "ERC20: INVALID_ADDRESS");
|
||||||
keccak256(abi.encodePacked(hex"19", "Ethereum Signed Message:", hex"32", digest)), v, r, s
|
|
||||||
);
|
|
||||||
}
|
|
||||||
require(recoveredAddress != address(0), "ERC20: INVALID_RECOVERED_ADDRESS");
|
|
||||||
require(recoveredAddress == owner, "ERC20: INVALID_SIGNATURE");
|
|
||||||
|
|
||||||
_approve(owner, spender, value);
|
_approve(owner, spender, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user