Skip to content

Commit

Permalink
lp-gateway: Ensure contract address is encoded properly
Browse files Browse the repository at this point in the history
  • Loading branch information
cdamian committed Sep 10, 2023
1 parent cd78243 commit 31aa21e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -250,11 +251,12 @@ where
source_address: String<MAX_SOURCE_ADDRESS_BYTES>,
payload: Bytes<MAX_PAYLOAD_BYTES>,
) -> EvmResult {
if handle.context().caller != GatewayContract::<T>::get() {
return Err(PrecompileFailure::Error {
exit_status: ExitError::Other("axelar gateway contract address mismatch".into()),
});
}
ensure!(
handle.context().caller == GatewayContract::<T>::get(),
PrecompileFailure::Error {
exit_status: ExitError::Other("gateway contract address mismatch".into()),
}
);

let msg = BoundedVec::<
u8,
Expand Down
1 change: 1 addition & 0 deletions pallets/liquidity-pools-gateway/routers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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")?;
Expand Down

0 comments on commit 31aa21e

Please sign in to comment.