decrease approval condition fix (greater than and equal to) #1063
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🚀 Description
The
decreaseApproval
function in StandardToken.sol has a condition that if the subtracted amount is greater than the allowed amount, simply make the allowance 0, otherwise, it invokes a subtraction function for reducing the approval amount:If the subtracted amount is exactly equal to the allowed tokens, this will execute both the first condition, and will then default to the else where the subtract function is called which unnecessarily increases the gas amount of such a transaction. If we modify the condition to be
(_subtractedValue >= oldValue)
, the allowance will be reset to 0. This will only increase 3 units of gas per transaction but it will save 88 units of gas whensubtractedValue
is equal to theoldValue
.Before update in statement the transaction cost is 16278 to decrease the exactly same allowed amount
![before](https://user-images.githubusercontent.com/14287497/42408604-d228e2a6-81e7-11e8-8b34-398d97dd38d4.png)
After the update the transaction cost is 16190
![after](https://user-images.githubusercontent.com/14287497/42408607-e54bb80e-81e7-11e8-8ba1-33ba406d740e.png)
npm run lint:all:fix
).