Context (Verify msg.sender)

anyCall V6 is permissionless so you need to verify the msg.sender on the source chain because anyone can call your destination contract.

This context function exists inside the AnyCallExecutor contract

contract AnyCallExecutor {
    struct Context {
        address from;
        uint256 fromChainID;
        uint256 nonce;
    }

    Context public context;}

Returned Information

  1. address from: The address on the source chain that called anyCall.

  2. uint256 fromChainID: The source chain id.

  3. uint256 nonce: The total amount of times anyCall has been called.

How to import the context interface

An interface should be created to get the context information, it could be the same interface as the interface for anyCall .

interface CallProxy{
    function anyCall(
        address _to,
        bytes calldata _data,
        address _fallback,
        uint256 _toChainID,
        uint256 _flags

    ) external payable;

    function context() external view returns (address from, uint256 fromChainID, uint256 nonce);
    
    function executor() external view returns (address executor);
}

Getting Context and Verify Sender

Note that the contract address for AnyCallExecutor is different from the address of AnyCallV6Proxy. Use the address of AnyCallExecutor to get Context information.

The address of AnyCallExecutor can be set in constuctor like this

  constructor(){
        anycallExecutor=CallProxy(anycallcontract).executor();
    }

Then context information can be fetched with the following codes and you can use a variable such as verifiedcaller to verify msg.sender on the source chain is authorized.

(address from, uint256 fromChainId,) = IAnycallV6Proxy(anycallExecutor).context();
require(verifiedcaller == from, "AnycallClient: wrong context");

Full Example: https://testnet.ftmscan.com/address/0xC939EbeedBdF61f839296cF326e9aE2a84C8022C#code

Last updated