Add ReentrancyGuard

This commit is contained in:
Remco Bloemen
2017-03-24 11:01:06 +00:00
parent ffce7e3b08
commit a2bd1bb7f6
5 changed files with 136 additions and 0 deletions

View File

@ -0,0 +1,28 @@
pragma solidity ^0.4.8;
/// @title Helps contracts guard agains rentrancy attacks.
/// @author Remco Bloemen <remco@2π.com>
/// @notice If you mark a function `nonReentrant`, you should also
/// mark it `external`.
contract ReentrancyGuard {
/// @dev We use a single lock for the whole contract.
bool private rentrancy_lock = false;
/// Prevent contract from calling itself, directly or indirectly.
/// @notice If you mark a function `nonReentrant`, you should also
/// mark it `external`. Calling one nonReentrant function from
/// another is not supported. Instead, you can implement a
/// `private` function doing the actual work, and a `external`
/// wrapper marked as `nonReentrant`.
modifier nonReentrant() {
if(rentrancy_lock == false) {
rentrancy_lock = true;
_;
rentrancy_lock = false;
} else {
throw;
}
}
}