Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add ibc_handler_address to packet_args #30

Merged
merged 4 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 16 additions & 0 deletions axon/src/handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,10 @@ pub fn handle_msg_send_packet(
return Err(VerifyError::WrongPacketAck);
}

if new_channel_args.ibc_handler_address != packet_args.ibc_handler_address {
return Err(VerifyError::WrongIBCHandlerAddress);
}

commitment.write_commitments([(
packet_commitment_path(
&ibc_packet.packet.source_port_id,
Expand Down Expand Up @@ -777,6 +781,10 @@ pub fn handle_msg_recv_packet<C: Client>(
return Err(VerifyError::WrongPacketArgs);
}

if new_channel_args.ibc_handler_address != packet_args.ibc_handler_address {
return Err(VerifyError::WrongIBCHandlerAddress);
}

commitment.write_no_commitment()?;

client.verify_membership(
Expand Down Expand Up @@ -853,6 +861,10 @@ pub fn handle_msg_ack_packet<C: Client>(
return Err(VerifyError::WrongChannel);
}

if new_channel_args.ibc_handler_address != new_packet_args.ibc_handler_address {
return Err(VerifyError::WrongIBCHandlerAddress);
}

commitment.write_no_commitment()?;

client.verify_membership(
Expand Down Expand Up @@ -905,6 +917,10 @@ pub fn handle_msg_write_ack_packet(
return Err(VerifyError::WrongPacketAck);
}

if new_channel_args.ibc_handler_address != new_packet_args.ibc_handler_address {
return Err(VerifyError::WrongIBCHandlerAddress);
}

commitment.write_commitments([(
packet_acknowledgement_commitment_path(
&new_ibc_packet.packet.destination_port_id,
Expand Down
2 changes: 2 additions & 0 deletions axon/src/handler/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,7 @@ fn test_channel_packet_commitment_ping_pong() {
ack: None,
};
let a_packet_args = PacketArgs {
ibc_handler_address: a_channel_args.ibc_handler_address,
channel_id: a_channel_args.channel_id,
port_id: a_channel_args.port_id,
sequence: 1,
Expand All @@ -1128,6 +1129,7 @@ fn test_channel_packet_commitment_ping_pong() {
let mut b_packet = packet.clone();
b_packet.status = PacketStatus::Recv;
let b_packet_args = PacketArgs {
ibc_handler_address: b_channel_args.ibc_handler_address,
channel_id: b_channel_args.channel_id,
port_id: b_channel_args.port_id,
sequence: 1,
Expand Down
7 changes: 7 additions & 0 deletions axon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ impl ChannelArgs {

#[derive(Debug, Default, PartialEq, Eq, Clone, Copy)]
pub struct PacketArgs {
pub ibc_handler_address: [u8; 20], // distinguish different packet cells with same channel and port
pub channel_id: u64,
pub port_id: [u8; 32], // mark as owner_lockhash
pub sequence: u64,
Expand All @@ -190,14 +191,20 @@ impl PacketArgs {

pub fn from_slice(mut slice: &[u8]) -> Result<Self, ()> {
Ok(Self {
ibc_handler_address: *try_read!(slice, 20),
channel_id: u64::from_le_bytes(*try_read!(slice, 8)),
port_id: *try_read!(slice, 32),
sequence: u64::from_le_bytes(*try_read_last!(slice, 8)),
})
}

pub fn get_prefix_for_all(self) -> Vec<u8> {
self.ibc_handler_address.to_vec()
}

pub fn get_search_args(self, search_all: bool) -> Vec<u8> {
let mut result = Vec::new();
result.extend(self.ibc_handler_address);
result.extend(self.channel_id.to_le_bytes());
result.extend(self.port_id);
if !search_all {
Expand Down
7 changes: 4 additions & 3 deletions axon/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rlp_derive::RlpEncodable;
#[derive(Debug)]
#[repr(i8)]
pub enum VerifyError {
FoundNoMessage = 100,
FoundNoMessage = 70,
EventNotMatch,
InvalidReceiptProof,
SerdeError,
Expand All @@ -22,6 +22,7 @@ pub enum VerifyError {
WrongConnectionnNumber,
WrongPortId,
WrongCommonHexId,
WrongIBCHandlerAddress,

ConnectionsWrong,

Expand All @@ -46,8 +47,8 @@ pub enum VerifyError {
WrongPacketArgs,
WrongPacketAck,

Commitment = 98,
Mpt = 99,
Commitment,
Mpt,
}

impl From<VerifyError> for i8 {
Expand Down