linter fixes

This commit is contained in:
Drygin 2022-01-22 03:23:33 +03:00
parent bd4500d7ff
commit 1f1964417a
6 changed files with 52 additions and 43 deletions

View File

@ -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");
}
}

View File

@ -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));
}

View File

@ -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);

View File

@ -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)))
}
}
}

View File

@ -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)

View File

@ -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)