From 582533fa31b1c2096566df00b7e07350f677a647 Mon Sep 17 00:00:00 2001 From: Diana Carvalho Date: Tue, 11 Feb 2025 16:33:34 +0000 Subject: [PATCH] fix: Miscellaneous audit remarks - Move pause functions together - Add missing zero checks - Use openzepplin's sendValues instead of transfer --- don't change below this line --- ENG-4226 Took 25 minutes Took 2 minutes --- foundry/src/TychoRouter.sol | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/foundry/src/TychoRouter.sol b/foundry/src/TychoRouter.sol index 4b8aa1f..c2e0b52 100644 --- a/foundry/src/TychoRouter.sol +++ b/foundry/src/TychoRouter.sol @@ -9,6 +9,7 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; import "@openzeppelin/contracts/utils/Pausable.sol"; +import "@openzeppelin/contracts/utils/Address.sol"; import "@permit2/src/interfaces/IAllowanceTransfer.sol"; import "@uniswap/v3-updated/CallbackValidationV2.sol"; import "./ExecutionDispatcher.sol"; @@ -65,23 +66,18 @@ contract TychoRouter is address private immutable _usv3Factory; constructor(address _permit2, address weth, address usv3Factory) { + if ( + _permit2 == address(0) || weth == address(0) + || usv3Factory == address(0) + ) { + revert TychoRouter__AddressZero(); + } permit2 = IAllowanceTransfer(_permit2); _grantRole(DEFAULT_ADMIN_ROLE, msg.sender); _weth = IWETH(weth); - - if (usv3Factory == address(0)) { - revert TychoRouter__AddressZero(); - } _usv3Factory = usv3Factory; } - /** - * @dev Unpauses the contract - */ - function unpause() external onlyRole(UNPAUSER_ROLE) { - _unpause(); - } - /** * @notice Executes a swap operation based on a predefined swap graph, supporting internal token amount splits. * This function enables multi-step swaps, optional ETH wrapping/unwrapping, and validates the output amount @@ -161,8 +157,7 @@ contract TychoRouter is _unwrapETH(amountOut); } if (tokenOut == address(0)) { - // slither-disable-next-line arbitrary-send-eth - payable(receiver).transfer(amountOut); + Address.sendValue(payable(receiver), amountOut); } else { IERC20(tokenOut).safeTransfer(receiver, amountOut); } @@ -257,6 +252,13 @@ contract TychoRouter is _pause(); } + /** + * @dev Unpauses the contract + */ + function unpause() external onlyRole(UNPAUSER_ROLE) { + _unpause(); + } + /** * @dev Allows granting roles to multiple accounts in a single call. */