Skip to content

Commit

Permalink
Merge branch 'master' of github.com:desmos-labs/desmos into release/v2
Browse files Browse the repository at this point in the history
� Conflicts:
�	CHANGELOG.md
  • Loading branch information
leobragaz committed Oct 13, 2021
2 parents b408d54 + aaf3cf6 commit a320c5e
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 7 deletions.
124 changes: 124 additions & 0 deletions docs/architecture/adr-009-avoid-accidental-dtag-override.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# ADR 009: Avoid accidental DTag override

## Changelog

- October 7th, 2021: Proposed
- October 8th, 2021: First review
- October 11th, 2021: Finalized ADR

## Status

PROPOSED

## Abstract

We SHOULD edit the behavior of the current `MsgSaveProfile` making the `DTag` an optional flag
in order to prevent users from accidentally overriding their own DTags. In this way, users will edit
their DTag only when they specify them with the flag.

## Context

Currently, the `desmos profile tx save` CLI command always requires to specify a DTag when using it. This means that
users that do not want to edit their DTag need to specify it anyway. This could lead to the situation where a user
accidentally makes a typo while inserting the DTag triggering its edit. If this happens, and the user doesn't notice it
immediately, another user can register a profile with the now free DTag, stealing it from the original user.

## Decision

To avoid the situation described above, we need to perform some changes on the logic that handles a `MsgSaveProfile`.
First, we need to edit the `desmos tx profiles save` CLI command so that the now required `dtag` field becomes
an optional flag:
```go
func GetCmdSaveProfile() *cobra.Command {
cmd := &cobra.Command{
Use: "save",
Args: cobra.NoArgs,
Short: "Save your profile",
Long: fmt.Sprintf(`
Save a new profile or edit the existing one specifying a DTag, a nickname, biography, profile picture and cover picture.
Every data given through the flags is optional.
If you are editing an existing profile you should fill only the fields that you want to edit.
The empty ones will be filled with a special [do-not-modify] flag that tells the system to not edit them.
%s tx profiles save
--%s "LeoDiCaprio" \
--%s "Leonardo Di Caprio" \
--%s "Hollywood actor. Proud environmentalist" \
--%s "https://profilePic.jpg" \
--%s "https://profileCover.jpg"
`, version.AppName, FlagDTag, FlagNickname, FlagBio, FlagProfilePic, FlagCoverPic),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

dTag, _ := cmd.Flags().GetString(FlagDTag)
nickname, _ := cmd.Flags().GetString(FlagNickname)
bio, _ := cmd.Flags().GetString(FlagBio)
profilePic, _ := cmd.Flags().GetString(FlagProfilePic)
coverPic, _ := cmd.Flags().GetString(FlagCoverPic)

msg := types.NewMsgSaveProfile(dTag, nickname, bio, profilePic, coverPic, clientCtx.FromAddress.String())
if err = msg.ValidateBasic(); err != nil {
return fmt.Errorf("message validation failed: %w", err)
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

cmd.Flags().String(FlagDTag, types.DoNotModify, "DTag to be used")
cmd.Flags().String(FlagNickname, types.DoNotModify, "Nickname to be used")
cmd.Flags().String(FlagBio, types.DoNotModify, "Biography to be used")
cmd.Flags().String(FlagProfilePic, types.DoNotModify, "Profile picture")
cmd.Flags().String(FlagCoverPic, types.DoNotModify, "Cover picture")

flags.AddTxFlagsToCmd(cmd)

return cmd
}
```
Second, we need to remove the check on DTag inside `ValidateBasic()` that currently makes it impossible to specify an
empty DTag inside a `MsgSaveProfile`:
```go
func (msg MsgSaveProfile) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, fmt.Sprintf("invalid creator: %s", msg.Creator))
}
return nil
}
```

## Consequences

### Backwards Compatibility

There are no backwards compatibility issues related to these changes.

### Positive

* Protect users from accidentally editing their DTag.

### Negative

- None known

### Neutral

- None known

## Further Discussions

## Test Cases [optional]

The following tests cases MUST to be present:
1. Creating a profile with an empty DTag returns an error;
2. Creating a profile with DTag `[do-not-modify]` returns an error;
3. Updating a profile with a different DTag changes its value and returns no error;
4. Updating a profile with DTag `[do-not-modify]` does not update its value and returns no error.

## References

- Issue [#622](https://github.com/desmos-labs/desmos/issues/622)
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ go 1.15

require (
github.com/armon/go-metrics v0.3.9
github.com/cosmos/cosmos-sdk v0.44.0
github.com/cosmos/cosmos-sdk v0.44.1
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/ibc-go v1.2.0
github.com/cosmos/ibc-go v1.2.1
github.com/desmos-labs/Go-Emoji-Utils v1.1.1-0.20210623064146-c30bc8196d0f
github.com/ghodss/yaml v1.0.0
github.com/gogo/protobuf v1.3.3
Expand All @@ -20,14 +20,14 @@ require (
github.com/mr-tron/base58 v1.2.0
github.com/rakyll/statik v0.1.7
github.com/regen-network/cosmos-proto v0.3.1
github.com/spf13/cast v1.3.1
github.com/spf13/cast v1.4.1
github.com/spf13/cobra v1.2.1
github.com/stretchr/testify v1.7.0
github.com/syndtr/goleveldb v1.0.1-0.20210305035536-64b5b1c73954 // indirect
github.com/tendermint/tendermint v0.34.13
github.com/tendermint/tm-db v0.6.4
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c
google.golang.org/grpc v1.40.0
google.golang.org/grpc v1.41.0
google.golang.org/protobuf v1.27.1
gopkg.in/yaml.v2 v2.4.0
)
Expand Down
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ github.com/cosmos/iavl v0.15.0-rc5/go.mod h1:WqoPL9yPTQ85QBMT45OOUzPxG/U/JcJoN7u
github.com/cosmos/iavl v0.15.3/go.mod h1:OLjQiAQ4fGD2KDZooyJG9yz+p2ao2IAYSbke8mVvSA4=
github.com/cosmos/iavl v0.17.1 h1:b/Cl8h1PRMvsu24+TYNlKchIu7W6tmxIBGe6E9u2Ybw=
github.com/cosmos/iavl v0.17.1/go.mod h1:7aisPZK8yCpQdy3PMvKeO+bhq1NwDjUwjzxwwROUxFk=
github.com/cosmos/ibc-go v1.2.0 h1:0RgxmKzCzIH9SwDp4ckL5VrzlO1KJ5hO0AsOAzOiWE4=
github.com/cosmos/ibc-go v1.2.0/go.mod h1:wGjeNd+T4kpGrt0OC8DTiE/qXLrlmTPNpdoYsBZUjKI=
github.com/cosmos/ibc-go v1.2.1 h1:eWi8EzcgSwVipvhyQ7Rh1KfBe66C1ZdDSskeKMtIg0Q=
github.com/cosmos/ibc-go v1.2.1/go.mod h1:YieSs25Y0TSFR67qg6Elge34yJNEOjYhYB+HNQQLoSQ=
github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76 h1:DdzS1m6o/pCqeZ8VOAit/gyATedRgjvkVI+UCrLpyuU=
github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76/go.mod h1:0mkLWIoZuQ7uBoospo5Q9zIpqq6rYCPJDSUdeCJvPM8=
github.com/cosmos/ledger-go v0.9.2 h1:Nnao/dLwaVTk1Q5U9THldpUMMXU94BOTWPddSmVB6pI=
Expand Down Expand Up @@ -973,8 +973,9 @@ github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B
github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY=
github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cast v1.4.1 h1:s0hze+J0196ZfEMTs80N7UlFt0BDuQ7Q+JDnHiMWKdA=
github.com/spf13/cast v1.4.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
Expand Down

0 comments on commit a320c5e

Please sign in to comment.