From f12611f4df0bc981fb32d5549e4d0155a578010e Mon Sep 17 00:00:00 2001 From: thal0x Date: Wed, 6 Nov 2024 08:48:06 -0600 Subject: [PATCH] only allow gateway as caller in GoFastCaller --- solidity/src/FastTransferGateway.sol | 3 ++- .../{GoFastMulticall.sol => GoFastCaller.sol} | 18 +++++++++++++++++- solidity/test/ERC7683.t.sol | 6 ++++-- solidity/test/FastTransferGateway.t.sol | 6 ++++-- 4 files changed, 27 insertions(+), 6 deletions(-) rename solidity/src/{GoFastMulticall.sol => GoFastCaller.sol} (60%) diff --git a/solidity/src/FastTransferGateway.sol b/solidity/src/FastTransferGateway.sol index d461906..090561f 100644 --- a/solidity/src/FastTransferGateway.sol +++ b/solidity/src/FastTransferGateway.sol @@ -16,7 +16,8 @@ import {OrderEncoder} from "./libraries/OrderEncoder.sol"; import {IPermit2} from "./interfaces/IPermit2.sol"; import {IMailbox} from "./interfaces/hyperlane/IMailbox.sol"; -import {GoFastCaller} from "./GoFastMulticall.sol"; +import {GoFastCaller} from "./GoFastCaller.sol"; + // Structure that contains the order details required to settle or refund an order struct SettlementDetails { diff --git a/solidity/src/GoFastMulticall.sol b/solidity/src/GoFastCaller.sol similarity index 60% rename from solidity/src/GoFastMulticall.sol rename to solidity/src/GoFastCaller.sol index 46522e9..44dd486 100644 --- a/solidity/src/GoFastMulticall.sol +++ b/solidity/src/GoFastCaller.sol @@ -3,12 +3,28 @@ pragma solidity ^0.8.13; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; +import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; -contract GoFastCaller { +contract GoFastCaller is Ownable { using SafeERC20 for IERC20; + address public gateway; + + constructor(address _owner) Ownable(_owner) {} + + function setGateway(address _gateway) external onlyOwner { + gateway = _gateway; + } + + modifier onlyGateway() { + require(gateway != address(0), "GoFastCaller: gateway not set"); + require(msg.sender == gateway, "GoFastCaller: sender not gateway"); + _; + } + function execute(address _target, address _token, uint256 _amount, bytes memory _data) external + onlyGateway returns (bool, bytes memory) { IERC20(_token).forceApprove(_target, _amount); diff --git a/solidity/test/ERC7683.t.sol b/solidity/test/ERC7683.t.sol index b37cd20..74f03cd 100644 --- a/solidity/test/ERC7683.t.sol +++ b/solidity/test/ERC7683.t.sol @@ -12,7 +12,7 @@ import {IPermit2} from "../src/interfaces/IPermit2.sol"; import {OnchainCrossChainOrder, GaslessCrossChainOrder} from "../src/erc7683/ERC7683.sol"; import {GoFastERC7683, OrderData} from "../src/GoFastERC7683.sol"; import {OrderEncoder} from "../src/libraries/OrderEncoder.sol"; -import {GoFastCaller} from "../src/GoFastMulticall.sol"; +import {GoFastCaller} from "../src/GoFastCaller.sol"; interface IUniswapV2Router02 { function swapExactTokensForTokens( @@ -56,7 +56,7 @@ contract ERC7683Test is Test { solver = address(2); mailbox = address(0x979Ca5202784112f4738403dBec5D0F3B9daabB9); - GoFastCaller goFastCaller = new GoFastCaller(); + GoFastCaller goFastCaller = new GoFastCaller(address(this)); FastTransferGateway gatewayImpl = new FastTransferGateway(); ERC1967Proxy gatewayProxy = new ERC1967Proxy( @@ -74,6 +74,8 @@ contract ERC7683Test is Test { ); gateway = FastTransferGateway(address(gatewayProxy)); + goFastCaller.setGateway(address(gateway)); + GoFastERC7683 goFastERC7683Impl = new GoFastERC7683(); ERC1967Proxy goFastERC7683Proxy = new ERC1967Proxy( address(goFastERC7683Impl), diff --git a/solidity/test/FastTransferGateway.t.sol b/solidity/test/FastTransferGateway.t.sol index 20f8483..197981b 100644 --- a/solidity/test/FastTransferGateway.t.sol +++ b/solidity/test/FastTransferGateway.t.sol @@ -11,7 +11,7 @@ import {TypeCasts} from "../src/libraries/TypeCasts.sol"; import {OrderEncoder} from "../src/libraries/OrderEncoder.sol"; import {IPermit2} from "../src/interfaces/IPermit2.sol"; import {IMailbox} from "../src/interfaces/hyperlane/IMailbox.sol"; -import {GoFastCaller} from "../src/GoFastMulticall.sol"; +import {GoFastCaller} from "../src/GoFastCaller.sol"; interface IUniswapV2Router02 { function swapExactTokensForTokens( @@ -55,7 +55,7 @@ contract FastTransferGatewayTest is Test { solver = address(2); mailbox = address(0x979Ca5202784112f4738403dBec5D0F3B9daabB9); - GoFastCaller _goFastCaller = new GoFastCaller(); + GoFastCaller _goFastCaller = new GoFastCaller(address(this)); goFastCaller = address(_goFastCaller); FastTransferGateway gatewayImpl = new FastTransferGateway(); ERC1967Proxy gatewayProxy = new ERC1967Proxy( @@ -72,6 +72,8 @@ contract FastTransferGatewayTest is Test { ) ); gateway = FastTransferGateway(address(gatewayProxy)); + + _goFastCaller.setGateway(address(gateway)); } function test_submitAndSettle() public {