-
Notifications
You must be signed in to change notification settings - Fork 88
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
base: main
Are you sure you want to change the base?
Conversation
398a63c
to
2f5d0ae
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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")] |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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")] |
There was a problem hiding this comment.
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}, |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// - 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// - 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// - if the `destination_chain_address` is not 256 bytes long | |
/// - if the `destination_chain_address` is over 256 bytes long |
if destination_chain_address.as_bytes().len() > 0 | ||
&& destination_chain_address.as_bytes().len() <= 256 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Summary
Enforces length constraints on
destination_chain_address
in BridgeTransfer and BridgeLockBackground
Invalid
destination_chain_address
could have been passed before as there as no checkChanges
In `crates/astria-core/src/protocol/transaction/v1/mod.rs
Changelogs
Changelogs updated
Related Issues
#1961
closes #1961