376 lines
36 KiB
HTML
376 lines
36 KiB
HTML
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||
|
|
||
|
<html lang="en">
|
||
|
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||
|
<title>LCOV - lcov.info - v2/TornadoRouter.sol</title>
|
||
|
<link rel="stylesheet" type="text/css" href="../gcov.css">
|
||
|
</head>
|
||
|
|
||
|
<body>
|
||
|
|
||
|
<table width="100%" border=0 cellspacing=0 cellpadding=0>
|
||
|
<tr><td class="title">LCOV - code coverage report</td></tr>
|
||
|
<tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
|
||
|
|
||
|
<tr>
|
||
|
<td width="100%">
|
||
|
<table cellpadding=1 border=0 width="100%">
|
||
|
<tr>
|
||
|
<td width="10%" class="headerItem">Current view:</td>
|
||
|
<td width="35%" class="headerValue"><a href="../index.html">top level</a> - <a href="index.html">v2</a> - TornadoRouter.sol<span style="font-size: 80%;"> (source / <a href="TornadoRouter.sol.func-sort-c.html">functions</a>)</span></td>
|
||
|
<td width="5%"></td>
|
||
|
<td width="15%"></td>
|
||
|
<td width="10%" class="headerCovTableHead">Hit</td>
|
||
|
<td width="10%" class="headerCovTableHead">Total</td>
|
||
|
<td width="15%" class="headerCovTableHead">Coverage</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td class="headerItem">Test:</td>
|
||
|
<td class="headerValue">lcov.info</td>
|
||
|
<td></td>
|
||
|
<td class="headerItem">Lines:</td>
|
||
|
<td class="headerCovTableEntry">12</td>
|
||
|
<td class="headerCovTableEntry">43</td>
|
||
|
<td class="headerCovTableEntryLo">27.9 %</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td class="headerItem">Date:</td>
|
||
|
<td class="headerValue">2023-06-19 00:07:36</td>
|
||
|
<td></td>
|
||
|
<td class="headerItem">Functions:</td>
|
||
|
<td class="headerCovTableEntry">4</td>
|
||
|
<td class="headerCovTableEntry">12</td>
|
||
|
<td class="headerCovTableEntryLo">33.3 %</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td class="headerItem">Legend:</td>
|
||
|
<td class="headerValueLeg"> Lines:
|
||
|
<span class="coverLegendCov">hit</span>
|
||
|
<span class="coverLegendNoCov">not hit</span>
|
||
|
</td>
|
||
|
<td></td>
|
||
|
</tr>
|
||
|
<tr><td><img src="../glass.png" width=3 height=3 alt=""></td></tr>
|
||
|
</table>
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
|
||
|
</table>
|
||
|
|
||
|
<table cellpadding=0 cellspacing=0 border=0>
|
||
|
<tr>
|
||
|
<td><br></td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td>
|
||
|
<pre class="sourceHeading"> Line data Source code</pre>
|
||
|
<pre class="source">
|
||
|
<a name="1"><span class="lineNum"> 1 </span> : // SPDX-License-Identifier: MIT</a>
|
||
|
<a name="2"><span class="lineNum"> 2 </span> : </a>
|
||
|
<a name="3"><span class="lineNum"> 3 </span> : pragma solidity ^0.6.12;</a>
|
||
|
<a name="4"><span class="lineNum"> 4 </span> : pragma experimental ABIEncoderV2;</a>
|
||
|
<a name="5"><span class="lineNum"> 5 </span> : </a>
|
||
|
<a name="6"><span class="lineNum"> 6 </span> : // OZ Imports</a>
|
||
|
<a name="7"><span class="lineNum"> 7 </span> : </a>
|
||
|
<a name="8"><span class="lineNum"> 8 </span> : import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";</a>
|
||
|
<a name="9"><span class="lineNum"> 9 </span> : import { Initializable } from "@openzeppelin/contracts/proxy/Initializable.sol";</a>
|
||
|
<a name="10"><span class="lineNum"> 10 </span> : import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";</a>
|
||
|
<a name="11"><span class="lineNum"> 11 </span> : import { Address } from "@openzeppelin/contracts/utils/Address.sol";</a>
|
||
|
<a name="12"><span class="lineNum"> 12 </span> : import { Math } from "@openzeppelin/contracts/math/Math.sol";</a>
|
||
|
<a name="13"><span class="lineNum"> 13 </span> : </a>
|
||
|
<a name="14"><span class="lineNum"> 14 </span> : // Tornado Imports</a>
|
||
|
<a name="15"><span class="lineNum"> 15 </span> : </a>
|
||
|
<a name="16"><span class="lineNum"> 16 </span> : import { ITornadoInstance } from "tornado-anonymity-mining/contracts/interfaces/ITornadoInstance.sol";</a>
|
||
|
<a name="17"><span class="lineNum"> 17 </span> : </a>
|
||
|
<a name="18"><span class="lineNum"> 18 </span> : // Local imports</a>
|
||
|
<a name="19"><span class="lineNum"> 19 </span> : </a>
|
||
|
<a name="20"><span class="lineNum"> 20 </span> : import { RelayerRegistry } from "./RelayerRegistry.sol";</a>
|
||
|
<a name="21"><span class="lineNum"> 21 </span> : import { InstanceRegistry, InstanceState } from "./InstanceRegistry.sol";</a>
|
||
|
<a name="22"><span class="lineNum"> 22 </span> : import { FeeOracleManager } from "./FeeOracleManager.sol";</a>
|
||
|
<a name="23"><span class="lineNum"> 23 </span> : </a>
|
||
|
<a name="24"><span class="lineNum"> 24 </span> : /**</a>
|
||
|
<a name="25"><span class="lineNum"> 25 </span> : * @title TornadoRouter</a>
|
||
|
<a name="26"><span class="lineNum"> 26 </span> : * @author AlienTornadosaurusHex</a>
|
||
|
<a name="27"><span class="lineNum"> 27 </span> : * @notice This contract is a router for all Tornado Cash deposits and withdrawals</a>
|
||
|
<a name="28"><span class="lineNum"> 28 </span> : * @dev This is an improved version of the TornadoRouter with a modified design from the original contract.</a>
|
||
|
<a name="29"><span class="lineNum"> 29 </span> : */</a>
|
||
|
<a name="30"><span class="lineNum"> 30 </span> : contract TornadoRouter is Initializable {</a>
|
||
|
<a name="31"><span class="lineNum"> 31 </span> : using SafeERC20 for IERC20;</a>
|
||
|
<a name="32"><span class="lineNum"> 32 </span> : </a>
|
||
|
<a name="33"><span class="lineNum"> 33 </span> : /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ VARIABLES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */</a>
|
||
|
<a name="34"><span class="lineNum"> 34 </span> : </a>
|
||
|
<a name="35"><span class="lineNum"> 35 </span> : /**</a>
|
||
|
<a name="36"><span class="lineNum"> 36 </span> : * @notice The address of the Governance proxy</a>
|
||
|
<a name="37"><span class="lineNum"> 37 </span> : */</a>
|
||
|
<a name="38"><span class="lineNum"> 38 </span> : address public immutable governanceProxyAddress;</a>
|
||
|
<a name="39"><span class="lineNum"> 39 </span> : </a>
|
||
|
<a name="40"><span class="lineNum"> 40 </span> : /**</a>
|
||
|
<a name="41"><span class="lineNum"> 41 </span> : * @notice The Instance Registry</a>
|
||
|
<a name="42"><span class="lineNum"> 42 </span> : */</a>
|
||
|
<a name="43"><span class="lineNum"> 43 </span> : InstanceRegistry public instanceRegistry;</a>
|
||
|
<a name="44"><span class="lineNum"> 44 </span> : </a>
|
||
|
<a name="45"><span class="lineNum"> 45 </span> : /**</a>
|
||
|
<a name="46"><span class="lineNum"> 46 </span> : * @notice The Relayer Registry</a>
|
||
|
<a name="47"><span class="lineNum"> 47 </span> : */</a>
|
||
|
<a name="48"><span class="lineNum"> 48 </span> : RelayerRegistry public relayerRegistry;</a>
|
||
|
<a name="49"><span class="lineNum"> 49 </span> : </a>
|
||
|
<a name="50"><span class="lineNum"> 50 </span> : /**</a>
|
||
|
<a name="51"><span class="lineNum"> 51 </span> : * @notice The Fee Oracle Manager</a>
|
||
|
<a name="52"><span class="lineNum"> 52 </span> : */</a>
|
||
|
<a name="53"><span class="lineNum"> 53 </span> : FeeOracleManager public feeOracleManager;</a>
|
||
|
<a name="54"><span class="lineNum"> 54 </span> : </a>
|
||
|
<a name="55"><span class="lineNum"> 55 </span> : /**</a>
|
||
|
<a name="56"><span class="lineNum"> 56 </span> : * @notice Note down proofs for slashing relayers</a>
|
||
|
<a name="57"><span class="lineNum"> 57 </span> : */</a>
|
||
|
<a name="58"><span class="lineNum"> 58 </span> : mapping(bytes32 => bool) public slashProofs;</a>
|
||
|
<a name="59"><span class="lineNum"> 59 </span> : </a>
|
||
|
<a name="60"><span class="lineNum"> 60 </span> : /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ EVENTS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */</a>
|
||
|
<a name="61"><span class="lineNum"> 61 </span> : </a>
|
||
|
<a name="62"><span class="lineNum"> 62 </span> : event EncryptedNote(address indexed sender, bytes encryptedNote);</a>
|
||
|
<a name="63"><span class="lineNum"> 63 </span> : event TokenApproved(address indexed spender, uint256 amount);</a>
|
||
|
<a name="64"><span class="lineNum"> 64 </span> : </a>
|
||
|
<a name="65"><span class="lineNum"> 65 </span> : event WithdrawalWithRelayer(</a>
|
||
|
<a name="66"><span class="lineNum"> 66 </span> : address sender, address relayer, address instanceAddress, bytes32 nullifierHash</a>
|
||
|
<a name="67"><span class="lineNum"> 67 </span> : );</a>
|
||
|
<a name="68"><span class="lineNum"> 68 </span> : </a>
|
||
|
<a name="69"><span class="lineNum"> 69 </span> : event InstanceRegistryUpdated(address newInstanceRegistryProxyAddress);</a>
|
||
|
<a name="70"><span class="lineNum"> 70 </span> : event RelayerRegistryUpdated(address newRelayerRegistryProxyAddress);</a>
|
||
|
<a name="71"><span class="lineNum"> 71 </span> : event FeeOracleManagerUpdated(address newFeeOracleManagerProxyAddress);</a>
|
||
|
<a name="72"><span class="lineNum"> 72 </span> : </a>
|
||
|
<a name="73"><span class="lineNum"> 73 </span> : /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ LOGIC ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */</a>
|
||
|
<a name="74"><span class="lineNum"> 74 </span> : </a>
|
||
|
<a name="75"><span class="lineNum"> 75 </span> : constructor(address _governanceProxyAddress) public {</a>
|
||
|
<a name="76"><span class="lineNum"> 76 </span> : governanceProxyAddress = _governanceProxyAddress;</a>
|
||
|
<a name="77"><span class="lineNum"> 77 </span> : }</a>
|
||
|
<a name="78"><span class="lineNum"> 78 </span> : </a>
|
||
|
<a name="79"><span class="lineNum"> 79 </span> : modifier onlyInstanceRegistry() {</a>
|
||
|
<a name="80"><span class="lineNum"> 80 </span> : require(msg.sender == address(instanceRegistry), "TornadoRouter: onlyInstanceRegistry");</a>
|
||
|
<a name="81"><span class="lineNum"> 81 </span> : _;</a>
|
||
|
<a name="82"><span class="lineNum"> 82 </span> : }</a>
|
||
|
<a name="83"><span class="lineNum"> 83 </span> : </a>
|
||
|
<a name="84"><span class="lineNum"> 84 </span> : modifier onlyGovernance() {</a>
|
||
|
<a name="85"><span class="lineNum"> 85 </span> : require(msg.sender == governanceProxyAddress, "TornadoRouter: onlyGovernance");</a>
|
||
|
<a name="86"><span class="lineNum"> 86 </span> : _;</a>
|
||
|
<a name="87"><span class="lineNum"> 87 </span> : }</a>
|
||
|
<a name="88"><span class="lineNum"> 88 </span> : </a>
|
||
|
<a name="89"><span class="lineNum"> 89 </span> : function version() public pure virtual returns (string memory) {</a>
|
||
|
<a name="90"><span class="lineNum"> 90 </span><span class="lineCov"> 1 : return "v2-slashing-and-oracles";</span></a>
|
||
|
<a name="91"><span class="lineNum"> 91 </span> : }</a>
|
||
|
<a name="92"><span class="lineNum"> 92 </span> : </a>
|
||
|
<a name="93"><span class="lineNum"> 93 </span> : function initialize(</a>
|
||
|
<a name="94"><span class="lineNum"> 94 </span> : address _instanceRegistryProxyAddress,</a>
|
||
|
<a name="95"><span class="lineNum"> 95 </span> : address _relayerRegistryProxyAddress,</a>
|
||
|
<a name="96"><span class="lineNum"> 96 </span> : address _feeOracleManagerProxyAddress</a>
|
||
|
<a name="97"><span class="lineNum"> 97 </span> : ) external onlyGovernance initializer {</a>
|
||
|
<a name="98"><span class="lineNum"> 98 </span><span class="lineCov"> 4 : instanceRegistry = InstanceRegistry(_instanceRegistryProxyAddress);</span></a>
|
||
|
<a name="99"><span class="lineNum"> 99 </span><span class="lineCov"> 4 : relayerRegistry = RelayerRegistry(_relayerRegistryProxyAddress);</span></a>
|
||
|
<a name="100"><span class="lineNum"> 100 </span><span class="lineCov"> 4 : feeOracleManager = FeeOracleManager(_feeOracleManagerProxyAddress);</span></a>
|
||
|
<a name="101"><span class="lineNum"> 101 </span> : }</a>
|
||
|
<a name="102"><span class="lineNum"> 102 </span> : </a>
|
||
|
<a name="103"><span class="lineNum"> 103 </span> : /**</a>
|
||
|
<a name="104"><span class="lineNum"> 104 </span> : * @notice Function to deposit into a Tornado instance. We don't really case if an external contract</a>
|
||
|
<a name="105"><span class="lineNum"> 105 </span> : * breaks for deposit since deposits can go through the instances too if need be.</a>
|
||
|
<a name="106"><span class="lineNum"> 106 </span> : * @param _tornado The instance to deposit into (address).</a>
|
||
|
<a name="107"><span class="lineNum"> 107 </span> : * @param _commitment The commitment which will be added to the Merkle Tree.</a>
|
||
|
<a name="108"><span class="lineNum"> 108 </span> : * @param _encryptedNote An encrypted note tied to the commitment which may be logged.</a>
|
||
|
<a name="109"><span class="lineNum"> 109 </span> : */</a>
|
||
|
<a name="110"><span class="lineNum"> 110 </span> : function deposit(ITornadoInstance _tornado, bytes32 _commitment, bytes calldata _encryptedNote)</a>
|
||
|
<a name="111"><span class="lineNum"> 111 </span> : public</a>
|
||
|
<a name="112"><span class="lineNum"> 112 </span> : payable</a>
|
||
|
<a name="113"><span class="lineNum"> 113 </span> : virtual</a>
|
||
|
<a name="114"><span class="lineNum"> 114 </span> : {</a>
|
||
|
<a name="115"><span class="lineNum"> 115 </span><span class="lineCov"> 1 : (IERC20 token,, bool isERC20, bool isEnabled) = instanceRegistry.instanceData(_tornado);</span></a>
|
||
|
<a name="116"><span class="lineNum"> 116 </span> : </a>
|
||
|
<a name="117"><span class="lineNum"> 117 </span> : // Better than having it revert at safeTransferFrom</a>
|
||
|
<a name="118"><span class="lineNum"> 118 </span><span class="lineCov"> 1 : require(isEnabled, "TornadoRouter: instance not enabled");</span></a>
|
||
|
<a name="119"><span class="lineNum"> 119 </span> : </a>
|
||
|
<a name="120"><span class="lineNum"> 120 </span><span class="lineCov"> 1 : if (isERC20) {</span></a>
|
||
|
<a name="121"><span class="lineNum"> 121 </span><span class="lineCov"> 1 : token.safeTransferFrom(msg.sender, address(this), _tornado.denomination());</span></a>
|
||
|
<a name="122"><span class="lineNum"> 122 </span> : }</a>
|
||
|
<a name="123"><span class="lineNum"> 123 </span> : </a>
|
||
|
<a name="124"><span class="lineNum"> 124 </span><span class="lineCov"> 1 : _tornado.deposit{ value: msg.value }(_commitment);</span></a>
|
||
|
<a name="125"><span class="lineNum"> 125 </span> : </a>
|
||
|
<a name="126"><span class="lineNum"> 126 </span><span class="lineCov"> 1 : emit EncryptedNote(msg.sender, _encryptedNote);</span></a>
|
||
|
<a name="127"><span class="lineNum"> 127 </span> : }</a>
|
||
|
<a name="128"><span class="lineNum"> 128 </span> : </a>
|
||
|
<a name="129"><span class="lineNum"> 129 </span> : /**</a>
|
||
|
<a name="130"><span class="lineNum"> 130 </span> : * @notice Withdrawal function for Governance relayers by which they can safely process a withdrawal</a>
|
||
|
<a name="131"><span class="lineNum"> 131 </span> : * without getting slashed (which kicks them off the frontend).</a>
|
||
|
<a name="132"><span class="lineNum"> 132 </span> : * @param _tornado The Tornado instance to withdraw from.</a>
|
||
|
<a name="133"><span class="lineNum"> 133 </span> : * @param _proof Bytes proof data.</a>
|
||
|
<a name="134"><span class="lineNum"> 134 </span> : * @param _root A current or historical bytes32 root of the Merkle Tree within the proofs context.</a>
|
||
|
<a name="135"><span class="lineNum"> 135 </span> : * @param _nullifierHash The bytes32 nullifierHash for the deposit.</a>
|
||
|
<a name="136"><span class="lineNum"> 136 </span> : * @param _recipient The address of recipient for withdrawn funds.</a>
|
||
|
<a name="137"><span class="lineNum"> 137 </span> : * @param _relayer The address of the relayer which will be making the withdrawal.</a>
|
||
|
<a name="138"><span class="lineNum"> 138 </span> : * @param _fee The fee in bips to pay the relayer.</a>
|
||
|
<a name="139"><span class="lineNum"> 139 </span> : * @param _refund If swapping into ETH on the other side, use this to specify how much should be paid for</a>
|
||
|
<a name="140"><span class="lineNum"> 140 </span> : */</a>
|
||
|
<a name="141"><span class="lineNum"> 141 </span> : function processWithdrawAsGovernanceRelayer(</a>
|
||
|
<a name="142"><span class="lineNum"> 142 </span> : ITornadoInstance _tornado,</a>
|
||
|
<a name="143"><span class="lineNum"> 143 </span> : bytes calldata _proof,</a>
|
||
|
<a name="144"><span class="lineNum"> 144 </span> : bytes32 _root,</a>
|
||
|
<a name="145"><span class="lineNum"> 145 </span> : bytes32 _nullifierHash,</a>
|
||
|
<a name="146"><span class="lineNum"> 146 </span> : address payable _recipient,</a>
|
||
|
<a name="147"><span class="lineNum"> 147 </span> : address payable _relayer,</a>
|
||
|
<a name="148"><span class="lineNum"> 148 </span> : uint256 _fee,</a>
|
||
|
<a name="149"><span class="lineNum"> 149 </span> : uint256 _refund</a>
|
||
|
<a name="150"><span class="lineNum"> 150 </span> : ) public payable virtual {</a>
|
||
|
<a name="151"><span class="lineNum"> 151 </span> : // Deduct balance immediately</a>
|
||
|
<a name="152"><span class="lineNum"> 152 </span><span class="lineNoCov"> 0 : relayerRegistry.deductBalance(msg.sender, _relayer, feeOracleManager.updateFee(_tornado, true));</span></a>
|
||
|
<a name="153"><span class="lineNum"> 153 </span> : // Then call the regular withdraw function which will make the relayer slashable</a>
|
||
|
<a name="154"><span class="lineNum"> 154 </span><span class="lineNoCov"> 0 : withdraw(_tornado, _proof, _root, _nullifierHash, _recipient, _relayer, _fee, _refund);</span></a>
|
||
|
<a name="155"><span class="lineNum"> 155 </span> : // But then undo this and get gas refund</a>
|
||
|
<a name="156"><span class="lineNum"> 156 </span><span class="lineNoCov"> 0 : slashProofs[keccak256(abi.encode(msg.sender, _tornado, _relayer, _nullifierHash))] = false;</span></a>
|
||
|
<a name="157"><span class="lineNum"> 157 </span> : }</a>
|
||
|
<a name="158"><span class="lineNum"> 158 </span> : </a>
|
||
|
<a name="159"><span class="lineNum"> 159 </span> : /**</a>
|
||
|
<a name="160"><span class="lineNum"> 160 </span> : * @notice Slash a relayer by proving that there is a nullifier hash for which he has not been deducted,</a>
|
||
|
<a name="161"><span class="lineNum"> 161 </span> : * get tokens back for it.</a>
|
||
|
<a name="162"><span class="lineNum"> 162 </span> : * @dev Events are emitted when withdrawals are processed, that is how you can find hashes.</a>
|
||
|
<a name="163"><span class="lineNum"> 163 </span> : * @param _relayer The relayer to be slashed</a>
|
||
|
<a name="164"><span class="lineNum"> 164 </span> : * @param _instanceAddress The instance for which nullifier hash is valid for</a>
|
||
|
<a name="165"><span class="lineNum"> 165 </span> : * @param _nullifierHash The nullifier hash</a>
|
||
|
<a name="166"><span class="lineNum"> 166 </span> : */</a>
|
||
|
<a name="167"><span class="lineNum"> 167 </span> : function slashRelayer(address _sender, address _relayer, address _instanceAddress, bytes32 _nullifierHash)</a>
|
||
|
<a name="168"><span class="lineNum"> 168 </span> : public</a>
|
||
|
<a name="169"><span class="lineNum"> 169 </span> : virtual</a>
|
||
|
<a name="170"><span class="lineNum"> 170 </span> : {</a>
|
||
|
<a name="171"><span class="lineNum"> 171 </span> : // Construct the proof, msg.sender can't lie about _sender, because proof will be invalid</a>
|
||
|
<a name="172"><span class="lineNum"> 172 </span> : // And _sender was withdraw msg.sender</a>
|
||
|
<a name="173"><span class="lineNum"> 173 </span><span class="lineNoCov"> 0 : bytes32 possibleSlashProof =</span></a>
|
||
|
<a name="174"><span class="lineNum"> 174 </span><span class="lineNoCov"> 0 : keccak256(abi.encode(_sender, _relayer, _instanceAddress, _nullifierHash));</span></a>
|
||
|
<a name="175"><span class="lineNum"> 175 </span> : </a>
|
||
|
<a name="176"><span class="lineNum"> 176 </span> : // Proof must be valid</a>
|
||
|
<a name="177"><span class="lineNum"> 177 </span><span class="lineNoCov"> 0 : require(slashProofs[possibleSlashProof], "TornadoRouter: invalid proof");</span></a>
|
||
|
<a name="178"><span class="lineNum"> 178 </span> : </a>
|
||
|
<a name="179"><span class="lineNum"> 179 </span> : // Since the proof is valid, we know the _sender is correct</a>
|
||
|
<a name="180"><span class="lineNum"> 180 </span> : // First step against multicall</a>
|
||
|
<a name="181"><span class="lineNum"> 181 </span><span class="lineNoCov"> 0 : require(msg.sender != _sender, "TornadoRouter: slasher is withdrawer");</span></a>
|
||
|
<a name="182"><span class="lineNum"> 182 </span> : </a>
|
||
|
<a name="183"><span class="lineNum"> 183 </span> : // Also require the sender is not a contract, multicall could proxy over one</a>
|
||
|
<a name="184"><span class="lineNum"> 184 </span><span class="lineNoCov"> 0 : require(!Address.isContract(msg.sender), "TornadoRouter: sender is contract");</span></a>
|
||
|
<a name="185"><span class="lineNum"> 185 </span> : </a>
|
||
|
<a name="186"><span class="lineNum"> 186 </span> : // Further it doesn't make sense then to really assert it's not a worker,</a>
|
||
|
<a name="187"><span class="lineNum"> 187 </span> : // since relayer could use a different account.</a>
|
||
|
<a name="188"><span class="lineNum"> 188 </span> : //</a>
|
||
|
<a name="189"><span class="lineNum"> 189 </span> : // In any case searchers and the balance not being returned in full should prevent relayers from not</a>
|
||
|
<a name="190"><span class="lineNum"> 190 </span> : // behaving well, if they are listed on the frontend</a>
|
||
|
<a name="191"><span class="lineNum"> 191 </span> : //</a>
|
||
|
<a name="192"><span class="lineNum"> 192 </span> : // Otherwise they are on their own</a>
|
||
|
<a name="193"><span class="lineNum"> 193 </span> : </a>
|
||
|
<a name="194"><span class="lineNum"> 194 </span> : // Slash relayer first, it also logs the slash event</a>
|
||
|
<a name="195"><span class="lineNum"> 195 </span><span class="lineNoCov"> 0 : relayerRegistry.slashRelayer(msg.sender, _relayer);</span></a>
|
||
|
<a name="196"><span class="lineNum"> 196 </span> : </a>
|
||
|
<a name="197"><span class="lineNum"> 197 </span> : // Then set this back false</a>
|
||
|
<a name="198"><span class="lineNum"> 198 </span><span class="lineNoCov"> 0 : slashProofs[possibleSlashProof] = false;</span></a>
|
||
|
<a name="199"><span class="lineNum"> 199 </span> : }</a>
|
||
|
<a name="200"><span class="lineNum"> 200 </span> : </a>
|
||
|
<a name="201"><span class="lineNum"> 201 </span> : /**</a>
|
||
|
<a name="202"><span class="lineNum"> 202 </span> : * @notice Withdraw from a Tornado Instance. Note that the withdraw function is totally independent of any</a>
|
||
|
<a name="203"><span class="lineNum"> 203 </span> : * Governance contracts, that means, even if the instances demand that only Router is the caller, and the</a>
|
||
|
<a name="204"><span class="lineNum"> 204 </span> : * Governance contracts get fucked, depositors won't lose their money AND third-party relayers will still</a>
|
||
|
<a name="205"><span class="lineNum"> 205 </span> : * have the opportunity to operate. Relayers not affiliated with Governance, sorry for that one extra</a>
|
||
|
<a name="206"><span class="lineNum"> 206 </span> : * SSTORE and emit!</a>
|
||
|
<a name="207"><span class="lineNum"> 207 </span> : * @param _tornado The Tornado instance to withdraw from.</a>
|
||
|
<a name="208"><span class="lineNum"> 208 </span> : * @param _proof Bytes proof data.</a>
|
||
|
<a name="209"><span class="lineNum"> 209 </span> : * @param _root A current or historical bytes32 root of the Merkle Tree within the proofs context.</a>
|
||
|
<a name="210"><span class="lineNum"> 210 </span> : * @param _nullifierHash The bytes32 nullifierHash for the deposit.</a>
|
||
|
<a name="211"><span class="lineNum"> 211 </span> : * @param _recipient The address of recipient for withdrawn funds.</a>
|
||
|
<a name="212"><span class="lineNum"> 212 </span> : * @param _relayer The address of the relayer which will be making the withdrawal.</a>
|
||
|
<a name="213"><span class="lineNum"> 213 </span> : * @param _fee The fee in bips to pay the relayer.</a>
|
||
|
<a name="214"><span class="lineNum"> 214 </span> : * @param _refund If swapping into ETH on the other side, use this to specify how much should be paid for</a>
|
||
|
<a name="215"><span class="lineNum"> 215 </span> : * it.</a>
|
||
|
<a name="216"><span class="lineNum"> 216 </span> : */</a>
|
||
|
<a name="217"><span class="lineNum"> 217 </span> : function withdraw(</a>
|
||
|
<a name="218"><span class="lineNum"> 218 </span> : ITornadoInstance _tornado,</a>
|
||
|
<a name="219"><span class="lineNum"> 219 </span> : bytes calldata _proof,</a>
|
||
|
<a name="220"><span class="lineNum"> 220 </span> : bytes32 _root,</a>
|
||
|
<a name="221"><span class="lineNum"> 221 </span> : bytes32 _nullifierHash,</a>
|
||
|
<a name="222"><span class="lineNum"> 222 </span> : address payable _recipient,</a>
|
||
|
<a name="223"><span class="lineNum"> 223 </span> : address payable _relayer,</a>
|
||
|
<a name="224"><span class="lineNum"> 224 </span> : uint256 _fee,</a>
|
||
|
<a name="225"><span class="lineNum"> 225 </span> : uint256 _refund</a>
|
||
|
<a name="226"><span class="lineNum"> 226 </span> : ) public payable virtual {</a>
|
||
|
<a name="227"><span class="lineNum"> 227 </span><span class="lineNoCov"> 0 : if (_relayer != address(0)) {</span></a>
|
||
|
<a name="228"><span class="lineNum"> 228 </span><span class="lineNoCov"> 0 : slashProofs[keccak256(abi.encode(msg.sender, _relayer, address(_tornado), _nullifierHash))] = true;</span></a>
|
||
|
<a name="229"><span class="lineNum"> 229 </span><span class="lineNoCov"> 0 : emit WithdrawalWithRelayer(msg.sender, _relayer, address(_tornado), _nullifierHash);</span></a>
|
||
|
<a name="230"><span class="lineNum"> 230 </span> : }</a>
|
||
|
<a name="231"><span class="lineNum"> 231 </span> : </a>
|
||
|
<a name="232"><span class="lineNum"> 232 </span><span class="lineNoCov"> 0 : _tornado.withdraw{ value: msg.value }(</span></a>
|
||
|
<a name="233"><span class="lineNum"> 233 </span> : _proof, _root, _nullifierHash, _recipient, _relayer, _fee, _refund</a>
|
||
|
<a name="234"><span class="lineNum"> 234 </span> : );</a>
|
||
|
<a name="235"><span class="lineNum"> 235 </span> : }</a>
|
||
|
<a name="236"><span class="lineNum"> 236 </span> : </a>
|
||
|
<a name="237"><span class="lineNum"> 237 </span> : function backupNotes(bytes[] calldata _encryptedNotes) public virtual {</a>
|
||
|
<a name="238"><span class="lineNum"> 238 </span><span class="lineNoCov"> 0 : for (uint256 i = 0; i < _encryptedNotes.length; i++) {</span></a>
|
||
|
<a name="239"><span class="lineNum"> 239 </span><span class="lineNoCov"> 0 : emit EncryptedNote(msg.sender, _encryptedNotes[i]);</span></a>
|
||
|
<a name="240"><span class="lineNum"> 240 </span> : }</a>
|
||
|
<a name="241"><span class="lineNum"> 241 </span> : }</a>
|
||
|
<a name="242"><span class="lineNum"> 242 </span> : </a>
|
||
|
<a name="243"><span class="lineNum"> 243 </span> : /**</a>
|
||
|
<a name="244"><span class="lineNum"> 244 </span> : * @notice Note that this contract doesn't leave dust unless someone sends dust to it.</a>
|
||
|
<a name="245"><span class="lineNum"> 245 </span> : */</a>
|
||
|
<a name="246"><span class="lineNum"> 246 </span> : function rescueTokens(IERC20 _token, address payable _to, uint256 _amount)</a>
|
||
|
<a name="247"><span class="lineNum"> 247 </span> : public</a>
|
||
|
<a name="248"><span class="lineNum"> 248 </span> : virtual</a>
|
||
|
<a name="249"><span class="lineNum"> 249 </span> : onlyGovernance</a>
|
||
|
<a name="250"><span class="lineNum"> 250 </span> : {</a>
|
||
|
<a name="251"><span class="lineNum"> 251 </span><span class="lineNoCov"> 0 : require(_to != address(0), "TORN: can not send to zero address");</span></a>
|
||
|
<a name="252"><span class="lineNum"> 252 </span> : </a>
|
||
|
<a name="253"><span class="lineNum"> 253 </span><span class="lineNoCov"> 0 : if (_token == IERC20(0)) {</span></a>
|
||
|
<a name="254"><span class="lineNum"> 254 </span> : // For Ether</a>
|
||
|
<a name="255"><span class="lineNum"> 255 </span><span class="lineNoCov"> 0 : uint256 totalBalance = address(this).balance;</span></a>
|
||
|
<a name="256"><span class="lineNum"> 256 </span><span class="lineNoCov"> 0 : uint256 balance = Math.min(totalBalance, _amount);</span></a>
|
||
|
<a name="257"><span class="lineNum"> 257 </span><span class="lineNoCov"> 0 : _to.transfer(balance);</span></a>
|
||
|
<a name="258"><span class="lineNum"> 258 </span> : } else {</a>
|
||
|
<a name="259"><span class="lineNum"> 259 </span> : // For any other ERC20</a>
|
||
|
<a name="260"><span class="lineNum"> 260 </span><span class="lineNoCov"> 0 : uint256 totalBalance = _token.balanceOf(address(this));</span></a>
|
||
|
<a name="261"><span class="lineNum"> 261 </span><span class="lineNoCov"> 0 : uint256 balance = Math.min(totalBalance, _amount);</span></a>
|
||
|
<a name="262"><span class="lineNum"> 262 </span><span class="lineNoCov"> 0 : require(balance > 0, "TORN: trying to send 0 balance");</span></a>
|
||
|
<a name="263"><span class="lineNum"> 263 </span><span class="lineNoCov"> 0 : _token.safeTransfer(_to, balance);</span></a>
|
||
|
<a name="264"><span class="lineNum"> 264 </span> : }</a>
|
||
|
<a name="265"><span class="lineNum"> 265 </span> : }</a>
|
||
|
<a name="266"><span class="lineNum"> 266 </span> : </a>
|
||
|
<a name="267"><span class="lineNum"> 267 </span> : /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SETTERS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */</a>
|
||
|
<a name="268"><span class="lineNum"> 268 </span> : </a>
|
||
|
<a name="269"><span class="lineNum"> 269 </span> : function approveTokenForInstance(IERC20 _token, address _spender, uint256 _amount)</a>
|
||
|
<a name="270"><span class="lineNum"> 270 </span> : external</a>
|
||
|
<a name="271"><span class="lineNum"> 271 </span> : onlyInstanceRegistry</a>
|
||
|
<a name="272"><span class="lineNum"> 272 </span> : {</a>
|
||
|
<a name="273"><span class="lineNum"> 273 </span><span class="lineCov"> 64 : _token.safeApprove(_spender, _amount);</span></a>
|
||
|
<a name="274"><span class="lineNum"> 274 </span><span class="lineCov"> 64 : emit TokenApproved(_spender, _amount);</span></a>
|
||
|
<a name="275"><span class="lineNum"> 275 </span> : }</a>
|
||
|
<a name="276"><span class="lineNum"> 276 </span> : </a>
|
||
|
<a name="277"><span class="lineNum"> 277 </span> : function setInstanceRegistry(address _newInstanceRegistryProxyAddress) external onlyGovernance {</a>
|
||
|
<a name="278"><span class="lineNum"> 278 </span><span class="lineNoCov"> 0 : instanceRegistry = InstanceRegistry(_newInstanceRegistryProxyAddress);</span></a>
|
||
|
<a name="279"><span class="lineNum"> 279 </span><span class="lineNoCov"> 0 : emit InstanceRegistryUpdated(_newInstanceRegistryProxyAddress);</span></a>
|
||
|
<a name="280"><span class="lineNum"> 280 </span> : }</a>
|
||
|
<a name="281"><span class="lineNum"> 281 </span> : </a>
|
||
|
<a name="282"><span class="lineNum"> 282 </span> : function setRelayerRegistry(address _newRelayerRegistryProxyAddress) external onlyGovernance {</a>
|
||
|
<a name="283"><span class="lineNum"> 283 </span><span class="lineNoCov"> 0 : relayerRegistry = RelayerRegistry(_newRelayerRegistryProxyAddress);</span></a>
|
||
|
<a name="284"><span class="lineNum"> 284 </span><span class="lineNoCov"> 0 : emit RelayerRegistryUpdated(_newRelayerRegistryProxyAddress);</span></a>
|
||
|
<a name="285"><span class="lineNum"> 285 </span> : }</a>
|
||
|
<a name="286"><span class="lineNum"> 286 </span> : </a>
|
||
|
<a name="287"><span class="lineNum"> 287 </span> : function setFeeOracleManager(address _newFeeOracleManagerProxyAddress) external onlyGovernance {</a>
|
||
|
<a name="288"><span class="lineNum"> 288 </span><span class="lineNoCov"> 0 : feeOracleManager = FeeOracleManager(_newFeeOracleManagerProxyAddress);</span></a>
|
||
|
<a name="289"><span class="lineNum"> 289 </span><span class="lineNoCov"> 0 : emit FeeOracleManagerUpdated(_newFeeOracleManagerProxyAddress);</span></a>
|
||
|
<a name="290"><span class="lineNum"> 290 </span> : }</a>
|
||
|
<a name="291"><span class="lineNum"> 291 </span> : }</a>
|
||
|
</pre>
|
||
|
</td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
<br>
|
||
|
|
||
|
<table width="100%" border=0 cellspacing=0 cellpadding=0>
|
||
|
<tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
|
||
|
<tr><td class="versionInfo">Generated by: <a href="https://github.com/linux-test-project/lcov" target="_parent">LCOV version 1.16</a></td></tr>
|
||
|
</table>
|
||
|
<br>
|
||
|
|
||
|
</body>
|
||
|
</html>
|