From 1f1964417a7376899aa2de440021926942f267a3 Mon Sep 17 00:00:00 2001 From: Drygin Date: Sat, 22 Jan 2022 03:23:33 +0300 Subject: [PATCH] linter fixes --- contracts/Mocks/WETH.sol | 10 ++----- contracts/TornadoPool.sol | 6 +++- contracts/bridge/L1Unwrapper.sol | 18 ++++++------ contracts/libraries/Bytes.sol | 47 ++++++++++++++++---------------- src/index.js | 12 +++++++- test/full.test.js | 2 +- 6 files changed, 52 insertions(+), 43 deletions(-) diff --git a/contracts/Mocks/WETH.sol b/contracts/Mocks/WETH.sol index 981eca4..21231ef 100644 --- a/contracts/Mocks/WETH.sol +++ b/contracts/Mocks/WETH.sol @@ -5,19 +5,15 @@ import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; contract WETH is ERC20 { - - constructor( - string memory name, - string memory ticker - ) ERC20(name, ticker) {} + constructor(string memory name, string memory ticker) ERC20(name, ticker) {} function deposit() external payable { _mint(msg.sender, msg.value); } function withdraw(uint256 value) external { - _burn(msg.sender, value); - (bool success, ) = msg.sender.call{value: value}(""); + _burn(msg.sender, value); + (bool success, ) = msg.sender.call{ value: value }(""); require(success, "WETH: ETH transfer failed"); } } diff --git a/contracts/TornadoPool.sol b/contracts/TornadoPool.sol index 3f25299..ef2d02d 100644 --- a/contracts/TornadoPool.sol +++ b/contracts/TornadoPool.sol @@ -276,7 +276,11 @@ contract TornadoPool is MerkleTreeWithHistory, IERC20Receiver, ReentrancyGuard, if (_extData.extAmount < 0) { require(_extData.recipient != address(0), "Can't withdraw to zero address"); if (_extData.isL1Withdrawal) { - token.transferAndCall(omniBridge, uint256(-_extData.extAmount), abi.encodePacked(l1Unwrapper, _extData.recipient, _extData.l1Fee)); + token.transferAndCall( + omniBridge, + uint256(-_extData.extAmount), + abi.encodePacked(l1Unwrapper, _extData.recipient, _extData.l1Fee) + ); } else { token.transfer(_extData.recipient, uint256(-_extData.extAmount)); } diff --git a/contracts/bridge/L1Unwrapper.sol b/contracts/bridge/L1Unwrapper.sol index 5b6f703..e438cd6 100644 --- a/contracts/bridge/L1Unwrapper.sol +++ b/contracts/bridge/L1Unwrapper.sol @@ -67,22 +67,22 @@ contract L1Unwrapper is WETHOmnibridgeRouter { } /** - * @dev Bridged callback function used for unwrapping received tokens. - * Can only be called by the associated Omnibridge contract. - * @param _token bridged token contract address, should be WETH. - * @param _value amount of bridged/received tokens. - * @param _data extra data passed alongside with relayTokensAndCall on the other side of the bridge. - * Should contain coins receiver address and L1 executer fee amount. - */ + * @dev Bridged callback function used for unwrapping received tokens. + * Can only be called by the associated Omnibridge contract. + * @param _token bridged token contract address, should be WETH. + * @param _value amount of bridged/received tokens. + * @param _data extra data passed alongside with relayTokensAndCall on the other side of the bridge. + * Should contain coins receiver address and L1 executer fee amount. + */ function onTokenBridged( address _token, uint256 _value, bytes memory _data - ) override external { + ) external override { require(_token == address(WETH)); require(msg.sender == address(bridge)); require(_data.length == 52); - + WETH.withdraw(_value); uint256 l1Fee = BytesHelper.sliceToUint(_data, 20); diff --git a/contracts/libraries/Bytes.sol b/contracts/libraries/Bytes.sol index fcfef76..08dc98f 100644 --- a/contracts/libraries/Bytes.sol +++ b/contracts/libraries/Bytes.sol @@ -6,31 +6,30 @@ pragma solidity ^0.7.0; * @dev Helper methods to transform bytes to other solidity types. */ library BytesHelper { - /** - * @dev Truncate bytes array if its size is more than 20 bytes. - * NOTE: This function does not perform any checks on the received parameter. - * Make sure that the _bytes argument has a correct length, not less than 20 bytes. - * A case when _bytes has length less than 20 will lead to the undefined behaviour, - * since assembly will read data from memory that is not related to the _bytes argument. - * @param _bytes to be converted to address type - * @return addr address included in the firsts 20 bytes of the bytes array in parameter. - */ - function bytesToAddress(bytes memory _bytes) internal pure returns (address addr) { - assembly { - addr := mload(add(_bytes, 20)) - } + /** + * @dev Truncate bytes array if its size is more than 20 bytes. + * NOTE: This function does not perform any checks on the received parameter. + * Make sure that the _bytes argument has a correct length, not less than 20 bytes. + * A case when _bytes has length less than 20 will lead to the undefined behaviour, + * since assembly will read data from memory that is not related to the _bytes argument. + * @param _bytes to be converted to address type + * @return addr address included in the firsts 20 bytes of the bytes array in parameter. + */ + function bytesToAddress(bytes memory _bytes) internal pure returns (address addr) { + assembly { + addr := mload(add(_bytes, 20)) } + } - /** - * @param _bytes it's 32 length slice to be converted to uint type - * @param _start start index of slice - * @return x uint included in the 32 length slice of the bytes array in parameter. - */ - function sliceToUint(bytes memory _bytes, uint _start) internal pure returns (uint x) - { - require(_bytes.length >= _start + 32, "slicing out of range"); - assembly { - x := mload(add(_bytes, add(0x20, _start))) - } + /** + * @param _bytes it's 32 length slice to be converted to uint type + * @param _start start index of slice + * @return x uint included in the 32 length slice of the bytes array in parameter. + */ + function sliceToUint(bytes memory _bytes, uint256 _start) internal pure returns (uint256 x) { + require(_bytes.length >= _start + 32, "slicing out of range"); + assembly { + x := mload(add(_bytes, add(0x20, _start))) } + } } diff --git a/src/index.js b/src/index.js index 4166969..3aec910 100644 --- a/src/index.js +++ b/src/index.js @@ -16,7 +16,17 @@ async function buildMerkleTree({ tornadoPool }) { return new MerkleTree(MERKLE_TREE_HEIGHT, leaves, { hashFunction: poseidonHash2 }) } -async function getProof({ inputs, outputs, tree, extAmount, fee, recipient, relayer, isL1Withdrawal, l1Fee }) { +async function getProof({ + inputs, + outputs, + tree, + extAmount, + fee, + recipient, + relayer, + isL1Withdrawal, + l1Fee, +}) { inputs = shuffle(inputs) outputs = shuffle(outputs) diff --git a/test/full.test.js b/test/full.test.js index 91d236e..15c3244 100644 --- a/test/full.test.js +++ b/test/full.test.js @@ -35,7 +35,7 @@ describe('TornadoPool', function () { await token.mint(sender.address, utils.parseEther('10000')) const l1Token = await deploy('WETH', 'Wrapped ETH', 'WETH') - await l1Token.deposit({value: utils.parseEther('3')}) + await l1Token.deposit({ value: utils.parseEther('3') }) const amb = await deploy('MockAMB', gov.address, l1ChainId) const omniBridge = await deploy('MockOmniBridge', amb.address)