infrastructure-upgrade/coverage/v1/tornado-proxy/TornadoRouter.sol.gcov.html
AlienTornadosaurusHex 1a6a4ebfbb mostly testing finalized design
Signed-off-by: AlienTornadosaurusHex <>
2023-06-20 21:04:29 +00:00

201 lines
15 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 - v1/tornado-proxy/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">v1/tornado-proxy</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">0</td>
<td class="headerCovTableEntry">22</td>
<td class="headerCovTableEntryLo">0.0 %</td>
</tr>
<tr>
<td class="headerItem">Date:</td>
<td class="headerValue">2023-06-20 21:04:08</td>
<td></td>
<td class="headerItem">Functions:</td>
<td class="headerCovTableEntry">0</td>
<td class="headerCovTableEntry">5</td>
<td class="headerCovTableEntryLo">0.0 %</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 &gt;=0.6.0 &lt;0.8.0;</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> : import &quot;@openzeppelin/contracts/token/ERC20/IERC20.sol&quot;;</a>
<a name="7"><span class="lineNum"> 7 </span> : import &quot;@openzeppelin/contracts/token/ERC20/SafeERC20.sol&quot;;</a>
<a name="8"><span class="lineNum"> 8 </span> : import &quot;@openzeppelin/contracts/math/Math.sol&quot;;</a>
<a name="9"><span class="lineNum"> 9 </span> : import &quot;tornado-anonymity-mining/contracts/interfaces/ITornadoInstance.sol&quot;;</a>
<a name="10"><span class="lineNum"> 10 </span> : import &quot;torn-token/contracts/ENS.sol&quot;;</a>
<a name="11"><span class="lineNum"> 11 </span> : import &quot;./InstanceRegistry.sol&quot;;</a>
<a name="12"><span class="lineNum"> 12 </span> : import &quot;../RelayerRegistry.sol&quot;;</a>
<a name="13"><span class="lineNum"> 13 </span> : </a>
<a name="14"><span class="lineNum"> 14 </span> : contract TornadoRouter is EnsResolve {</a>
<a name="15"><span class="lineNum"> 15 </span> : using SafeERC20 for IERC20;</a>
<a name="16"><span class="lineNum"> 16 </span> : </a>
<a name="17"><span class="lineNum"> 17 </span> : event EncryptedNote(address indexed sender, bytes encryptedNote);</a>
<a name="18"><span class="lineNum"> 18 </span> : </a>
<a name="19"><span class="lineNum"> 19 </span> : address public immutable governance;</a>
<a name="20"><span class="lineNum"> 20 </span> : InstanceRegistry public immutable instanceRegistry;</a>
<a name="21"><span class="lineNum"> 21 </span> : RelayerRegistry public immutable relayerRegistry;</a>
<a name="22"><span class="lineNum"> 22 </span> : </a>
<a name="23"><span class="lineNum"> 23 </span> : modifier onlyGovernance() {</a>
<a name="24"><span class="lineNum"> 24 </span> : require(msg.sender == governance, &quot;Not authorized&quot;);</a>
<a name="25"><span class="lineNum"> 25 </span> : _;</a>
<a name="26"><span class="lineNum"> 26 </span> : }</a>
<a name="27"><span class="lineNum"> 27 </span> : </a>
<a name="28"><span class="lineNum"> 28 </span> : modifier onlyInstanceRegistry() {</a>
<a name="29"><span class="lineNum"> 29 </span> : require(msg.sender == address(instanceRegistry), &quot;Not authorized&quot;);</a>
<a name="30"><span class="lineNum"> 30 </span> : _;</a>
<a name="31"><span class="lineNum"> 31 </span> : }</a>
<a name="32"><span class="lineNum"> 32 </span> : </a>
<a name="33"><span class="lineNum"> 33 </span> : constructor(</a>
<a name="34"><span class="lineNum"> 34 </span> : address _governance,</a>
<a name="35"><span class="lineNum"> 35 </span> : bytes32 _instanceRegistry,</a>
<a name="36"><span class="lineNum"> 36 </span> : bytes32 _relayerRegistry</a>
<a name="37"><span class="lineNum"> 37 </span> : ) public {</a>
<a name="38"><span class="lineNum"> 38 </span> : governance = _governance;</a>
<a name="39"><span class="lineNum"> 39 </span> : instanceRegistry = InstanceRegistry(resolve(_instanceRegistry));</a>
<a name="40"><span class="lineNum"> 40 </span> : relayerRegistry = RelayerRegistry(resolve(_relayerRegistry));</a>
<a name="41"><span class="lineNum"> 41 </span> : }</a>
<a name="42"><span class="lineNum"> 42 </span> : </a>
<a name="43"><span class="lineNum"> 43 </span> : function deposit(</a>
<a name="44"><span class="lineNum"> 44 </span> : ITornadoInstance _tornado,</a>
<a name="45"><span class="lineNum"> 45 </span> : bytes32 _commitment,</a>
<a name="46"><span class="lineNum"> 46 </span> : bytes calldata _encryptedNote</a>
<a name="47"><span class="lineNum"> 47 </span> : ) public payable virtual {</a>
<a name="48"><span class="lineNum"> 48 </span><span class="lineNoCov"> 0 : (bool isERC20, IERC20 token, InstanceRegistry.InstanceState state, , ) = instanceRegistry.instances(_tornado);</span></a>
<a name="49"><span class="lineNum"> 49 </span><span class="lineNoCov"> 0 : require(state != InstanceRegistry.InstanceState.DISABLED, &quot;The instance is not supported&quot;);</span></a>
<a name="50"><span class="lineNum"> 50 </span> : </a>
<a name="51"><span class="lineNum"> 51 </span><span class="lineNoCov"> 0 : if (isERC20) {</span></a>
<a name="52"><span class="lineNum"> 52 </span><span class="lineNoCov"> 0 : token.safeTransferFrom(msg.sender, address(this), _tornado.denomination());</span></a>
<a name="53"><span class="lineNum"> 53 </span> : }</a>
<a name="54"><span class="lineNum"> 54 </span><span class="lineNoCov"> 0 : _tornado.deposit{ value: msg.value }(_commitment);</span></a>
<a name="55"><span class="lineNum"> 55 </span><span class="lineNoCov"> 0 : emit EncryptedNote(msg.sender, _encryptedNote);</span></a>
<a name="56"><span class="lineNum"> 56 </span> : }</a>
<a name="57"><span class="lineNum"> 57 </span> : </a>
<a name="58"><span class="lineNum"> 58 </span> : function withdraw(</a>
<a name="59"><span class="lineNum"> 59 </span> : ITornadoInstance _tornado,</a>
<a name="60"><span class="lineNum"> 60 </span> : bytes calldata _proof,</a>
<a name="61"><span class="lineNum"> 61 </span> : bytes32 _root,</a>
<a name="62"><span class="lineNum"> 62 </span> : bytes32 _nullifierHash,</a>
<a name="63"><span class="lineNum"> 63 </span> : address payable _recipient,</a>
<a name="64"><span class="lineNum"> 64 </span> : address payable _relayer,</a>
<a name="65"><span class="lineNum"> 65 </span> : uint256 _fee,</a>
<a name="66"><span class="lineNum"> 66 </span> : uint256 _refund</a>
<a name="67"><span class="lineNum"> 67 </span> : ) public payable virtual {</a>
<a name="68"><span class="lineNum"> 68 </span><span class="lineNoCov"> 0 : (, , InstanceRegistry.InstanceState state, , ) = instanceRegistry.instances(_tornado);</span></a>
<a name="69"><span class="lineNum"> 69 </span><span class="lineNoCov"> 0 : require(state != InstanceRegistry.InstanceState.DISABLED, &quot;The instance is not supported&quot;);</span></a>
<a name="70"><span class="lineNum"> 70 </span><span class="lineNoCov"> 0 : relayerRegistry.burn(msg.sender, _relayer, _tornado);</span></a>
<a name="71"><span class="lineNum"> 71 </span> : </a>
<a name="72"><span class="lineNum"> 72 </span><span class="lineNoCov"> 0 : _tornado.withdraw{ value: msg.value }(_proof, _root, _nullifierHash, _recipient, _relayer, _fee, _refund);</span></a>
<a name="73"><span class="lineNum"> 73 </span> : }</a>
<a name="74"><span class="lineNum"> 74 </span> : </a>
<a name="75"><span class="lineNum"> 75 </span> : /**</a>
<a name="76"><span class="lineNum"> 76 </span> : * @dev Sets `amount` allowance of `_spender` over the router's (this contract) tokens.</a>
<a name="77"><span class="lineNum"> 77 </span> : */</a>
<a name="78"><span class="lineNum"> 78 </span> : function approveExactToken(</a>
<a name="79"><span class="lineNum"> 79 </span> : IERC20 _token,</a>
<a name="80"><span class="lineNum"> 80 </span> : address _spender,</a>
<a name="81"><span class="lineNum"> 81 </span> : uint256 _amount</a>
<a name="82"><span class="lineNum"> 82 </span> : ) external onlyInstanceRegistry {</a>
<a name="83"><span class="lineNum"> 83 </span><span class="lineNoCov"> 0 : _token.safeApprove(_spender, _amount);</span></a>
<a name="84"><span class="lineNum"> 84 </span> : }</a>
<a name="85"><span class="lineNum"> 85 </span> : </a>
<a name="86"><span class="lineNum"> 86 </span> : /**</a>
<a name="87"><span class="lineNum"> 87 </span> : * @notice Manually backup encrypted notes</a>
<a name="88"><span class="lineNum"> 88 </span> : */</a>
<a name="89"><span class="lineNum"> 89 </span> : function backupNotes(bytes[] calldata _encryptedNotes) external virtual {</a>
<a name="90"><span class="lineNum"> 90 </span><span class="lineNoCov"> 0 : for (uint256 i = 0; i &lt; _encryptedNotes.length; i++) {</span></a>
<a name="91"><span class="lineNum"> 91 </span><span class="lineNoCov"> 0 : emit EncryptedNote(msg.sender, _encryptedNotes[i]);</span></a>
<a name="92"><span class="lineNum"> 92 </span> : }</a>
<a name="93"><span class="lineNum"> 93 </span> : }</a>
<a name="94"><span class="lineNum"> 94 </span> : </a>
<a name="95"><span class="lineNum"> 95 </span> : /// @dev Method to claim junk and accidentally sent tokens</a>
<a name="96"><span class="lineNum"> 96 </span> : function rescueTokens(</a>
<a name="97"><span class="lineNum"> 97 </span> : IERC20 _token,</a>
<a name="98"><span class="lineNum"> 98 </span> : address payable _to,</a>
<a name="99"><span class="lineNum"> 99 </span> : uint256 _amount</a>
<a name="100"><span class="lineNum"> 100 </span> : ) external virtual onlyGovernance {</a>
<a name="101"><span class="lineNum"> 101 </span><span class="lineNoCov"> 0 : require(_to != address(0), &quot;TORN: can not send to zero address&quot;);</span></a>
<a name="102"><span class="lineNum"> 102 </span> : </a>
<a name="103"><span class="lineNum"> 103 </span><span class="lineNoCov"> 0 : if (_token == IERC20(0)) {</span></a>
<a name="104"><span class="lineNum"> 104 </span> : // for Ether</a>
<a name="105"><span class="lineNum"> 105 </span><span class="lineNoCov"> 0 : uint256 totalBalance = address(this).balance;</span></a>
<a name="106"><span class="lineNum"> 106 </span><span class="lineNoCov"> 0 : uint256 balance = Math.min(totalBalance, _amount);</span></a>
<a name="107"><span class="lineNum"> 107 </span><span class="lineNoCov"> 0 : _to.transfer(balance);</span></a>
<a name="108"><span class="lineNum"> 108 </span> : } else {</a>
<a name="109"><span class="lineNum"> 109 </span> : // any other erc20</a>
<a name="110"><span class="lineNum"> 110 </span><span class="lineNoCov"> 0 : uint256 totalBalance = _token.balanceOf(address(this));</span></a>
<a name="111"><span class="lineNum"> 111 </span><span class="lineNoCov"> 0 : uint256 balance = Math.min(totalBalance, _amount);</span></a>
<a name="112"><span class="lineNum"> 112 </span><span class="lineNoCov"> 0 : require(balance &gt; 0, &quot;TORN: trying to send 0 balance&quot;);</span></a>
<a name="113"><span class="lineNum"> 113 </span><span class="lineNoCov"> 0 : _token.safeTransfer(_to, balance);</span></a>
<a name="114"><span class="lineNum"> 114 </span> : }</a>
<a name="115"><span class="lineNum"> 115 </span> : }</a>
<a name="116"><span class="lineNum"> 116 </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>