From 1ecda54449f96630cc596b064e07290cfed6365c Mon Sep 17 00:00:00 2001 From: Lucas Gleba Date: Fri, 20 Jul 2018 19:52:02 +0200 Subject: [PATCH] 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. --- contracts/token/ERC20/BasicToken.sol | 2 +- contracts/token/ERC20/StandardToken.sol | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/token/ERC20/BasicToken.sol b/contracts/token/ERC20/BasicToken.sol index e6b6ebfb5..98136743b 100644 --- a/contracts/token/ERC20/BasicToken.sol +++ b/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); diff --git a/contracts/token/ERC20/StandardToken.sol b/contracts/token/ERC20/StandardToken.sol index 7c236130d..0a4c5b8c6 100644 --- a/contracts/token/ERC20/StandardToken.sol +++ b/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);