From 0b1a3eed393dce132fa2bb812fea12e26f306985 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Fri, 13 Nov 2020 15:32:33 +0100 Subject: [PATCH] add docs and make prefix a const (#7926) Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- x/ibc/applications/transfer/keeper/relay.go | 4 +++- x/ibc/applications/transfer/spec/01_concepts.md | 6 ++++++ x/ibc/applications/transfer/types/keys.go | 3 +++ x/ibc/applications/transfer/types/trace.go | 6 +++--- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/x/ibc/applications/transfer/keeper/relay.go b/x/ibc/applications/transfer/keeper/relay.go index c9bc4470d3..d26e71e984 100644 --- a/x/ibc/applications/transfer/keeper/relay.go +++ b/x/ibc/applications/transfer/keeper/relay.go @@ -361,7 +361,9 @@ func (k Keeper) refundPacketToken(ctx sdk.Context, packet channeltypes.Packet, d // DenomPathFromHash returns the full denomination path prefix from an ibc denom with a hash // component. func (k Keeper) DenomPathFromHash(ctx sdk.Context, denom string) (string, error) { - hexHash := denom[4:] + // trim the denomination prefix, by default "ibc/" + hexHash := denom[len(types.DenomPrefix+"/"):] + hash, err := types.ParseHexHash(hexHash) if err != nil { return "", sdkerrors.Wrap(types.ErrInvalidDenomForTransfer, err.Error()) diff --git a/x/ibc/applications/transfer/spec/01_concepts.md b/x/ibc/applications/transfer/spec/01_concepts.md index 55b8a6c0c6..96f05f12a7 100644 --- a/x/ibc/applications/transfer/spec/01_concepts.md +++ b/x/ibc/applications/transfer/spec/01_concepts.md @@ -109,3 +109,9 @@ Cosmos Hub for the `uatom`). Sending a token back to the same chain across a dif **not** move the token back across its timeline. If a channel in the chain history closes before the token can be sent back across that channel, then the token will not be returnable to its original form. + + +## Security Considerations + +For safety, no other module must be capable of minting tokens with the `ibc/` prefix. The IBC +transfer module needs a subset of the denomination space that only it can create tokens in. diff --git a/x/ibc/applications/transfer/types/keys.go b/x/ibc/applications/transfer/types/keys.go index b9d4b3085e..f1fbffd951 100644 --- a/x/ibc/applications/transfer/types/keys.go +++ b/x/ibc/applications/transfer/types/keys.go @@ -25,6 +25,9 @@ const ( // QuerierRoute is the querier route for IBC transfer QuerierRoute = ModuleName + + // DenomPrefix is the prefix used for internal SDK coin representation. + DenomPrefix = "ibc" ) var ( diff --git a/x/ibc/applications/transfer/types/trace.go b/x/ibc/applications/transfer/types/trace.go index d465dcbc29..b4527d668f 100644 --- a/x/ibc/applications/transfer/types/trace.go +++ b/x/ibc/applications/transfer/types/trace.go @@ -54,7 +54,7 @@ func (dt DenomTrace) GetPrefix() string { // 'ibc/{hash(tracePath + baseDenom)}'. If the trace is empty, it will return the base denomination. func (dt DenomTrace) IBCDenom() string { if dt.Path != "" { - return fmt.Sprintf("ibc/%s", dt.Hash()) + return fmt.Sprintf("%s/%s", DenomPrefix, dt.Hash()) } return dt.BaseDenom } @@ -172,8 +172,8 @@ func ValidateIBCDenom(denom string) error { switch { case strings.TrimSpace(denom) == "", - len(denomSplit) == 1 && denomSplit[0] == "ibc", - len(denomSplit) == 2 && (denomSplit[0] != "ibc" || strings.TrimSpace(denomSplit[1]) == ""): + len(denomSplit) == 1 && denomSplit[0] == DenomPrefix, + len(denomSplit) == 2 && (denomSplit[0] != DenomPrefix || strings.TrimSpace(denomSplit[1]) == ""): return sdkerrors.Wrapf(ErrInvalidDenomForTransfer, "denomination should be prefixed with the format 'ibc/{hash(trace + \"/\" + %s)}'", denom) case denomSplit[0] == denom && strings.TrimSpace(denom) != "":