Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,81 @@ forge coverage --no-match-coverage "(script|test|wormhole/external/wormhole|worm
forge script deploy --sig "run(string[])" "[<chains>]" --account <account> --slow --multi --isolate --always-use-create-2-factory --verify --broadcast [-vvvv]
```

### Axelar deployment

`script/AxelarOracle.s.sol:DeployAxelarOracle` deploys with CREATE2 (`salt = 0`), matching the
other oracle deployment scripts. Pass the mapping owner, local gateway, and local gas service
explicitly. The deployer can differ from the owner. Deployment does **not** configure any chain maps
and is not restricted to Base or Arbitrum.

Use verified provider addresses for the target network from
[Axelar's mainnet contract reference](https://docs.axelar.dev/dev/reference/mainnet-contract-addresses/).
On Base (8453) and Arbitrum (42161), both providers currently use the addresses in this example:

```shell
OWNER=0x712E90032d8f44bE276A903E1769d64dD1C7F45a
GATEWAY=0xe432150cce91c13a887f7D836923d5597adD8E31
GAS_SERVICE=0x2d5d7d31F671F86C782533cc367F14109a082712
RPC=https://arb1.arbitrum.io/rpc

# Verify the target network and provider code before signing.
cast chain-id --rpc-url "$RPC"
cast code "$GATEWAY" --rpc-url "$RPC"
cast code "$GAS_SERVICE" --rpc-url "$RPC"

# Dry run; no transactions are sent.
forge script script/AxelarOracle.s.sol:DeployAxelarOracle \
--sig 'deploy(address,address,address)' "$OWNER" "$GATEWAY" "$GAS_SERVICE" \
--rpc-url "$RPC" --account deployer

# Deployment only; the deployer signs, not necessarily OWNER.
forge script script/AxelarOracle.s.sol:DeployAxelarOracle \
--sig 'deploy(address,address,address)' "$OWNER" "$GATEWAY" "$GAS_SERVICE" \
--rpc-url "$RPC" --account deployer --broadcast
```

Set `ORACLE` to the returned deployed address. Verify `owner()(address)`, `gateway()(address)`,
and `gasService()(address)` with `cast call`. CREATE2 prediction depends on the factory, salt,
bytecode, and all constructor arguments, not the sender's nonce. Fund the deployer above Forge's
estimated transaction cost, with headroom for fee changes; a dry run does not prove sufficient funds.

#### Separate chain-map configuration

`script/AxelarChainMap.s.sol:ConfigureAxelarChainMap` configures one route per invocation.
The signing account must control the oracle's owner. Axelar names must be lowercase; names and
canonical OIF chain IDs are set-once. Repeated configuration reverts rather than overwriting a route.

```shell
# Example: configure the Base route on an Arbitrum oracle. Dry-run first.
forge script script/AxelarChainMap.s.sol:ConfigureAxelarChainMap \
--sig 'setChainMap(address,string,uint256)' "$ORACLE" base 8453 \
--rpc-url "$RPC" --account owner

# Only after checking the route and signing account:
forge script script/AxelarChainMap.s.sol:ConfigureAxelarChainMap \
--sig 'setChainMap(address,string,uint256)' "$ORACLE" base 8453 \
--rpc-url "$RPC" --account owner --broadcast

cast call "$ORACLE" 'reverseChainIdMap(uint256)(bytes32)' 8453 --rpc-url "$RPC"
# Expected: $(cast --format-bytes32-string base), the lowercase name packed left-aligned.
```

The sibling [`intents-oracle-owner`](../../intents-oracle-owner/README.md) repository keeps its
ceremony owner keys in GitHub Actions, separately from deployment. Use the target chain's
`expectedOwner` from its reviewed configuration when that owner is intended; the example above uses
its current Base/Arbitrum owner. Axelar uses the numeric `setChainMap(uint256,uint256)` that its
reconciler already supports. The key is `uint256(bytes32(bytes(lowercaseName)))`; the oracle
rejects keys that are not packed lowercase names. The local configuration script is for owners
with an available signer; it does not access GitHub-held keys.

Route checks confirm configuration, not live GMP delivery. `submit` takes the destination's OIF
chain ID and the destination oracle's Axelar address string (EVM `0x…`, Stellar `C…` StrKey, Solana
base58), passed through unchecked. Use a nonzero `destinationConfig` only for Solana destinations;
it selects the Borsh envelope. Clients split batches to meet the destination's limits: Stellar
allows 1–4 payloads of ≤684 bytes, and Solana allows one payload of ≤320 bytes. Relayed delivery
requires a positive, off-chain-estimated native gas payment. Self-relay uses zero value and still
requires gateway approval before `execute`.

## License Notice

This project is licensed under the **[GNU Lesser General Public License v3.0 only (LGPL-3.0-only)](/LICENSE)**.
Expand Down
24 changes: 24 additions & 0 deletions script/AxelarChainMap.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

import { Script } from "forge-std/Script.sol";

import { AxelarOracle } from "../src/integrations/oracles/axelar/AxelarOracle.sol";

/// @notice Configures one permanent Axelar route; broadcast with the oracle's owner.
/// Names must be lowercase Axelar chain names; the oracle rejects anything else.
///
/// Usage (omit --broadcast for a dry run):
/// forge script script/AxelarChainMap.s.sol:ConfigureAxelarChainMap \
/// --sig 'setChainMap(address,string,uint256)' <ORACLE> <NAME> <CHAIN_ID> \
/// --rpc-url <RPC> --account owner --broadcast
contract ConfigureAxelarChainMap is Script {
function setChainMap(
address oracle,
string calldata name,
uint256 chainId
) external {
vm.broadcast();
AxelarOracle(oracle).setChainMap(uint256(bytes32(bytes(name))), chainId);
}
}
25 changes: 25 additions & 0 deletions script/AxelarOracle.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

import { Script } from "forge-std/Script.sol";

import { AxelarOracle } from "../src/integrations/oracles/axelar/AxelarOracle.sol";

/// @notice Deploys an AxelarOracle without configuring chain maps.
/// Uses CREATE2 with salt zero, matching the other oracle deployment scripts.
/// The owner need not be the broadcasting account.
///
/// Usage (omit --broadcast for a dry run):
/// forge script script/AxelarOracle.s.sol:DeployAxelarOracle \
/// --sig 'deploy(address,address,address)' <OWNER> <GATEWAY> <GAS_SERVICE> \
/// --rpc-url <RPC> --account deployer --broadcast
contract DeployAxelarOracle is Script {
function deploy(
address owner,
address gateway,
address gasService
) external returns (AxelarOracle oracle) {
vm.broadcast();
oracle = new AxelarOracle{ salt: bytes32(0) }(owner, gateway, gasService);
}
}
27 changes: 6 additions & 21 deletions snapshots/inputSettler.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
{
"BasePurchaseOrder": "138441",
"CompactFinaliseFor": "167221",
"CompactFinaliseSelf": "158347",
"CompactFinaliseTo": "158347",
"EscrowFinalise": "81268",
"CompactFinaliseFor": "162638",
"CompactFinaliseSelf": "153798",
"CompactFinaliseTo": "153798",
"IntegrationCoinFill": "89862",
"IntegrationCompactFinaliseSelf": "150381",
"IntegrationWormholeReceiveMessage": "73557",
"IntegrationCompactFinaliseSelf": "152843",
"IntegrationWormholeReceiveMessage": "73558",
"IntegrationWormholeSubmit": "42492",
"broadcast": "43912",
"compactFinaliseSelfWithFee": "189114",
"depositAndRegisterFor": "163659",
"escrowFinaliseSelfWithFee": "106622",
"escrowFinaliseWithSignature": "89900",
"escrowOpen": "83106",
"escrowOpenFor3009Single": "115693",
"escrowOpenFor3009SingleArray": "122525",
"escrowOpenFor3009Two": "178133",
"escrowOpenForMsgSender": "83913",
"escrowOpenForPermit2": "125605",
"escrowRefundOnNonFill": "54410",
"maxTimestamp1": "461",
"minTimestamp1": "483",
"tronEscrowFinaliseSelfWithFee": "111065",
"validate2Fills": "9617",
"validate2FillsMultipleSolvers": "9617"
"minTimestamp1": "483"
}
14 changes: 1 addition & 13 deletions snapshots/oracle.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
{
"bitcoinFinaliseDispute": "63284",
"bitcoinOPVerify": "87733",
"bitcoinOutputClaim": "99799",
"bitcoinOutputDispute": "71733",
"bitcoinVerify": "135429",
"bitcoinVerifyWithEmbed": "138039",
"citreaFinaliseDispute": "63284",
"citreaOPVerify": "87733",
"citreaOutputClaim": "99799",
"citreaOutputDispute": "71733",
"citreaVerify": "130685",
"citreaVerifyWithEmbed": "133295",
"hyperlaneOracleHandle": "50281",
"hyperlaneOracleHandle": "50296",
"hyperlaneOracleSubmit": "67472",
"hyperlaneOracleSubmitCustomHook": "67848",
"wormholeOracleSubmit": "42648"
Expand Down
5 changes: 0 additions & 5 deletions snapshots/outputSettler.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
"emitNotFilled": "32683",
"outputSettlerCoinFill": "83316",
"outputSettlerCoinFillDutchAuction": "84576",
"outputSettlerCoinFillExclusive": "84709",
"outputSettlerCoinFillExclusiveDutchAuction": "85453",
"outputSettlerCoinFillNative": "89389",
"outputSettlerCoinFillOrderOutputsNative": "128930",
"outputSettlerCoinfillOrderOutputs": "119862"
}
54 changes: 54 additions & 0 deletions src/integrations/oracles/axelar/AxelarChainName.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

import { LibString } from "solady/utils/LibString.sol";

/// @title AxelarChainName
/// @notice Axelar chain name ↔ packed `uint256` chain-map key.
/// @dev The key is the ASCII-lowercased name packed left-aligned and zero-padded: `uint256(bytes32(bytes(name)))`.
/// Names are 1–32 bytes without NUL; no character set is imposed. Axelar compares names ASCII-case-insensitively,
/// so lowercasing gives each chain exactly one key.
library AxelarChainName {
/// @notice The name is empty, longer than 32 bytes, or contains a NUL byte.
error InvalidChainName();

/// @notice ASCII-lowercases `chainName` and packs it left-aligned, word-at-a-time.
/// @dev Only 0x41–0x5a change (by setting bit 0x20); bytes ≥ 0x80 are left as is.
/// @param chainName Axelar chain name, in any ASCII case.
/// @return packed Packed lowercase name.
function key(
string memory chainName
) internal pure returns (uint256 packed) {
uint256 n = bytes(chainName).length;
if (n == 0 || n > 32) revert InvalidChainName();
bool nul;
assembly ("memory-safe") {
let ones := 0x0101010101010101010101010101010101010101010101010101010101010101
let highs := shl(7, ones)
// Mask of the bytes past the name. n = 32 shifts by 256, which yields 0 (no tail).
let tail := shr(shl(3, n), not(0))
let w := and(mload(add(chainName, 0x20)), not(tail))
// NUL test on a copy `v` whose tail bytes are 0x01, so the zero padding does not count; `w` and the key
// keep a zero tail. The has-zero-byte test is exact for a yes/no answer.
let v := or(w, and(tail, ones))
nul := iszero(iszero(and(and(sub(v, ones), not(v)), highs)))
// With high bits cleared each byte is ≤ 0x7f, so adding ≤ 0x3f per byte never carries across bytes.
// Bit 7 of (b + 0x3f) is set iff b ≥ 0x41; of (b + 0x25) iff b ≥ 0x5b.
let low := and(w, not(highs))
let ge41 := and(add(low, mul(0x3f, ones)), highs)
let ge5b := and(add(low, mul(0x25, ones)), highs)
// Uppercase ASCII: ≥ 0x41, < 0x5b, and the original high bit clear; move bit 7 to bit 5.
packed := or(w, shr(2, and(and(ge41, not(ge5b)), not(w))))
}
if (nul) revert InvalidChainName();
}

/// @notice Unpacks a key into its name: the bytes up to the first zero byte.
/// @param packed Packed name.
/// @return Chain name.
function name(
uint256 packed
) internal pure returns (string memory) {
return LibString.fromSmallString(bytes32(packed));
}
}
140 changes: 140 additions & 0 deletions src/integrations/oracles/axelar/AxelarOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

import { IAttester } from "../../../interfaces/IAttester.sol";
import { LibAddress } from "../../../libs/LibAddress.sol";
import { MessageEncodingLib } from "../../../libs/MessageEncodingLib.sol";
import { BaseInputOracle } from "../../../oracles/BaseInputOracle.sol";
import { ChainMap } from "../../../oracles/ChainMap.sol";
import { AxelarChainName } from "./AxelarChainName.sol";
import { OracleAddress } from "./OracleAddress.sol";
import { SolanaEnvelope } from "./SolanaEnvelope.sol";

interface IAxelarMessageGateway {
function callContract(
string calldata chain,
string calldata destination,
bytes calldata payload
) external;
function validateContractCall(
bytes32 commandId,
string calldata chain,
string calldata sender,
bytes32 hash
) external returns (bool);
}

interface IAxelarNativeGasService {
function payNativeGasForContractCall(
address sender,
string calldata chain,
string calldata destination,
bytes calldata payload,
address refund
) external payable;
}

/// @title AxelarOracle
/// @notice Transparent Axelar GMP oracle with owner-set, immutable chain maps.
/// @dev The owner maps an Axelar chain to an OIF chain through `ChainMap.setChainMap(key, chainId)`, where `key` is
/// the ASCII-lowercased Axelar name packed left-aligned and zero-padded: `uint256(bytes32(bytes(name)))`. Names are
/// 1–32 bytes without NUL; no other character set is imposed, so `reverseChainIdMap(chainId)` returns the packed
/// name, which `submit` unpacks into the outbound chain name. Axelar currently caps names at 20 bytes.
/// Inbound sender formats (EVM hex, Stellar StrKey, Solana base58) are inferred from the
/// sender string. No Stellar message limits are enforced here; Stellar and Solana destinations enforce their own,
/// so clients split batches to fit.
contract AxelarOracle is BaseInputOracle, ChainMap {
using LibAddress for address;

enum DeliveryMode {
Relayed,
SelfRelay
}

IAxelarMessageGateway public immutable gateway;
IAxelarNativeGasService public immutable gasService;

error InvalidConfiguration();
error NotAllPayloadsValid();
error NotApproved();
error InvalidFee();

constructor(
address owner_,
address gateway_,
address gasService_
) ChainMap(owner_) {
if (gateway_.code.length == 0 || gasService_.code.length == 0) revert InvalidConfiguration();
gateway = IAxelarMessageGateway(gateway_);
gasService = IAxelarNativeGasService(gasService_);
}

/// @notice Sets an immutable map from a packed lowercase Axelar name to an OIF chain ID.
/// @dev `protocolChainIdentifier` must be `uint256(bytes32(bytes(name)))` for a 1–32-byte name with no NUL and no
/// ASCII uppercase; anything else (zero, right-aligned, bytes after a NUL, uppercase) reverts
/// `AxelarChainName.InvalidChainName`.
function setChainMap(
uint256 protocolChainIdentifier,
uint256 chainId
) public override onlyOwner {
if (AxelarChainName.key(AxelarChainName.name(protocolChainIdentifier)) != protocolChainIdentifier) {
revert AxelarChainName.InvalidChainName();
}
super.setChainMap(protocolChainIdentifier, chainId);
}

/// @notice Sends attested payloads to the Axelar chain mapped to `destinationChainId`.
/// @dev `recipientOracle` is passed to Axelar unchecked. A wrong recipient or config loses only that delivery:
/// export does not consume anything, so anyone can submit again.
/// @param destinationChainId OIF chain ID of the destination; must be mapped.
/// @param recipientOracle Destination oracle as an Axelar address string (`0x…`, `C…` StrKey, or base58).
/// @param source Attester whose payloads are sent.
/// @param payloads Payloads `source` has attested.
/// @param destinationConfig Nonzero selects the Solana Borsh envelope with this config; zero sends the raw message.
/// @param deliveryMode `Relayed` pays `msg.value` to the gas service; `SelfRelay` requires no value.
function submit(
uint256 destinationChainId,
string calldata recipientOracle,
address source,
bytes[] calldata payloads,
bytes32 destinationConfig,
DeliveryMode deliveryMode
) external payable {
uint256 key = reverseChainIdMap[destinationChainId];
if (key == 0) revert ZeroValue();
string memory chain = AxelarChainName.name(key);
if (!IAttester(source).hasAttested(payloads)) revert NotAllPayloadsValid();
bytes memory message = MessageEncodingLib.encodeMessage(source.toIdentifier(), payloads);
if (destinationConfig != 0) message = SolanaEnvelope.encode(message, destinationConfig);
if (deliveryMode == DeliveryMode.Relayed) {
if (msg.value == 0) revert InvalidFee();
gasService.payNativeGasForContractCall{ value: msg.value }(
address(this), chain, recipientOracle, message, msg.sender
);
} else if (msg.value != 0) {
revert InvalidFee();
}
gateway.callContract(chain, recipientOracle, message);
}

/// @notice Records the payload hashes of a gateway-approved message.
/// @dev Anyone may execute, but only the gateway can approve the exact destination-bound message. The original
/// `sourceChain` and `sourceAddress` strings are validated, since Axelar binds the approved spelling.
function execute(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
bytes calldata payload
) external {
uint256 chainId = _getMappedChainId(AxelarChainName.key(sourceChain));
bytes32 sender = OracleAddress.decode(sourceAddress);
if (!gateway.validateContractCall(commandId, sourceChain, sourceAddress, keccak256(payload))) {
revert NotApproved();
}
(bytes32 application, bytes32[] memory hashes) = MessageEncodingLib.getHashesOfEncodedPayloads(payload);
for (uint256 i; i < hashes.length; ++i) {
_attestations[chainId][sender][application][hashes[i]] = true;
emit OutputProven(chainId, sender, application, hashes[i]);
}
}
}
Loading
Loading