Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

This article examines Avalanche ICM. It covers the components and message flow so that readers without an engineering background can understand the overall architecture. It also explains the underlying mechanics in greater detail for engineers. The original figures are retained; some labels may remain in Japanese.

What is ICM?

Avalanche ICM (Interchain Messaging) enables L1 blockchains on Avalanche to send and receive messages. These messages can contain simple strings or data used to invoke functions, among other things. For example, an application can send a string to a contract on a destination L1, or burn ERC20 tokens on the source L1 and mint ERC20 tokens on the destination L1.

For more information about Avalanche ICM, see the following article.

Prerequisites

Before examining the ICM message flow, let's cover the concepts that underpin it.

P-Chain

In addition to the C-Chain and separately created L1 blockchains, Avalanche has the P-Chain. The P-Chain manages the validators responsible for block production and other activities on the C-Chain and individual L1s, as well as the AVAX staked by validators. When a new L1 is created, its information, including its validators and chain ID, must be registered on the P-Chain. The P-Chain is therefore central to validator management, staking, and the L1 lifecycle on Avalanche.

Validators

Validator diagram https://build.avax.network/academy/interchain-messaging/02-interoperability/03-multi-chain-networks

Each L1 on Avalanche has its own validators. These validators perform tasks such as producing blocks.

Validator diagram https://medium.com/coinmonks/avalanche-fundamentals-subnet-architecture-explained-e69f5aa3d75a

A validator is not restricted to a single L1; it can validate multiple L1s.

Validator diagram https://build.avax.network/blog/etna-upgrade-motivation

To become a validator of an L1, a participant must satisfy that L1's staking requirements for its native token.

Validator diagram https://build.avax.network/blog/etna-upgrade-motivation

Validators also pay a small monthly fee in AVAX to the P-Chain for registering their information.

BLS signatures

BLS signature diagram https://build.avax.network/academy/avalanche-fundamentals/05-interoperability/08-signature-aggregation

A BLS signature (Boneh–Lynn–Shacham signature) is a cryptographic signature scheme that allows multiple signatures to be combined into one aggregate signature. In addition to Avalanche ICM, it is used in Ethereum 2.0 (the Beacon Chain).

  1. Signature aggregation When multiple signers sign the same message, their signatures can be combined into a single signature. This reduces the amount of data transmitted over the network and makes more efficient use of block space.
  2. Lower verification costs An aggregate signature can be verified in a single verification operation, improving efficiency.
  3. Pairing-based cryptography BLS uses specialized cryptographic operations called pairings to verify signatures.

For example, consider three validators (Validator A, B, and C) signing the same message "Block123".

  1. Each validator signs with its private key. sigA = sign(privA, "Block123") sigB = sign(privB, "Block123") sigC = sign(privC, "Block123")
  2. Combine the individual signatures into a single aggregate signature. aggSig = aggregate(sigA, sigB, sigC)
  3. The verifier can check the aggregate signature in a single verification operation. verify([pubA, pubB, pubC], "Block123", aggSig) This verifies that A, B, and C signed the same message in one operation.

Avalanche ICM message flow

This section examines the ICM message flow in detail.

Components

First, let's identify the components involved.

Source Chain & Destination Chain

Source Chain Message Destination Chain
Source and destination chain diagram Source and destination chain diagram Source and destination chain diagram
L1 chain sending the request Message being sent L1 chain receiving the request

The L1 that sends a message is called the Source Chain, and the L1 that receives it is called the Destination Chain. Both L1 chains must already be registered on the P-Chain.

When an L1 is created using a service such as AvaCloud, registration on the P-Chain is typically handled during creation.

Source and destination chain diagram https://build.avax.network/academy/interchain-messaging/05-two-way-communication/01-two-way-communication

A user submits a request on the Source Chain containing the message to be sent to the Destination Chain.

Source and destination chain diagram

Both chains need contracts that send or receive messages across L1s (labeled Cross-Subnet dApp in the diagram), as well as a contract called Teleporter that handles message transmission and reception.

A Cross-Subnet dApp can include ERC20 contracts deployed across multiple L1s, contracts that exchange messages with other L1s, and off-chain applications that interact with those contracts. Teleporter formats data, including the message, for transmission to another L1 and supports retrying failed message deliveries.

For more information about Teleporter, see the following article.

Message

Let's look at how a message is formatted.

Simple data

Messages must be encoded rather than sent as raw strings.

Simple data encoding diagram https://build.avax.network/academy/interchain-messaging/04-icm-basics/02-recap-bytes-encoding-decoding

The example above encodes two values, test and 42, together.

Encoding means converting data into a particular format.

The diagram converts the message ("test", 42) into bytes. Representing the message as bytes makes it easier to process.

solidity
string memory someString = "test";
uint someNumber = 42;
 
bytes message = abi.encode(someString, someNumber);

In the example, the variable someString holds the string test. The variable someNumber holds the numeric value 42. The two values, someString and someNumber, are encoded using abi.encode.

On the destination L1, the encoded data must be decoded back into its original values. Decoding uses the data types and the encoded bytes, as shown below.

solidity
( 
  string memory someString,
  uint someNumber
) = abi.decode(message, (string, uint));

By passing the encoded data message and its original types, string and uint, to abi.decode, the destination contract recovers the original values someString and someNumber. someString and someNumber contain test and 42, respectively.

This is how a message can be sent from the Source Chain to the Destination Chain.

The contract performing the decoding on the Destination Chain must know the original data types in advance. This is because abi.decode cannot correctly decode message without the original data types.

Function invocation data

An application may also want to send function invocation data to the destination chain.

Function invocation data diagram https://build.avax.network/academy/interchain-messaging/06-invoking-functions/01-invoking-functions

There are two ways to pass this data:

  • Send function arguments as the message.
  • Send an identifier for the function to execute together with its arguments.

Function invocation data diagram https://build.avax.network/academy/interchain-messaging/06-invoking-functions/02-encoding-multiple-values

To send function arguments as the message, encode the values to be passed to the function, as described in the Simple data section.

text
string someString = "test";
uint someNumber = 43;
address someAddress = address(0);

bytes message = abi.encode(
  someString,
  someNumber,
  someAddress
);

Function invocation data diagram https://build.avax.network/academy/interchain-messaging/06-invoking-functions/06-encoding-function-name

The other approach is to send the function identifier together with the argument data.

text
enum CalculatorAction {
    add,
    concatenate
}

Define an enum containing the function identifiers as shown above.

bash
function encodeAddData(uint256 a, uint256 b) public pure returns (bytes memory) {
    bytes memory paramsData = abi.encode(a, b);
    return abi.encode(CalculatorAction.add, paramsData);
}

function encodeConcatenateData(string memory a, string memory b) public pure returns (bytes memory) {
    bytes memory paramsData = abi.encode(a, b);
    return abi.encode(CalculatorAction.concatenate, paramsData);
}

Then define functions such as those above in the contract, including the previously defined function identifier in the message. paramsData contains the arguments for the function. These bytes are then encoded together with the function identifier (CalculatorAction.add or CalculatorAction.concatenate). When decoding, first specify the types of the function identifier and its encoded argument data (bytes), as shown below.

text
(CalculatorAction actionType, bytes memory paramsData) = abi.decode(message, (CalculatorAction, bytes));

Define the same enum of function identifiers in the destination contract. Pass its type and the argument-data type (here, bytes, because the arguments were encoded twice) to abi.decode to obtain the function identifier (actionType) and the encoded arguments (paramsData).

text
if (actionType == CalculatorAction.add) {
        (uint256 a, uint256 b) = abi.decode(paramsData, (uint256, uint256));
        _calculatorAdd(a, b);
    } else if (actionType == ...) {
        (string memory text1, string memory text2) = abi.decode(paramsData, (string, string));
        _calculatorConcatenateStrings(text1, text2);
    } else {
        revert("CalculatorReceiverOnDispatch: invalid action");
    }

Dispatch execution to the appropriate function based on the received identifier. Finally, decode the argument data to obtain the values passed to the function.

Representing messages as bytes allows applications to send a wide range of data to destination L1 chains. The example uses two layers of encoding, but three, four, or more layers are possible for more complex data structures. Keep in mind that additional layers can increase processing overhead and make the data more difficult to manage.

Relayer

Relayer diagram https://build.avax.network/academy/interchain-messaging/08-avalanche-warp-messaging/04-awm-relayer

The Relayer is the component that actually relays messages between two L1s. It runs off-chain, monitoring connected L1 chains for message requests. When it detects a message, it collects BLS signatures from the relevant nodes and submits the message to the destination L1.

For more details, see the following article.

Warp Precompile

Avalanche precompiles are smart contracts built into an L1 when it is created. The Warp Precompile makes messages passed to it by the Teleporter contract available for relay. The Warp Precompile on the destination L1 also verifies the data submitted by the Relayer.

For more details about the Warp Precompile and precompiles in general, see the following article.

Message data

The message payload alone is not enough to send data to a destination chain. For example, it does not identify which L1 should receive it or which contract should be called. The Teleporter contract is designed to accept and process the information needed to send messages to other L1s. A Cross-Subnet dApp contract supplies the following information to the Teleporter contract.

contracts/teleporter/TeleporterMessenger.sol#L450-L460
                requiredGasLimit: uint256(0),
                allowedRelayerAddresses: allowedRelayerAddresses,
                message: new bytes(0)
            }),
            receiptsToSend
        );
    }

    /**
     * @dev Requirements:
     *
ava-labs/icm-contractsの元のファイルを開く
  • destinationBlockchainID The blockchain ID of the destination L1. This is not the conventional chain ID. It is the hash of the transaction that registered the L1 on the P-Chain when the chain was created.
  • destinationAddress The address of the contract deployed on the destination L1 that should receive the message.
  • feeInfo Information about the fee to be paid to the Relayer. It is defined as follows. https://github.com/ava-labs/icm-contracts/blob/main/contracts/teleporter/ITeleporterMessenger.sol#L44-L47
    • feeTokenAddress The contract address of the ERC20 token used to pay the fee, or the native token address (0x00...), as described in the original article.
    • amount The amount of tokens to pay as the fee.
  • requiredGasLimit The gas limit for execution. This can be configured so that execution does not consume more gas than the specified value.
  • allowedRelayerAddresses The list of Relayers authorized to relay the message. The list is empty by default, allowing any Relayer to process the message. Specify addresses when only particular Relayers should process it.
  • message The message to be sent to the destination L1.

The Relayer uses this information to submit the message to the destination L1. A Cross-Subnet dApp contract does not need to implement this processing itself; it supplies the required information to Teleporter, which handles the rest.

Message flow

With the components in place, let's trace how ICM processes a message.

ICM message flow diagram

1. Sending a message

A contract on the Source Chain that integrates with Teleporter initiates a message request.

The contract deployed on the Source Chain assembles the information needed for the request and calls Teleporter's sendCrossChainMessage function, as shown below.

icm-erc20/src/SimpleSender.sol#L38-L50
        teleporterMessenger.sendCrossChainMessage(
            TeleporterMessageInput({
                destinationBlockchainID: destinationChainID,
                destinationAddress: destinationAddress,
                feeInfo: TeleporterFeeInfo({
                    feeTokenAddress: address(0),
                    amount: 0
                }),
                requiredGasLimit: 200000,
                allowedRelayerAddresses: new address[](0),
                message: abi.encode(message)
            })
        );
cardene777/avalanche-sampleの元のファイルを開く

2. Teleporter message processing

When sendCrossChainMessage is called, Teleporter retrieves a list of receipts for messages previously sent from the destination L1 to this Teleporter contract on what is now the Source Chain. Returning those receipts to the destination L1 confirms successful processing and allows Relayers to collect their rewards. This step is needed because a Relayer receives its reward only after message delivery is complete.

contracts/teleporter/TeleporterMessenger.sol#L122-L132
        // Get the outstanding receipts for messages that have been previously received
        // from the destination chain but not yet acknowledged, and attach the receipts
        // to the Teleporter message to be sent.
        return _sendTeleporterMessage(
            messageInput,
            receiptQueues[messageInput.destinationBlockchainID].getOutstandingReceiptsToSend()
        );
    }

    /**
     * @dev Emits a {SendCrossChainMessage} event.
ava-labs/icm-contractsの元のファイルを開く

The sendCrossChainMessage function calls _sendTeleporterMessage to perform the underlying operations. The _sendTeleporterMessage function performs the following operations.

  • Obtain the messageID Associating each message with a unique ID makes it easier to manage operations such as retries.
contracts/teleporter/TeleporterMessenger.sol#L636-L637
            messageNonce: messageNonce_,
            originSenderAddress: msg.sender,
ava-labs/icm-contractsの元のファイルを開く
  • Construct the TeleporterMessage Build a TeleporterMessage, the data format used to send messages to the destination L1. The originSenderAddress field holds the address of the contract that called Teleporter.
contracts/teleporter/TeleporterMessenger.sol#L640-L650
            requiredGasLimit: messageInput.requiredGasLimit,
            allowedRelayerAddresses: messageInput.allowedRelayerAddresses,
            receipts: receipts,
            message: messageInput.message
        });
        bytes memory teleporterMessageBytes = abi.encode(teleporterMessage);

        // If the fee amount is non-zero, transfer the asset into control of this TeleporterMessenger contract instance.
        // The fee is allowed to be 0 because it's possible for someone to run their own relayer and deliver their own messages,
        // which does not require further incentivization. They still must pay the transaction fee to submit the message, so
        // this is not a DOS vector in terms of being able to submit zero-fee messages.
ava-labs/icm-contractsの元のファイルを開く
  • Collect the fee Based on the fee information supplied by the calling contract, transfer the specified ERC20 fee tokens to the Teleporter contract. The fee tokens held by Teleporter are transferred to the Relayer after delivery to the destination L1 has been confirmed.
contracts/teleporter/TeleporterMessenger.sol#L656-L667
                "TeleporterMessenger: zero fee asset contract address"
            );

            adjustedFeeAmount = SafeERC20TransferFrom.safeTransferFrom(
                IERC20(messageInput.feeInfo.feeTokenAddress), messageInput.feeInfo.amount
            );
        }

        // Store the fee asset and amount to be paid to the relayer of this message upon receiving the receipt.
        // Also store the message hash so that it can be retried until a receipt of its delivery is received back.
        TeleporterFeeInfo memory adjustedFeeInfo = TeleporterFeeInfo({
            feeTokenAddress: messageInput.feeInfo.feeTokenAddress,
ava-labs/icm-contractsの元のファイルを開く
  • Emit an event Emit an event announcing that a message is to be sent to another L1. Relayers monitor this event.
contracts/teleporter/TeleporterMessenger.sol#L680-L682
        WARP_MESSENGER.sendWarpMessage(teleporterMessageBytes);

        return messageID;
ava-labs/icm-contractsの元のファイルを開く
  • Call the Warp Precompile Call the Warp Precompile so that the following additional information is emitted separately, as described in the original article.
    • sourceChainID The blockchain ID of the source L1.
    • payload (teleporterMessageBytes) The bytes of the message to be sent.
    • originSenderAddress The address of the contract that submitted the request on the source L1.
    • messageIndex A unique ID.
    • BLS signature After detecting the Teleporter event, the Relayer retrieves the event emitted by the Warp Precompile containing the information listed above.
contracts/teleporter/TeleporterMessenger.sol#L685
    /**
ava-labs/icm-contractsの元のファイルを開く

3. Retrieving events

When Teleporter emits a SendCrossChainMessage event, the Relayer retrieves it. The Relayer monitors connected L1s for SendCrossChainMessage events and retrieves them as soon as they are emitted.

The detailed process is explained here.

As described earlier, after retrieving the event, the Relayer also retrieves the event emitted by the Warp Precompile that contains the required information. Because the Warp Precompile is called within the same transaction in which Teleporter emits its event, the Relayer retrieves events from that transaction. If a transaction contains multiple events from Teleporter and the Warp Precompile, the Relayer associates them by checking the event order and whether the messageID derived from the following information matches.

  • networkID The source network ID.
  • sourceChainID The blockchain ID of the source L1.
  • payload The actual payload containing the TeleporterMessage.

4. Collecting BLS signatures

Collecting BLS signatures https://build.avax.network/academy/interchain-messaging/08-avalanche-warp-messaging/06-message-pickup

The Relayer requests BLS signatures from validators on the Source Chain.

Collecting BLS signatures Collecting BLS signatures

Each validator has a weight corresponding to its stake. Depending on the L1's configuration, BLS signature verification fails unless the signatures represent at least the required weight.

Collecting BLS signatures https://build.avax.network/academy/avalanche-fundamentals/05-interoperability/08-signature-aggregation

Collecting individual signatures and aggregating them produces a signature of fixed length, even as the number of validators increases.

Collecting BLS signatures https://build.avax.network/academy/avalanche-fundamentals/05-interoperability/08-signature-aggregation

The public keys of the participating validators must also be aggregated for verification.

5. Submitting the message to the destination chain

Once the BLS signatures have been collected, the Relayer uses the retrieved event information to submit the message to the specified destination L1. It calls the Teleporter contract on that destination L1. The Relayer registers the Teleporter contracts on its connected L1s in advance. Since only one Teleporter contract can be registered per L1 in this configuration, the Relayer sends the message to that registered contract.

6. Verification

Message verification diagram https://build.avax.network/academy/interchain-messaging/08-avalanche-warp-messaging/07-message-delivery

When the Relayer calls the Teleporter contract on the destination L1, the receiveCrossChainMessage function is invoked.

contracts/teleporter/TeleporterMessenger.sol#L245-L326
    ) external receiverNonReentrant {
        // Verify and parse the cross chain message included in the transaction access list
        // using the warp message precompile.
        (WarpMessage memory warpMessage, bool success) =
            WARP_MESSENGER.getVerifiedWarpMessage(messageIndex);
        require(success, "TeleporterMessenger: invalid warp message");

        // Only allow for messages to be received from the same address as this teleporter contract.
        // The contract should be deployed using the universal deployer pattern, such that it knows messages
        // received from the same address on other chains were constructed using the same bytecode of this contract.
        // This allows for trusting the message format and uniqueness as specified by sendCrossChainMessage.
        require(
            warpMessage.originSenderAddress == address(this),
            "TeleporterMessenger: invalid origin sender address"
        );

        // Parse the payload of the message.
        TeleporterMessage memory teleporterMessage =
            abi.decode(warpMessage.payload, (TeleporterMessage));

        // If the blockchain ID has yet to be initialized, do so now.
        bytes32 blockchainID_ = initializeBlockchainID();

        // Require that the message was intended for this blockchain.
        require(
            teleporterMessage.destinationBlockchainID == blockchainID_,
            "TeleporterMessenger: invalid destination chain ID"
        );

        // Calculate the message ID of the message given the source blockchain ID and message nonce.
        bytes32 messageID = calculateMessageID(
            warpMessage.sourceChainID, blockchainID_, teleporterMessage.messageNonce
        );

        // Require that the message has not been received previously.
        require(!_messageReceived(messageID), "TeleporterMessenger: message already received");

        // Check that the caller is allowed to deliver this message.
        require(
            _checkIsAllowedRelayer(msg.sender, teleporterMessage.allowedRelayerAddresses),
            "TeleporterMessenger: unauthorized relayer"
        );

        // Mark the message as received.
        _markMessageReceived(messageID, teleporterMessage.messageNonce);

        // Store the relayer reward address if non-zero.
        if (relayerRewardAddress != address(0)) {
            _relayerRewardAddresses[messageID] = relayerRewardAddress;
        }

        // Process the receipts that were included in the teleporter message by paying the
        // fee for the messages are reward to the given relayers.
        uint256 length = teleporterMessage.receipts.length;
        for (uint256 i; i < length; ++i) {
            _markReceipt(blockchainID_, warpMessage.sourceChainID, teleporterMessage.receipts[i]);
        }

        // Store the receipt of this message delivery.
        receiptQueues[warpMessage.sourceChainID].enqueue(
            TeleporterMessageReceipt({
                receivedMessageNonce: teleporterMessage.messageNonce,
                relayerRewardAddress: relayerRewardAddress
            })
        );

        emit ReceiveCrossChainMessage(
            messageID,
            warpMessage.sourceChainID,
            msg.sender,
            relayerRewardAddress,
            teleporterMessage
        );

        // Execute the message.
        if (teleporterMessage.message.length > 0) {
            _handleInitialMessageExecution(messageID, warpMessage.sourceChainID, teleporterMessage);
        }
    }

    /**
     * @dev A Teleporter message has an associated `requiredGasLimit` that is used to execute the message.
ava-labs/icm-contractsの元のファイルを開く

At the beginning of receiveCrossChainMessage, the Warp Precompile is called. The Warp Precompile's VerifyPredicate function below verifies the BLS signature and checks whether the signing validators meet the weight threshold configured by the destination L1.

precompile/contracts/warp/config.go#L189-L240
func (c *Config) VerifyPredicate(predicateContext *precompileconfig.PredicateContext, pred predicate.Predicate) error {
	unpackedPredicateBytes, err := pred.Bytes()
	if err != nil {
		return fmt.Errorf("%w: %w", errInvalidPredicateBytes, err)
	}

	// Note: PredicateGas should be called before VerifyPredicate, so we should never reach an error case here.
	warpMsg, err := warp.ParseMessage(unpackedPredicateBytes)
	if err != nil {
		return fmt.Errorf("%w: %w", errCannotParseWarpMsg, err)
	}

	quorumNumerator := WarpDefaultQuorumNumerator
	if c.QuorumNumerator != 0 {
		quorumNumerator = c.QuorumNumerator
	}

	log.Debug("verifying warp message", "warpMsg", warpMsg, "quorumNum", quorumNumerator, "quorumDenom", WarpQuorumDenominator)

	// Wrap validators.State on the chain snow context to special case the Primary Network
	state := warpValidators.NewState(
		predicateContext.SnowCtx.ValidatorState,
		predicateContext.SnowCtx.SubnetID,
		warpMsg.SourceChainID,
		c.RequirePrimaryNetworkSigners,
	)

	validatorSet, err := warp.GetCanonicalValidatorSetFromChainID(
		context.Background(),
		state,
		predicateContext.ProposerVMBlockCtx.PChainHeight,
		warpMsg.UnsignedMessage.SourceChainID,
	)
	if err != nil {
		log.Debug("failed to retrieve canonical validator set", "msgID", warpMsg.ID(), "err", err)
		return fmt.Errorf("%w: %w", errCannotRetrieveValidatorSet, err)
	}

	err = warpMsg.Signature.Verify(
		&warpMsg.UnsignedMessage,
		predicateContext.SnowCtx.NetworkID,
		validatorSet,
		quorumNumerator,
		WarpQuorumDenominator,
	)
	if err != nil {
		log.Debug("failed to verify warp signature", "msgID", warpMsg.ID(), "err", err)
		return fmt.Errorf("%w: %w", errFailedVerification, err)
	}

	return nil
}
ava-labs/subnet-evmの元のファイルを開く

BLS signature verification uses the aggregate signature and aggregate public key of the validators. The system also checks that the signatures represent at least the weight configured in advance on the destination L1. For example, if the threshold is 50% or more, processing fails when the signing validators represent less than 50% of the total weight.

Weight refers to a value determined by the amount of tokens a validator has staked on that L1. A larger stake corresponds to a higher weight.

The receiveCrossChainMessage function also performs the following checks.

  • Verify the originating Teleporter contract Check that the originating Teleporter contract address matches the address of the Teleporter contract being called. This check is based on the convention that Teleporter is deployed at the same contract address on each L1 using CREATE2.

For more information about CREATE2, see the following article.

  • Verify the destination chain Check that the message is addressed to the L1 on which the called Teleporter contract resides.

  • Verify the messageID Check whether the messageID has already been processed. The messageID is unique, so the same message cannot be executed twice through this path.

  • Verify allowedRelayerAddresses If the message specifies Relayers through allowedRelayerAddresses, check that it was submitted by an authorized Relayer.

If all checks pass, the message is delivered to the specified contract.

7. Receiving the message

The specified contract on the destination L1 is called. The function invoked is receiveTeleporterMessage, which the receiving contract must implement.

icm-erc20/src/SimpleReceiver.sol#L46-L63
    function receiveTeleporterMessage(
        bytes32 originChainID,
        address originSenderAddress,
        bytes calldata message
    ) external onlyTeleporter {
        string memory decodedMessage = abi.decode(message, (string));

        lastMessage = decodedMessage;
        lastSender = originSenderAddress;
        lastOriginChainID = originChainID;

        emit MessageReceived(
            originChainID,
            originSenderAddress,
            decodedMessage
        );
    }
}
cardene777/avalanche-sampleの元のファイルを開く

The receiveTeleporterMessage function accepts the following three arguments.

  • originChainID The blockchain ID of the source L1.
  • originSenderAddress The address of the contract that requested message delivery on the source L1.
  • message The message that was sent.

Additional considerations

Fee flow

Fee flow diagram https://build.avax.network/academy/interchain-messaging/11-incentivizing-a-relayer/02-fee-data-flow

A fee can be specified when sending a message from the Source Chain. Some Relayers may decline to process messages unless a minimum fee is offered, making a fee necessary in those cases. The fee is paid to the Relayer after delivery to the destination L1 has been confirmed. As shown in the diagram, when a message is requested, the specified ERC20 tokens are first deposited on the Source Chain. The message is then delivered to the destination L1. Once the delivery information is returned to the Teleporter contract as a receipt, the fee can finally be paid to the Relayer.

Note that the receipt is sent back to the Source Chain's Teleporter contract only when the Destination Chain's Teleporter contract is called for the return message. Until that occurs, the fee remains unpaid.

ICM Registry

By default, the Teleporter contract is not upgradeable. However, changes to Teleporter's specification or the discovery of a vulnerability may make it desirable to upgrade to a new Teleporter contract. The ICM Registry supports this process.

ICM Registry diagram https://build.avax.network/academy/interchain-messaging/07-icm-registry/02-how-the-icm-registry-works

The diagram shows a contract called the Teleporter Registry. Calling its getLatestTeleporter function returns the address of the latest Teleporter contract.

contracts/teleporter/registry/TeleporterRegistry.sol#L133-L135

    /**
     * @dev Gets the {ITeleporterMessenger} contract of the given `version`.
ava-labs/icm-contractsの元のファイルを開く

Each dApp contract can call getLatestTeleporter to access the latest version of the Teleporter contract. When a new version of Teleporter is deployed, registering its address with the Teleporter Registry makes it available as the latest version.

For more information about the Teleporter Registry, see the following article.

Conclusion

This article covered the components and message flow of Avalanche ICM.

I also write articles on other topics. You can find them at the following links.

https://chaldene.net/