Skip to content

Commit 04a8d0d

Browse files
crodriguezvegamergify-bot
authored and
mergify-bot
committed
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
1 parent 545ccd1 commit 04a8d0d

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,14 @@ Ref: https://keepachangelog.com/en/1.0.0/
4242

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

45+
<<<<<<< HEAD
4546
### Improvements
4647

4748
* (channel) [\#692](https://github.com/cosmos/ibc-go/pull/692) Minimize channel logging by only emitting the packet sequence, source port/channel, destination port/channel upon packet receives, acknowledgements and timeouts.
49+
=======
50+
* (testing) [\#884](https://github.com/cosmos/ibc-go/pull/884) Add and use in simapp a custom ante handler that rejects redundant transactions
51+
* (transfer) [\#978](https://github.com/cosmos/ibc-go/pull/978) Support base denoms with slashes in denom validation
52+
>>>>>>> 4545154 (bug: support base denoms with slashes (#978))
4853
4954
## [v2.0.2](https://github.com/cosmos/ibc-go/releases/tag/v2.0.2) - 2021-12-15
5055

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)