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
After the update the transaction cost is 16190
npm run lint:all:fix
).