Skip to content

Commit

Permalink
Handle receiving PFM packets with invalid receivers
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed Dec 2, 2024
1 parent 0f2a755 commit 64e7e47
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 103 deletions.
64 changes: 32 additions & 32 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ fs_extra = "1.2.0"
futures = "0.3"
git2 = { version = "0.18.1", default-features = false }
# branch tiago/optional-ack
ibc = { git = "https://github.com/heliaxdev/cosmos-ibc-rs", rev = "aa229566e6bb688cc2626dab276c3849abc0c583", features = ["serde"] }
ibc-derive = { git = "https://github.com/heliaxdev/cosmos-ibc-rs", rev = "aa229566e6bb688cc2626dab276c3849abc0c583" }
ibc-middleware-packet-forward = { git = "https://github.com/heliaxdev/ibc-middleware", tag = "pfm/v0.6.0", features = ["borsh"] }
ibc-testkit = { git = "https://github.com/heliaxdev/cosmos-ibc-rs", rev = "aa229566e6bb688cc2626dab276c3849abc0c583", default-features = false }
ibc = { git = "https://github.com/heliaxdev/cosmos-ibc-rs", rev = "38489943c4e75206eaffeeeec6153c039c2499d1", features = ["serde"] }
ibc-derive = { git = "https://github.com/heliaxdev/cosmos-ibc-rs", rev = "38489943c4e75206eaffeeeec6153c039c2499d1" }
ibc-middleware-packet-forward = { git = "https://github.com/heliaxdev/ibc-middleware", tag = "pfm/v0.8.0", features = ["borsh"] }
ibc-testkit = { git = "https://github.com/heliaxdev/cosmos-ibc-rs", rev = "38489943c4e75206eaffeeeec6153c039c2499d1", default-features = false }
ics23 = "0.12.0"
index-set = { git = "https://github.com/heliaxdev/index-set", tag = "v0.8.1", features = ["serialize-borsh", "serialize-serde"] }
indexmap = { git = "https://github.com/heliaxdev/indexmap", tag = "2.2.4-heliax-1", features = ["borsh-schema", "serde"] }
Expand Down
13 changes: 10 additions & 3 deletions crates/core/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,10 @@ impl Debug for Address {
}
}

// compute an Address from an IBC signer
impl TryFrom<Signer> for Address {
impl TryFrom<&Signer> for Address {
type Error = DecodeError;

fn try_from(signer: Signer) -> Result<Self> {
fn try_from(signer: &Signer) -> Result<Self> {
// The given address should be an address or payment address. When
// sending a token from a spending key, it has been already
// replaced with the MASP address.
Expand All @@ -412,6 +411,14 @@ impl TryFrom<Signer> for Address {
}
}

impl TryFrom<Signer> for Address {
type Error = DecodeError;

fn try_from(signer: Signer) -> Result<Self> {
(&signer).try_into()
}
}

/// An established address is generated on-chain
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(
Expand Down
2 changes: 1 addition & 1 deletion crates/ibc/src/context/middlewares.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ where
C: IbcCommonContext + Debug,
Params: namada_systems::parameters::Read<<C as IbcStorageContext>::Storage>,
{
PacketForwardMiddleware::next(PfmTransferModule {
PacketForwardMiddleware::wrap(PfmTransferModule {
transfer_module: TransferModule::new(ctx, verifiers),
_phantom: PhantomData,
})
Expand Down
18 changes: 17 additions & 1 deletion crates/ibc/src/context/middlewares/pfm_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,23 @@ where
packet: &Packet,
relayer: &Signer,
) -> (ModuleExtras, Option<Acknowledgement>) {
self.transfer_module.on_recv_packet_execute(packet, relayer)
let Ok(packet_data) =
serde_json::from_slice::<PacketData>(&packet.data)
else {
return self
.transfer_module
.on_recv_packet_execute(packet, relayer);
};

if crate::is_packet_forward(&packet_data) {
self.transfer_module.ctx.enable_parse_addr_as_governance();
let ret =
self.transfer_module.on_recv_packet_execute(packet, relayer);
self.transfer_module.ctx.disable_parse_addr_as_governance();
ret
} else {
self.transfer_module.on_recv_packet_execute(packet, relayer)
}
}

fn on_acknowledgement_packet_validate(
Expand Down
Loading

0 comments on commit 64e7e47

Please sign in to comment.