Browse Source

Input check sequence modification for gas efficiency (#1043)

* Update StandardToken.sol

* Slight improvement in gas efficiency

Users tend to attempt to over-spend more than they attempt to burn non-burnable tokens. If the contract checks for overspending before assuring tokens are not being burnt a slight amount of gas might be saved in the long term.
Lucas Gleba 7 years ago
parent
commit
1ecda54449
2 changed files with 2 additions and 2 deletions
  1. 1 1
      contracts/token/ERC20/BasicToken.sol
  2. 1 1
      contracts/token/ERC20/StandardToken.sol

+ 1 - 1
contracts/token/ERC20/BasicToken.sol

@@ -29,8 +29,8 @@ contract BasicToken is ERC20Basic {
   * @param _value The amount to be transferred.
   */
   function transfer(address _to, uint256 _value) public returns (bool) {
-    require(_to != address(0));
     require(_value <= balances[msg.sender]);
+    require(_to != address(0));
 
     balances[msg.sender] = balances[msg.sender].sub(_value);
     balances[_to] = balances[_to].add(_value);

+ 1 - 1
contracts/token/ERC20/StandardToken.sol

@@ -30,9 +30,9 @@ contract StandardToken is ERC20, BasicToken {
     public
     returns (bool)
   {
-    require(_to != address(0));
     require(_value <= balances[_from]);
     require(_value <= allowed[_from][msg.sender]);
+    require(_to != address(0));
 
     balances[_from] = balances[_from].sub(_value);
     balances[_to] = balances[_to].add(_value);