diff --git a/Cargo.lock b/Cargo.lock index 83c27dffbd..88000ee4de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5805,6 +5805,7 @@ dependencies = [ "ethabi 16.0.0", "frame-support", "frame-system", + "hex", "lazy_static", "orml-traits", "pallet-balances", diff --git a/pallets/liquidity-pools-gateway/axelar-gateway-precompile/src/lib.rs b/pallets/liquidity-pools-gateway/axelar-gateway-precompile/src/lib.rs index 4622199339..1468d434b3 100644 --- a/pallets/liquidity-pools-gateway/axelar-gateway-precompile/src/lib.rs +++ b/pallets/liquidity-pools-gateway/axelar-gateway-precompile/src/lib.rs @@ -13,6 +13,7 @@ use cfg_types::domain_address::{Domain, DomainAddress}; use fp_evm::PrecompileHandle; +use frame_support::ensure; use pallet_evm::{ExitError, PrecompileFailure}; use precompile_utils::prelude::*; use sp_core::{bounded::BoundedVec, ConstU32, H256, U256}; @@ -250,11 +251,12 @@ where source_address: String, payload: Bytes, ) -> EvmResult { - if handle.context().caller != GatewayContract::::get() { - return Err(PrecompileFailure::Error { - exit_status: ExitError::Other("axelar gateway contract address mismatch".into()), - }); - } + ensure!( + handle.context().caller == GatewayContract::::get(), + PrecompileFailure::Error { + exit_status: ExitError::Other("gateway contract address mismatch".into()), + } + ); let msg = BoundedVec::< u8, diff --git a/pallets/liquidity-pools-gateway/routers/Cargo.toml b/pallets/liquidity-pools-gateway/routers/Cargo.toml index d0ba8b5395..fae92ee6ea 100644 --- a/pallets/liquidity-pools-gateway/routers/Cargo.toml +++ b/pallets/liquidity-pools-gateway/routers/Cargo.toml @@ -11,6 +11,7 @@ version = "0.0.1" targets = ["x86_64-unknown-linux-gnu"] [dependencies] +hex = { version = "0.4.3", default-features = false } codec = { package = "parity-scale-codec", version = "3.0.0", features = ["derive"], default-features = false } frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } diff --git a/pallets/liquidity-pools-gateway/routers/src/routers/axelar_evm.rs b/pallets/liquidity-pools-gateway/routers/src/routers/axelar_evm.rs index 137160536f..a5912166fd 100644 --- a/pallets/liquidity-pools-gateway/routers/src/routers/axelar_evm.rs +++ b/pallets/liquidity-pools-gateway/routers/src/routers/axelar_evm.rs @@ -15,7 +15,10 @@ use ethabi::{Contract, Function, Param, ParamType, Token}; use frame_support::dispatch::{DispatchError, DispatchResult}; use frame_system::pallet_prelude::OriginFor; use scale_info::{ - prelude::string::{String, ToString}, + prelude::{ + format, + string::{String, ToString}, + }, TypeInfo, }; use sp_core::{bounded::BoundedVec, ConstU32, H160}; @@ -155,7 +158,11 @@ pub(crate) fn get_axelar_encoded_msg( .map_err(|_| "cannot retrieve Axelar contract function")? .encode_input(&[ Token::String(target_chain_string), - Token::String(target_contract.to_string()), + // Ensure that the target contract is correctly converted to hex. + // + // The `to_string` method on the H160 is returning a string containing an ellipsis, such + // as: 0x1234…7890 + Token::String(format!("0x{}", hex::encode(target_contract.0))), Token::Bytes(encoded_liquidity_pools_contract), ]) .map_err(|_| "cannot encode input for Axelar contract function")?;