mirror of
https://github.com/tornadocash/tornado-core.git
synced 2024-12-12 17:14:19 -05:00
57 lines
2.2 KiB
Solidity
57 lines
2.2 KiB
Solidity
// https://tornado.cash
|
|
/*
|
|
* d888888P dP a88888b. dP
|
|
* 88 88 d8' `88 88
|
|
* 88 .d8888b. 88d888b. 88d888b. .d8888b. .d888b88 .d8888b. 88 .d8888b. .d8888b. 88d888b.
|
|
* 88 88' `88 88' `88 88' `88 88' `88 88' `88 88' `88 88 88' `88 Y8ooooo. 88' `88
|
|
* 88 88. .88 88 88 88 88. .88 88. .88 88. .88 dP Y8. .88 88. .88 88 88 88
|
|
* dP `88888P' dP dP dP `88888P8 `88888P8 `88888P' 88 Y88888P' `88888P8 `88888P' dP dP
|
|
* ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
|
|
*/
|
|
|
|
pragma solidity ^0.5.8;
|
|
|
|
import "./GSNMixer.sol";
|
|
|
|
contract ETHMixer is GSNMixer {
|
|
constructor(
|
|
address _verifier,
|
|
uint256 _mixDenomination,
|
|
uint8 _merkleTreeHeight,
|
|
uint256 _emptyElement,
|
|
address payable _operator
|
|
) GSNMixer(_verifier, _mixDenomination, _merkleTreeHeight, _emptyElement, _operator) public {
|
|
}
|
|
|
|
function _processWithdraw(address payable _receiver, address payable _relayer, uint256 _fee) internal {
|
|
_receiver.transfer(mixDenomination - _fee);
|
|
if (_fee > 0) {
|
|
_relayer.transfer(_fee);
|
|
}
|
|
}
|
|
|
|
function _processDeposit() internal {
|
|
require(msg.value == mixDenomination, "Please send `mixDenomination` ETH along with transaction");
|
|
}
|
|
|
|
// this func is called by RelayerHub right after calling a target func
|
|
function postRelayedCall(bytes memory context, bool /*success*/, uint actualCharge, bytes32 /*preRetVal*/) public onlyHub {
|
|
// this require allows to protect againt malicious relay hub that can drain the mixer
|
|
require(couldBeWithdrawn, "could be called only after withdrawViaRelayer");
|
|
couldBeWithdrawn = false;
|
|
|
|
IRelayHub relayHub = IRelayHub(getHubAddr());
|
|
address payable recipient;
|
|
uint256 nullifierHash;
|
|
assembly {
|
|
recipient := mload(add(context, 32))
|
|
nullifierHash := mload(add(context, 64))
|
|
}
|
|
|
|
recipient.transfer(mixDenomination - actualCharge);
|
|
relayHub.depositFor.value(actualCharge)(address(this));
|
|
|
|
emit Withdraw(recipient, nullifierHash, tx.origin, actualCharge);
|
|
}
|
|
}
|