Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
openzeppelin-contracts-upgradeable
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
俞永鹏
openzeppelin-contracts-upgradeable
Commits
31ac59b2
Commit
31ac59b2
authored
Aug 06, 2018
by
yaronvel
Committed by
Nicolás Venturo
Aug 06, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reentrancy mutex gas optimization (#1155)
* reentrancy mutex gas optimization * 1) uint => uint256 2) ++ to += 1
parent
bf349118
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
14 deletions
+5
-14
ReentrancyGuard.sol
contracts/ReentrancyGuard.sol
+5
-14
No files found.
contracts/ReentrancyGuard.sol
View file @
31ac59b2
...
...
@@ -9,17 +9,8 @@ pragma solidity ^0.4.24;
*/
contract ReentrancyGuard {
/// @dev Constant for unlocked guard state - non-zero to prevent extra gas costs.
/// See: https://github.com/OpenZeppelin/openzeppelin-solidity/issues/1056
uint private constant REENTRANCY_GUARD_FREE = 1;
/// @dev Constant for locked guard state
uint private constant REENTRANCY_GUARD_LOCKED = 2;
/**
* @dev We use a single lock for the whole contract.
*/
uint private reentrancyLock = REENTRANCY_GUARD_FREE;
/// @dev counter to allow mutex lock with only one SSTORE operation
uint256 private guardCounter = 1;
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
...
...
@@ -30,10 +21,10 @@ contract ReentrancyGuard {
* wrapper marked as `nonReentrant`.
*/
modifier nonReentrant() {
require(reentrancyLock == REENTRANCY_GUARD_FREE)
;
reentrancyLock = REENTRANCY_GUARD_LOCKED
;
guardCounter += 1
;
uint256 localCounter = guardCounter
;
_;
re
entrancyLock = REENTRANCY_GUARD_FREE
;
re
quire(localCounter == guardCounter)
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment