From ca5401806d732e811798967ee6afb9a84d980232 Mon Sep 17 00:00:00 2001 From: skosito Date: Thu, 8 Aug 2024 15:52:12 +0200 Subject: [PATCH] locanet fixes --- v2/scripts/localnet/EvmDepositAndCall.s.sol | 5 +++++ v2/scripts/localnet/ZevmWithdrawAndCall.s.sol | 2 +- v2/scripts/localnet/worker.ts | 4 ++-- v2/src/evm/GatewayEVM.sol | 1 + v2/test/GatewayEVM.t.sol | 7 +++++++ 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/v2/scripts/localnet/EvmDepositAndCall.s.sol b/v2/scripts/localnet/EvmDepositAndCall.s.sol index e44c3e88..42ad10a4 100644 --- a/v2/scripts/localnet/EvmDepositAndCall.s.sol +++ b/v2/scripts/localnet/EvmDepositAndCall.s.sol @@ -3,6 +3,7 @@ pragma solidity 0.8.26; import "forge-std/Script.sol"; import "src/evm/GatewayEVM.sol"; +import "src/evm/ERC20Custody.sol"; import "test/utils/TestZContract.sol"; import "test/utils/TestERC20.sol"; @@ -12,6 +13,7 @@ contract EvmDepositAndCallScript is Script { function run() external { address payable gatewayEVMAddress = payable(vm.envOr("GATEWAY_EVM", 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0)); address payable zContractAddress = payable(vm.envOr("Z_CONTRACT", 0x68B1D87F95878fE05B998F19b66F4baba5De1aed)); + address custodyAddress = vm.envOr("CUSTODY", 0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9); address erc20Address = vm.envOr("ERC20", 0x9A676e781A523b5d0C0e43731313A708CB607508); uint256 amount = vm.envOr("AMOUNT", uint256(1)); string memory mnemonic = "test test test test test test test test test test test junk"; @@ -23,6 +25,9 @@ contract EvmDepositAndCallScript is Script { GatewayEVM gatewayEVM = GatewayEVM(gatewayEVMAddress); TestZContract zContract = TestZContract(zContractAddress); TestERC20 erc20 = TestERC20(erc20Address); + ERC20Custody custody = ERC20Custody(custodyAddress); + + custody.whitelist(erc20Address); // Approve the ERC20 transfer erc20.approve(gatewayEVMAddress, amount); diff --git a/v2/scripts/localnet/ZevmWithdrawAndCall.s.sol b/v2/scripts/localnet/ZevmWithdrawAndCall.s.sol index fed5bf3b..69babcd4 100644 --- a/v2/scripts/localnet/ZevmWithdrawAndCall.s.sol +++ b/v2/scripts/localnet/ZevmWithdrawAndCall.s.sol @@ -4,7 +4,7 @@ pragma solidity 0.8.26; import "forge-std/Script.sol"; import "src/zevm/GatewayZEVM.sol"; import "test/utils/ReceiverEVM.sol"; -import "test/utils/ZRC20.sol"; +import "src/zevm/ZRC20.sol"; // ZevmWithdrawAndCallScript executes withdrawAndCall method on GatewayZEVM and it should be used on localnet. // It uses anvil private key, and sets default contract addresses deployed on fresh localnet, that can be overriden with env vars. diff --git a/v2/scripts/localnet/worker.ts b/v2/scripts/localnet/worker.ts index ed3f37d3..95298ee6 100644 --- a/v2/scripts/localnet/worker.ts +++ b/v2/scripts/localnet/worker.ts @@ -246,7 +246,7 @@ const startWorker = async () => { chainID, }, testContracts.zrc20.target, - 0, + 1, zContract, payload, deployOpts @@ -271,7 +271,7 @@ const startWorker = async () => { .execute( [protocolContracts.gatewayZEVM.target, await fungibleModuleSigner.getAddress(), 1], asset, - 0, + 1, receiver, payload, deployOpts diff --git a/v2/src/evm/GatewayEVM.sol b/v2/src/evm/GatewayEVM.sol index 3daf28fb..ae81dc77 100644 --- a/v2/src/evm/GatewayEVM.sol +++ b/v2/src/evm/GatewayEVM.sol @@ -269,6 +269,7 @@ contract GatewayEVM is /// @param receiver Address of the receiver. /// @param payload Calldata to pass to the call. function call(address receiver, bytes calldata payload) external whenNotPaused nonReentrant { + if (receiver == address(0)) revert ZeroAddress(); emit Call(msg.sender, receiver, payload); } diff --git a/v2/test/GatewayEVM.t.sol b/v2/test/GatewayEVM.t.sol index ed0514f3..81660e30 100644 --- a/v2/test/GatewayEVM.t.sol +++ b/v2/test/GatewayEVM.t.sol @@ -488,4 +488,11 @@ contract GatewayEVMInboundTest is Test, IGatewayEVMErrors, IGatewayEVMEvents, IR emit Call(owner, destination, payload); gateway.call(destination, payload); } + + function testCallWithPayloadFailsIfDestinationIsZeroAddress() public { + bytes memory payload = abi.encodeWithSignature("hello(address)", destination); + + vm.expectRevert(ZeroAddress.selector); + gateway.call(address(0), payload); + } }