Add feeToSetter

This commit is contained in:
Brian Li 2021-04-02 15:32:58 -07:00
parent 66a8fe5712
commit 603dcdc426
19 changed files with 29460 additions and 20562 deletions

View file

@ -15,15 +15,19 @@ import "./Tornado.sol";
contract ERC20Tornado is Tornado {
address public token;
uint256 public protocolFee;
constructor(
IVerifier _verifier,
IFeeManager _feeManager,
uint256 _denomination,
uint32 _merkleTreeHeight,
address _operator,
address _token
) Tornado(_verifier, _denomination, _merkleTreeHeight, _operator) public {
) Tornado(_verifier, _feeManager, _denomination, _merkleTreeHeight, _operator) public {
token = _token;
// 0.5% fee
protocolFee = _denomination / 200;
}
function _processDeposit() internal {
@ -31,12 +35,19 @@ contract ERC20Tornado is Tornado {
_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 _relayer_fee, uint256 _refund, address _feeTo) internal {
require(msg.value == _refund, "Incorrect refund amount received by the contract");
_safeErc20Transfer(_recipient, denomination - _fee);
if (_fee > 0) {
_safeErc20Transfer(_relayer, _fee);
bool feeOn = _feeTo != address(0);
if (feeOn) {
_safeErc20Transfer(_recipient, denomination - _relayer_fee - protocolFee);
_safeErc20Transfer(_feeTo, protocolFee);
} else {
_safeErc20Transfer(_recipient, denomination - _relayer_fee);
}
if (_relayer_fee > 0) {
_safeErc20Transfer(_relayer, _relayer_fee);
}
if (_refund > 0) {

View file

@ -1,41 +0,0 @@
// 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.17;
import "./Tornado.sol";
contract ETHTornado is Tornado {
constructor(
IVerifier _verifier,
uint256 _denomination,
uint32 _merkleTreeHeight,
address _operator
) Tornado(_verifier, _denomination, _merkleTreeHeight, _operator) public {
}
function _processDeposit() internal {
require(msg.value == denomination, "Please send `mixDenomination` ETH along with transaction");
}
function _processWithdraw(address payable _recipient, address payable _relayer, uint256 _fee, uint256 _refund) internal {
// sanity checks
require(msg.value == 0, "Message value is supposed to be zero for ETH instance");
require(_refund == 0, "Refund value is supposed to be zero for ETH instance");
(bool success, ) = _recipient.call.value(denomination - _fee)("");
require(success, "payment to _recipient did not go thru");
if (_fee > 0) {
(success, ) = _relayer.call.value(_fee)("");
require(success, "payment to _relayer did not go thru");
}
}
}

20
contracts/FeeManager.sol Normal file
View file

@ -0,0 +1,20 @@
pragma solidity 0.5.17;
contract FeeManager {
address public feeTo;
address public feeToSetter;
constructor(address _feeToSetter) public {
feeToSetter = _feeToSetter;
}
function setFeeTo(address _feeTo) external {
require(msg.sender == feeToSetter, 'Poof: FORBIDDEN');
feeTo = _feeTo;
}
function setFeeToSetter(address _feeToSetter) external {
require(msg.sender == feeToSetter, 'Poof: FORBIDDEN');
feeToSetter = _feeToSetter;
}
}

View file

@ -1,14 +1,3 @@
// 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.17;
import "./MerkleTreeWithHistory.sol";
@ -18,12 +7,17 @@ contract IVerifier {
function verifyProof(bytes memory _proof, uint256[6] memory _input) public returns(bool);
}
contract IFeeManager {
function feeTo() external view returns (address);
}
contract Tornado is MerkleTreeWithHistory, ReentrancyGuard {
uint256 public denomination;
mapping(bytes32 => bool) public nullifierHashes;
// we store all commitments just to prevent accidental deposits with the same commitment
mapping(bytes32 => bool) public commitments;
IVerifier public verifier;
IFeeManager public feeManager;
// operator can update snark verification key
// after the final trusted setup ceremony operator rights are supposed to be transferred to zero address
@ -45,12 +39,14 @@ contract Tornado is MerkleTreeWithHistory, ReentrancyGuard {
*/
constructor(
IVerifier _verifier,
IFeeManager _feeManager,
uint256 _denomination,
uint32 _merkleTreeHeight,
address _operator
) MerkleTreeWithHistory(_merkleTreeHeight) public {
require(_denomination > 0, "denomination should be greater than 0");
verifier = _verifier;
feeManager = _feeManager;
operator = _operator;
denomination = _denomination;
}
@ -87,12 +83,12 @@ contract Tornado is MerkleTreeWithHistory, ReentrancyGuard {
require(verifier.verifyProof(_proof, [uint256(_root), uint256(_nullifierHash), uint256(_recipient), uint256(_relayer), _fee, _refund]), "Invalid withdraw proof");
nullifierHashes[_nullifierHash] = true;
_processWithdraw(_recipient, _relayer, _fee, _refund);
_processWithdraw(_recipient, _relayer, _fee, _refund, feeManager.feeTo());
emit Withdrawal(_recipient, _nullifierHash, _relayer, _fee);
}
/** @dev this function is defined in a child contract */
function _processWithdraw(address payable _recipient, address payable _relayer, uint256 _fee, uint256 _refund) internal;
function _processWithdraw(address payable _recipient, address payable _relayer, uint256 _relayer_fee, uint256 _refund, address _feeTo) internal;
/** @dev whether a note is already spent */
function isSpent(bytes32 _nullifierHash) public view returns(bool) {