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

feat: enforce length constraints on destination_chain_address #1977

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

varun-doshi
Copy link

Summary

Enforces length constraints on destination_chain_address in BridgeTransfer and BridgeLock

Background

Invalid destination_chain_address could have been passed before as there as no check

Changes

In `crates/astria-core/src/protocol/transaction/v1/mod.rs

Changelogs

Changelogs updated

Related Issues

#1961

closes #1961

Copy link
Member

@joroshiba joroshiba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contribution, some improvements to be made.

@@ -1557,6 +1539,8 @@ impl Protobuf for BridgeLock {
/// - if the `to` field is invalid
/// - if the `asset` field is invalid
/// - if the `fee_asset` field is invalid
/// /// - if `destination_chain_address` is not set
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting oddity

@@ -1988,6 +1989,9 @@ impl Protobuf for BridgeTransfer {
"destination_chain_address",
));
}
if destination_chain_address.as_bytes().len() != 256 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here as well

@@ -1638,6 +1636,8 @@ enum BridgeLockErrorKind {
InvalidAsset(#[source] asset::ParseDenomError),
#[error("the `fee_asset` field was invalid")]
InvalidFeeAsset(#[source] asset::ParseDenomError),
#[error("the `destination_chain_address` length is not 256")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re shouldn't be exactly update language here as well

Copy link
Author

@varun-doshi varun-doshi Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be the correct error message?

the destination_chain_address length is 0 or greater than 256

"destination_chain_address",
));
}
if proto.destination_chain_address.as_bytes().len() != 256 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 256 bytes is a reasonable upper limit, but we shouldn't restrict to an exact meassure.

@@ -2059,6 +2068,8 @@ enum BridgeTransferErrorKind {
FeeAsset { source: asset::ParseDenomError },
#[error("the `bridge_address` field was invalid")]
BridgeAddress { source: AddressError },
#[error("the `destination_chain_address` length is not 256")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again

channel::ChannelId,
client::Height as IbcHeight,
},
core::{channel::ChannelId, client::Height as IbcHeight},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

general throughout here, please don't override formatting.

If you have just installed can run just fmt rust to format according to repo standards.

@@ -1556,7 +1556,8 @@ impl Protobuf for BridgeLock {
/// - if the `to` field is not set
/// - if the `to` field is invalid
/// - if the `asset` field is invalid
/// - if the `fee_asset` field is invalid
/// - if the `fee_asset` field is invalid /// - if `destination_chain_address` is not set
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// - if the `fee_asset` field is invalid /// - if `destination_chain_address` is not set
/// - if the `fee_asset` field is invalid
/// - if `destination_chain_address` is not set

@@ -1556,7 +1556,8 @@ impl Protobuf for BridgeLock {
/// - if the `to` field is not set
/// - if the `to` field is invalid
/// - if the `asset` field is invalid
/// - if the `fee_asset` field is invalid
/// - if the `fee_asset` field is invalid /// - if `destination_chain_address` is not set
/// - if the `destination_chain_address` is not 256 bytes long
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// - if the `destination_chain_address` is not 256 bytes long
/// - if the `destination_chain_address` is over 256 bytes long

@@ -1968,6 +1983,7 @@ impl Protobuf for BridgeTransfer {
/// - if the `fee_asset` field is invalid
/// - if the `from` field is invalid
/// - if `destination_chain_address` is not set
/// - if the `destination_chain_address` is not 256 bytes long
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// - if the `destination_chain_address` is not 256 bytes long
/// - if the `destination_chain_address` is over 256 bytes long

Comment on lines 2007 to 2008
if destination_chain_address.as_bytes().len() > 0
&& destination_chain_address.as_bytes().len() <= 256
Copy link
Collaborator

@noot noot Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if destination_chain_address.as_bytes().len() > 0
&& destination_chain_address.as_bytes().len() <= 256
if destination_chain_address.as_bytes().is_empty() || destination_chain_address.as_bytes().len() > 256

ideally these will be two separate errors actually

@varun-doshi varun-doshi requested a review from noot February 21, 2025 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

enforce length constraints on destination_chain_address for BridgeLock and BridgeTransfer
3 participants