nonReentrant guards

This commit is contained in:
Alexey 2019-11-11 19:12:17 +03:00
parent e6cce0c7ce
commit 83c9ba7296
3 changed files with 6 additions and 5 deletions

View File

@ -26,12 +26,12 @@ contract ERC20Mixer is Mixer {
token = _token; token = _token;
} }
function _processDeposit() internal { function _processDeposit() internal nonReentrant {
require(msg.value == 0, "ETH value is supposed to be 0 for ETH mixer"); require(msg.value == 0, "ETH value is supposed to be 0 for ETH mixer");
_safeErc20TransferFrom(msg.sender, address(this), denomination); _safeErc20TransferFrom(msg.sender, address(this), denomination);
} }
function _processWithdraw(address payable _recipient, address payable _relayer, uint256 _fee, uint256 _refund) internal { function _processWithdraw(address payable _recipient, address payable _relayer, uint256 _fee, uint256 _refund) internal nonReentrant {
require(msg.value == _refund, "Incorrect refund amount received by the contract"); require(msg.value == _refund, "Incorrect refund amount received by the contract");
_safeErc20Transfer(_recipient, denomination - _fee); _safeErc20Transfer(_recipient, denomination - _fee);

View File

@ -22,11 +22,11 @@ contract ETHMixer is Mixer {
) Mixer(_verifier, _denomination, _merkleTreeHeight, _operator) public { ) Mixer(_verifier, _denomination, _merkleTreeHeight, _operator) public {
} }
function _processDeposit() internal { function _processDeposit() internal nonReentrant {
require(msg.value == denomination, "Please send `mixDenomination` ETH along with transaction"); require(msg.value == denomination, "Please send `mixDenomination` ETH along with transaction");
} }
function _processWithdraw(address payable _recipient, address payable _relayer, uint256 _fee, uint256 _refund) internal { function _processWithdraw(address payable _recipient, address payable _relayer, uint256 _fee, uint256 _refund) internal nonReentrant {
// sanity checks // sanity checks
require(msg.value == 0, "Message value is supposed to be zero for ETH mixer"); require(msg.value == 0, "Message value is supposed to be zero for ETH mixer");
require(_refund == 0, "Refund value is supposed to be zero for ETH mixer"); require(_refund == 0, "Refund value is supposed to be zero for ETH mixer");

View File

@ -12,12 +12,13 @@
pragma solidity ^0.5.8; pragma solidity ^0.5.8;
import "./MerkleTreeWithHistory.sol"; import "./MerkleTreeWithHistory.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
contract IVerifier { contract IVerifier {
function verifyProof(bytes memory _proof, uint256[6] memory _input) public returns(bool); function verifyProof(bytes memory _proof, uint256[6] memory _input) public returns(bool);
} }
contract Mixer is MerkleTreeWithHistory { contract Mixer is MerkleTreeWithHistory, ReentrancyGuard {
uint256 public denomination; uint256 public denomination;
mapping(bytes32 => bool) public nullifierHashes; mapping(bytes32 => bool) public nullifierHashes;
// we store all commitments just to prevent accidental deposits with the same commitment // we store all commitments just to prevent accidental deposits with the same commitment