Cosmos General Message Passing
Axelar has expanded General Message Passing (GMP) to support Cosmos blockchains. With Axelar, you can now send and receive messages on EVM chains and Cosmos chains. Messages sent to Cosmos chains can be received by CosmWasm smart contracts (on blockchains with CosmWasm support), or those messages can be received natively at the consensus layer as part Go code.
Cosmos GMP works by sending and receiving through IBC’s memo field. Cosmos chains looking to support GMP should integrate the appropriate middleware and verify message source.
To see full examples of sending and receiving messages in all cases, check out our full Cosmos GMP Example Project.
Messages from EVM to CosmWasm
To send a message from an EVM chain to a Cosmos CosmWasm contract, the payload must be encoded before calling the standard payNativeGasForContractCall
and callContract
methods (or token-including equivalents). You must also specify the destination method you are calling.
The payload must specify:
string
- The method name of the CosmWasm contract to callstring[]
- The names of all argumentsstring[]
- the types of all argumentsbytes
- the values of all arguments
Multi-send Example encoding
This example encodes a string array of recipients, as you can see in our example of sending tokens and recipients.
Messages from EVM to Native Cosmos
When sending a message to a Cosmos chain with native (consensus layer) support for GMP, you must encode a version number with the intended payload. This allows the consensus layer to know what to do with the payload.
Messages from Native Cosmos
To send a message from Native Cosmos Go code, you must send a message to the Axelar GMP Account (axelar1dv4u5k73pzqrxlzujxg3qp8kvc3pje7jtdvu72npnt5zhq05ejcsn5qme5
) via IBC.
When sending messages from Cosmos, you should perform standard GMP ABI encoding via the github.com/ethereum/go-ethereum/accounts/abi
package.
Messages from CosmWasm
To send a message from CosmWasm Rust code, you must send a message to the Axelar Gateway (axelar1dv4u5k73pzqrxlzujxg3qp8kvc3pje7jtdvu72npnt5zhq05ejcsn5qme5s
) via IBC.
You should encode your payload using ethabi.
Chain Support
For a Cosmos blockchain to support receiving GMP messages (naively or via CosmWasm), it should implement the appropriate middleware in Go as part of the consensus layer.
If you have CosmWasm on your Cosmos chain and want to be able to receieve and deliver messages, install Osmosis IBC-hooks.
If you don’t support CosmWasm on your Cosmos chain, you’ll need to implement and install your own Axelar GMP module to receive and execute messages. See our sample reference implementation.
Establishing a Path of Trust
Because IBC messages are permissionless, you’ll want to ensure you verify the source of all messages.
When you receive a packet on Cosmos chain, you’ll need to verify:
-
That the packet came from Axelar (verify IBC channel; Axelar GMP sender account).
Specify the Axelar IBC channel by allowlisting the channel hash.
-
For example, in your CosmWasm code, you can combine the IBC hook, the channel ID, and the Axelar GMP account to verify the channel matches the expected channel.
-
For Consensus
Verify (channel & sender == address of our GMP account =
axelar1dv4u5k73pzqrxlzujxg3qp8kvc3pje7jtdvu72npnt5zhq05ejcsn5qme5
. https://github.com/axelarnetwork/evm-cosmos-gmp-sample/blob/main/native-integration/sample-middleware/gmp_middleware.go#L114
-
-
The EVM source chain and address.
When a message has an EVM source, the chain and address are passed in differently for CosmWasm and Native GMP.
- CosmWasm: When you build your CosmWasm contract, you can define
source_chain
and/orsource_address
as arguments for theirwasm
method. And pass in the correctsource_chain
and/orsource_address
as an argument from the EVM contract. The Axelar network will validate that these values are accurate and not being spoofed by the sender. - Native GMP: The GMP call will be sent by the Axelar GMP account to the cosmos chain. Make sure that it is formatted correctly in the IBC memo that contains validated source chain/address values.
- CosmWasm: When you build your CosmWasm contract, you can define