From e47cc0ebcb2ddf5dadf8554c3d412abaf172d46c Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Tue, 12 Nov 2024 14:07:33 +0300 Subject: [PATCH] throw error if function doesn't exist when making arbitrary call --- packages/localnet/src/handleOnZEVMCalled.ts | 10 ++++++++++ .../localnet/src/handleOnZEVMWithdrawnAndCalled.ts | 12 +++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/localnet/src/handleOnZEVMCalled.ts b/packages/localnet/src/handleOnZEVMCalled.ts index ba7de4a..d4ae7af 100644 --- a/packages/localnet/src/handleOnZEVMCalled.ts +++ b/packages/localnet/src/handleOnZEVMCalled.ts @@ -43,6 +43,16 @@ export const handleOnZEVMCalled = async ({ }; log(chainID, `Calling ${receiver} with message ${message}`); + if (isArbitraryCall) { + const selector = message.slice(0, 10); + const code = await provider.getCode(receiver); + if (!code.includes(selector.slice(2))) { + throw new Error( + `Receiver contract does not contain function with selector ${selector}` + ); + } + } + const executeTx = await evmContracts[chainID].gatewayEVM .connect(tss) .execute(messageContext, receiver, message, deployOpts); diff --git a/packages/localnet/src/handleOnZEVMWithdrawnAndCalled.ts b/packages/localnet/src/handleOnZEVMWithdrawnAndCalled.ts index f823df8..e567a2c 100644 --- a/packages/localnet/src/handleOnZEVMWithdrawnAndCalled.ts +++ b/packages/localnet/src/handleOnZEVMWithdrawnAndCalled.ts @@ -56,7 +56,17 @@ export const handleOnZEVMWithdrawnAndCalled = async ({ const zrc20Contract = new ethers.Contract(zrc20, ZRC20.abi, deployer); const coinType = await zrc20Contract.COIN_TYPE(); const isGasToken = coinType === 1n; - const isERC20orZETA = coinType === 2n; + + if (isArbitraryCall) { + const selector = message.slice(0, 10); + const code = await provider.getCode(receiver); + if (!code.includes(selector.slice(2))) { + throw new Error( + `Receiver contract does not contain function with selector ${selector}` + ); + } + } + log(chainID, `Calling ${receiver} with message ${message}`); if (isGasToken) { const executeTx = await evmContracts[chainID].gatewayEVM