Skip to content

Commit ac0a541

Browse files
bug: support base denoms with slashes (backport #978) (#1018)
* bug: support base denoms with slashes (#978) * bug: support base denoms with slashes * add changelog entry Co-authored-by: Carlos Rodriguez <crodveg@gmail.com> (cherry picked from commit 4545154) # Conflicts: # CHANGELOG.md * fix conflicts Co-authored-by: Carlos Rodriguez <carlos@interchain.io> Co-authored-by: Carlos Rodriguez <crodveg@gmail.com>
1 parent 8039ebf commit ac0a541

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ Ref: https://keepachangelog.com/en/1.0.0/
4343

4444
### Features
4545

46-
* [\#679](https://github.com/cosmos/ibc-go/pull/679) New CLI command `query ibc-transfer denom-hash <denom trace>` to get the denom hash for a denom trace; this might be useful for debug
46+
* [\#679](https://github.com/cosmos/ibc-go/pull/679) New CLI command `query ibc-transfer denom-hash <denom trace>` to get the denom hash for a denom trace; this might be useful for debug
47+
48+
### Bug Fixes
49+
50+
* (transfer) [\#978](https://github.com/cosmos/ibc-go/pull/978) Support base denoms with slashes in denom validation
4751

4852
## [v2.0.3](https://github.com/cosmos/ibc-go/releases/tag/v2.0.2) - 2022-02-03
4953

modules/apps/transfer/types/msgs_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var (
3232

3333
coin = sdk.NewCoin("atom", sdk.NewInt(100))
3434
ibcCoin = sdk.NewCoin("ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", sdk.NewInt(100))
35-
invalidIBCCoin = sdk.NewCoin("notibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", sdk.NewInt(100))
35+
invalidIBCCoin = sdk.NewCoin("ibc/7F1D3FCF4AE79E1554", sdk.NewInt(100))
3636
invalidDenomCoin = sdk.Coin{Denom: "0atom", Amount: sdk.NewInt(100)}
3737
zeroCoin = sdk.Coin{Denom: "atoms", Amount: sdk.NewInt(0)}
3838

modules/apps/transfer/types/trace.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func ValidatePrefixedDenom(denom string) error {
162162

163163
// ValidateIBCDenom validates that the given denomination is either:
164164
//
165-
// - A valid base denomination (eg: 'uatom')
165+
// - A valid base denomination (eg: 'uatom' or 'gamm/pool/1' as in https://github.com/cosmos/ibc-go/issues/894)
166166
// - A valid fungible token representation (i.e 'ibc/{hash}') per ADR 001 https://github.com/cosmos/ibc-go/blob/main/docs/architecture/adr-001-coin-source-tracing.md
167167
func ValidateIBCDenom(denom string) error {
168168
if err := sdk.ValidateDenom(denom); err != nil {
@@ -172,17 +172,17 @@ func ValidateIBCDenom(denom string) error {
172172
denomSplit := strings.SplitN(denom, "/", 2)
173173

174174
switch {
175-
case strings.TrimSpace(denom) == "",
176-
len(denomSplit) == 1 && denomSplit[0] == DenomPrefix,
177-
len(denomSplit) == 2 && (denomSplit[0] != DenomPrefix || strings.TrimSpace(denomSplit[1]) == ""):
175+
case denom == DenomPrefix:
178176
return sdkerrors.Wrapf(ErrInvalidDenomForTransfer, "denomination should be prefixed with the format 'ibc/{hash(trace + \"/\" + %s)}'", denom)
179177

180-
case denomSplit[0] == denom && strings.TrimSpace(denom) != "":
181-
return nil
182-
}
178+
case len(denomSplit) == 2 && denomSplit[0] == DenomPrefix:
179+
if strings.TrimSpace(denomSplit[1]) == "" {
180+
return sdkerrors.Wrapf(ErrInvalidDenomForTransfer, "denomination should be prefixed with the format 'ibc/{hash(trace + \"/\" + %s)}'", denom)
181+
}
183182

184-
if _, err := ParseHexHash(denomSplit[1]); err != nil {
185-
return sdkerrors.Wrapf(err, "invalid denom trace hash %s", denomSplit[1])
183+
if _, err := ParseHexHash(denomSplit[1]); err != nil {
184+
return sdkerrors.Wrapf(err, "invalid denom trace hash %s", denomSplit[1])
185+
}
186186
}
187187

188188
return nil

modules/apps/transfer/types/trace_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,12 @@ func TestValidateIBCDenom(t *testing.T) {
131131
}{
132132
{"denom with trace hash", "ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", false},
133133
{"base denom", "uatom", false},
134+
{"base denom with single '/'s", "gamm/pool/1", false},
135+
{"base denom with double '/'s", "gamm//pool//1", false},
136+
{"non-ibc prefix with hash", "notibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", false},
134137
{"empty denom", "", true},
135-
{"invalid prefixed denom", "transfer/channelToA/uatom", true},
136138
{"denom 'ibc'", "ibc", true},
137139
{"denom 'ibc/'", "ibc/", true},
138-
{"invald prefix", "notibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", true},
139140
{"invald hash", "ibc/!@#$!@#", true},
140141
}
141142

0 commit comments

Comments
 (0)