Skip to content

Commit

Permalink
fix: add check for internal call in ack and timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
SlayerAnsh committed Dec 11, 2024
1 parent 8a3002f commit 72aee5c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion contracts/hub/router/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub fn execute(
ibc_receive_internal_call(&mut deps, env, info, receive_msg)
}
ExecuteMsg::IbcCallbackAckAndTimeout { ack } => {
ibc_ack_packet_internal_call(deps, env, ack)
ibc_ack_packet_internal_call(deps, info, env, ack)
}
ExecuteMsg::UpdateLock {} => execute_update_lock(deps, info),
ExecuteMsg::NativeReceiveCallback { msg, chain_uid } => {
Expand Down
9 changes: 7 additions & 2 deletions contracts/hub/router/src/ibc/ack_and_timeout.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
from_json, Binary, CosmosMsg, DepsMut, Env, IbcBasicResponse, IbcPacketAckMsg,
IbcPacketTimeoutMsg, Response, StdError, StdResult, SubMsg, Uint128, WasmMsg,
ensure, from_json, Binary, CosmosMsg, DepsMut, Env, IbcBasicResponse, IbcPacketAckMsg,
IbcPacketTimeoutMsg, MessageInfo, Response, StdError, StdResult, SubMsg, Uint128, WasmMsg,
};
use cosmwasm_std::{to_json_binary, IbcAcknowledgement};
use euclid::chain::{Chain, ChainType, ChainUid, CrossChainUser};
Expand Down Expand Up @@ -48,9 +48,14 @@ pub fn ibc_packet_ack(

pub fn ibc_ack_packet_internal_call(
deps: DepsMut,
info: MessageInfo,
env: Env,
ack: IbcPacketAckMsg,
) -> Result<Response, ContractError> {
ensure!(
info.sender == env.contract.address,
ContractError::Unauthorized {}
);
// Parse the ack based on request
let msg: HubIbcExecuteMsg = from_json(ack.original_packet.data)?;

Expand Down
2 changes: 1 addition & 1 deletion contracts/liquidity/factory/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ pub fn execute(
),
ExecuteMsg::Receive(msg) => receive_cw20(deps, env, info, msg),
ExecuteMsg::IbcCallbackAckAndTimeout { ack } => {
ibc::ack_and_timeout::ibc_ack_packet_internal_call(deps, env, ack)
ibc::ack_and_timeout::ibc_ack_packet_internal_call(deps, info, env, ack)
}
ExecuteMsg::IbcCallbackReceive { receive_msg } => {
ibc::receive::ibc_receive_internal_call(deps, env, receive_msg)
Expand Down
11 changes: 8 additions & 3 deletions contracts/liquidity/factory/src/ibc/ack_and_timeout.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
from_json, to_json_binary, Binary, CosmosMsg, DepsMut, Env, IbcAcknowledgement,
IbcBasicResponse, IbcPacketAckMsg, IbcPacketTimeoutMsg, Int256, ReplyOn, Response, StdError,
StdResult, SubMsg, WasmMsg,
ensure, from_json, to_json_binary, Binary, CosmosMsg, DepsMut, Env, IbcAcknowledgement,
IbcBasicResponse, IbcPacketAckMsg, IbcPacketTimeoutMsg, Int256, MessageInfo, ReplyOn, Response,
StdError, StdResult, SubMsg, WasmMsg,
};
use cw20::Cw20Coin;
use euclid::{
Expand Down Expand Up @@ -58,9 +58,14 @@ pub fn ibc_packet_ack(

pub fn ibc_ack_packet_internal_call(
deps: DepsMut,
info: MessageInfo,
env: Env,
ack: IbcPacketAckMsg,
) -> Result<Response, ContractError> {
ensure!(
info.sender == env.contract.address,
ContractError::Unauthorized {}
);
let msg: ChainIbcExecuteMsg = from_json(&ack.original_packet.data)?;
reusable_internal_ack_call(deps, env, msg, ack.acknowledgement.data, false)
}
Expand Down

0 comments on commit 72aee5c

Please sign in to comment.