Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only allow valid denoms in bank's denom Metadata #12026

Open
4 tasks
amaury1093 opened this issue May 24, 2022 · 17 comments
Open
4 tasks

Only allow valid denoms in bank's denom Metadata #12026

amaury1093 opened this issue May 24, 2022 · 17 comments
Labels
C:x/bank S:proposed T: State Machine Breaking State machine breaking changes (impacts consensus).

Comments

@amaury1093
Copy link
Contributor

amaury1093 commented May 24, 2022

Summary of Bug

ref: #10701 (comment)

Only allow valid denoms in bank's denom Metadata.

The denom regex we use is

reDnmString = `[a-zA-Z][a-zA-Z0-9/:._-]{2,127}`

But it seems to me we don't do a regex check when writing the metadata to state.

Version

v0.46.0-rc1

Steps to Reproduce

Currently, the denom metadata is set in InitGenesis, by reading a genesis JSON file. This json file can contain denom strings that don't adhere to the regex above. But they are still written to state:

// SetDenomMetaData sets the denominations metadata
func (k BaseKeeper) SetDenomMetaData(ctx sdk.Context, denomMetaData types.Metadata) {
store := ctx.KVStore(k.storeKey)
denomMetaDataStore := prefix.NewStore(store, types.DenomMetadataPrefix)
m := k.cdc.MustMarshal(&denomMetaData)
denomMetaDataStore.Set([]byte(denomMetaData.Base), m)
}

Proposed fix

A validate basic function on Metadata to verify that all denoms match the regex.


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@aaronc
Copy link
Member

aaronc commented May 24, 2022

That makes sense but can we please get rid of the global regex when we fix this

@amaury1093
Copy link
Contributor Author

The regex should definitely go into x/bank

@alexanderbez
Copy link
Contributor

We should do this along with ensuring globally unique aliases.

@alexanderbez alexanderbez self-assigned this May 26, 2022
@amaury1093
Copy link
Contributor Author

amaury1093 commented Sep 5, 2022

@alexanderbez I would like to add this to the current sprint, because of #12729 (comment). Are you still planning to tackle this? If not, I can take it.

@amaury1093 amaury1093 moved this to 📝 Todo in Cosmos-SDK Legacy Sep 5, 2022
@amaury1093 amaury1093 added the T: State Machine Breaking State machine breaking changes (impacts consensus). label Sep 5, 2022
@amaury1093
Copy link
Contributor Author

One thing to discuss is what to do if the app has existing coins metadata already in their state, whose denoms don't match the regex.

I think we can add a bank migration that don't do any state migrations, but simply checks existing metadata, and errors/panics if there are invalid denoms with a useful message.

@alexanderbez
Copy link
Contributor

@AmauryM I am not working on it and we should definitely add it to the sprint!

I think we can add a bank migration that don't do any state migrations, but simply checks existing metadata, and errors/panics if there are invalid denoms with a useful message.

That sounds reasonable to me.

@amaury1093 amaury1093 assigned amaury1093 and unassigned alexanderbez Sep 5, 2022
@aaronc
Copy link
Member

aaronc commented Sep 6, 2022

Two related issues - one the denom regex is global and mutable (seeing I had already pointed this out above). We should either make it configurable (maybe a bank keeper param) or totally fixed. For the needs of sign mode textual it seems that we need ASCII. I know people want emojis and stuff too. These seem like two contrary aims and I might lean towards the needs of textual here over emojis. Either way would be good to address.

@alexanderbez
Copy link
Contributor

Even if the regex is a global, the app dev can modify it which would be used by all denom verification, no?

@aaronc
Copy link
Member

aaronc commented Sep 6, 2022

Even if the regex is a global, the app dev can modify it which would be used by all denom verification, no?

We can make it unexported if we want to prevent modification.

@amaury1093
Copy link
Contributor Author

What I understood is that it's:

  • either global but non-mutable
  • or a bank keeper param

Note that if we go with a keeper param, we need to remove stateless validation on Coins, e.g.

func (coin Coin) Validate() error {

@aaronc
Copy link
Member

aaronc commented Sep 6, 2022

Is there a way textual could handle non-ASCII denoms? What does textual do with raw strings with non-ASCII chars?

@amaury1093
Copy link
Contributor Author

amaury1093 commented Sep 6, 2022

Yes Textual needs its own way to deal with UTF8 in any case. Latest development from yesterday goes towards actually accepting UTF8 in the spec itself, and add spec on how the signing device escapes utf8 chars (if it wants), e.g. with its display code.

I think this makes the emoji issue in denoms orthogonal to Textual.

@alexanderbez
Copy link
Contributor

I'm a bit weary of making it a bank keeper param. I think methods on the coin type might prove to be challening as you've pointed out.

Can we keep a private immutable global (for coins and metadata) while using a different regex for sign modes?

@aaronc
Copy link
Member

aaronc commented Sep 6, 2022

Can we keep a private immutable global (for coins and metadata) while using a different regex for sign modes?

Then there's no way of guaranteeing whether sign mode textual will actually work if they're different. Do we have no use cases for custom regexes?

If sign mode textual can deal with UTF-8 somehow then the simplest solution might be to choose the most permissive regex which still is parseable.

@alexanderbez
Copy link
Contributor

Then there's no way of guaranteeing whether sign mode textual will actually work if they're different. Do we have no use cases for custom regexes?

Maybe we do, but at that point, we're just gonna have to pass around a Regex everywhere, which I guess is fine.

@amaury1093
Copy link
Contributor Author

then the simplest solution might be to choose the most permissive regex which still is parseable.

Let's go with that. Any ideas how the regex might look like? We might still want to disallow dangerous denoms which start with numeral-looking unicodes, e.g. (\u2488)

@amaury1093
Copy link
Contributor Author

I have a PR here: #13247

@amaury1093 amaury1093 moved this from 📝 Todo to 👀 Needs Review in Cosmos-SDK Legacy Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:x/bank S:proposed T: State Machine Breaking State machine breaking changes (impacts consensus).
Projects
No open projects
Status: 📋 Backlog
Development

Successfully merging a pull request may close this issue.

4 participants