Skip to content

Commit

Permalink
throw error if function doesn't exist when making arbitrary call
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Nov 12, 2024
1 parent 0b47bea commit e47cc0e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/localnet/src/handleOnZEVMCalled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 11 additions & 1 deletion packages/localnet/src/handleOnZEVMWithdrawnAndCalled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e47cc0e

Please sign in to comment.