Skip to content

Commit

Permalink
feat(proto, core, sequencer)!: permit bech32 compatible addresses (#1425
Browse files Browse the repository at this point in the history
)

## Summary
Enables bech32 compatible addresses when necessary.

## Background
Some IBC enabled chains enforce that ics20 transfer packets must contain
bech32 compatible only (see
#1407 for more background).
This patch adds a `ibc_compat` prefix to sequencer's genesis and a new
field `bool Ics20Withdrawal.use_compat_address` to the withdrawal action
to request a bech32 compatible address format when interacting with such
chains.

## Changes
- Add field
`astria.protocol.transactions.v1alpha1.Ics20Withdrawal.use_compat_address`
- Add field
`astria.protocol.genesis.v1alpha1.AddressPrefixes.ibc_compat`
- Rewrite the `Address` domain type to be generic over the format; this
allows bech32 and bech32m addresses when parsing and formatting
- Note that all Astria domain types containing addresses now require
`Address<Bech32m>` with `Bech32m` also being set as the default type is
the parameter is absent
- this now enforces that all Astria addresses in Astria's domain types
*must* be bech32m compatible (this was not enforced before because
`bech32::decode` does not enforce either checksum as of `[email protected]`).
- When executing an
`astria.protocol.transactions.v1alpha1.Ics20Withdrawal` with field
`use_compat_address == true`, sequencer will now construct a bech32
compatible address using the value stored at `prefixes/ibc-compat` in
its state.
- When refunding a rollup due to a failed withdrawal, sequencer will now
attempt to parse the sender as either a standard (non-compat) bech32m
address, or a compat bech32 address.
- If a compat bech32 address was found during a refund, sequencer will
convert it to a bech32m address with its base prefix for further
processing. This ensures that the compat addresses are only ever
constructed for outgoing and incoming fungible token packets.

## Testing
+ Updated sequencer tests for ics20 refunds for both compat and
base/non-compat senders.
+ Updated all snapshot tests
+ Added a snapshot test for `Address<Bech32>`
+ Added unit tests for address parsing (to ensure that bech32 addresses
cannot be parsaed as bech32m and vice versa)
+ Updated chart sequencer genesis to run smoke tests
+ IBC tests for noble are still work in progress and outside the scope
of this PR.

## Breaking Changelist
- Sequencer gained a new genesis value (the ibc compat prefix), changing
the app hash

## Related Issues
Closes #1407
  • Loading branch information
SuperFluffy authored Sep 5, 2024
1 parent e9d5f0f commit 0ed3c19
Show file tree
Hide file tree
Showing 35 changed files with 846 additions and 332 deletions.
2 changes: 1 addition & 1 deletion charts/sequencer/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.22.0
version: 0.22.1
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
Expand Down
3 changes: 2 additions & 1 deletion charts/sequencer/files/cometbft/config/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"outbound_ics20_transfers_enabled": {{ .Values.genesis.ibc.outboundEnabled }}
},
"address_prefixes": {
"base": "{{ .Values.genesis.addressPrefixes.base }}"
"base": "{{ .Values.genesis.addressPrefixes.base }}",
"ibcCompat": "{{ .Values.genesis.addressPrefixes.ibcCompat }}"
},
"accounts": [
{{- range $index, $value := .Values.genesis.genesisAccounts }}
Expand Down
1 change: 1 addition & 0 deletions charts/sequencer/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ genesis:
genesisTime: "" # '2023-09-22T17:22:35.092832Z'
addressPrefixes:
base: "astria"
ibcCompat: "astriacompat"
authoritySudoAddress: ""
nativeAssetBaseDenomination: nria
allowedFeeAssets: []
Expand Down
3 changes: 3 additions & 0 deletions crates/astria-bridge-contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,9 @@ where
timeout_time: timeout_in_5_min(),
source_channel,
bridge_address: Some(self.bridge_address),
// FIXME: this needs a way to determine when to use compat address
// https://github.com/astriaorg/astria/issues/1424
use_compat_address: false,
};
Ok(Action::Ics20Withdrawal(action))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ impl From<Ics20Withdrawal> for SubsetOfIcs20Withdrawal {
fee_asset,
memo,
bridge_address,
use_compat_address: _use_compat_address,
} = value;
Self {
amount,
Expand Down Expand Up @@ -464,6 +465,7 @@ pub fn make_ics20_withdrawal_action(receipt: &TransactionReceipt) -> Action {
timeout_time,
source_channel: "channel-0".parse().unwrap(),
bridge_address: Some(default_bridge_address()),
use_compat_address: false,
};

Action::Ics20Withdrawal(inner)
Expand Down
3 changes: 2 additions & 1 deletion crates/astria-cli/src/commands/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use astria_core::{
crypto::SigningKey,
primitive::v1::{
Address,
Bech32m,
ADDRESS_LEN,
},
protocol::transaction::v1alpha1::{
Expand Down Expand Up @@ -167,7 +168,7 @@ pub(crate) fn make_bech32m(args: &Bech32mAddressArgs) -> eyre::Result<()> {
use hex::FromHex as _;
let bytes = <[u8; ADDRESS_LEN]>::from_hex(&args.bytes)
.wrap_err("failed decoding provided hex bytes")?;
let address = Address::builder()
let address = Address::<Bech32m>::builder()
.array(bytes)
.prefix(&args.prefix)
.try_build()
Expand Down

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

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

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

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

Loading

0 comments on commit 0ed3c19

Please sign in to comment.