Update ReentrancyGuard for Istanbul Hard Fork#1992
Merged
nventuro merged 4 commits intoOpenZeppelin:masterfrom Nov 13, 2019
Merged
Update ReentrancyGuard for Istanbul Hard Fork#1992nventuro merged 4 commits intoOpenZeppelin:masterfrom
nventuro merged 4 commits intoOpenZeppelin:masterfrom
Conversation
Changes: Added L37, `_guardCounter = 1;` Rationale: The planned _Istanbul Hard Fork_ will implement [EIP 2200](https://github.com/ethereum/EIPs/blob/e4d4ea348e06c54d0075c400dc7b72430d427ff1/EIPS/eip-2200.md), which implements "net gas metering" for `sstore` operations. If the final value of `_guardCounter` is unchanged relative to the original value of it, a gas refund will be applied and charges for changing the value of `_guardCounter` will effectively not exist. This ends up being cheaper than the current implementation ONLY AFTER Istanbul. Before Istanbul, the added line actually ends up costing more gas. Note that if `_guardCounter` is `0` initially, the initial cost and subsequent refund will both be larger than if `_guardCounter` is `1` initially. Although in both cases, the net gas cost (`gasCost - gasRefund`) are equal, it's better in terms of cost to have both the gas cost and refund smaller, as there is some limit to the percentage of a gas refund that can actually be realized.
Contributor
|
Thanks a lot @ericDeCourcy! Could you add an entry for this change on the changelog file? |
Added note for change to ReentrancyGuard.sol
Contributor
|
Thanks! I took the liberty of changing it up a bit so that the improvements introduced by this PR are more evident by the reader, who may not be aware of the implications of the actual code change. I also added a note on the documentation for the module, to entice people to try out the new version. |
nventuro
approved these changes
Nov 13, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Changes:
Added L37,
_guardCounter = 1;Rationale:
The planned Istanbul Hard Fork will implement EIP 2200, which implements "net gas metering" for
sstoreoperations. If the final value of_guardCounteris unchanged relative to the original value of it, a gas refund will be applied and charges for changing the value of_guardCounterwill effectively not exist. This ends up being cheaper than the current implementation ONLY AFTER Istanbul. Before Istanbul, the added line actually ends up costing more gas.Note that if
_guardCounteris0initially, the initial cost and subsequent refund will both be larger than if_guardCounteris1initially. Although in both cases, the net gas cost (gasCost - gasRefund) are equal, it's better in terms of cost to have both the gas cost and refund smaller, as there is some limit to the percentage of a gas refund that can actually be realized.