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

fix fail amino sign verify with special chars #1373

Merged
merged 1 commit into from
Mar 9, 2023

Conversation

loin3
Copy link
Contributor

@loin3 loin3 commented Feb 20, 2023

this PR is for #1367

I found that there is a problem with escaping special chars in keplr-wallet. If you follow this method, the value is still escaped when you check memo of tx in mintscan. Because cosmjs sends memo through protobuf, the value needs to be escaped only when signed with amino. So escaping is done only on values ​​encoded for amino signatures. This way, even if you look up the tx, the memo will not be escaped.

Copy link
Member

@webmaster128 webmaster128 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this PR. Since we only care about JSON strings and not the whole JSON document, I think it is cleaner and safer to use the replacer argument in JSON.stringify.

Here is some example how this can be used to manipulate the inner strings as part of the stringification: https://gist.github.com/Tanapruk/4ab1505ead2491229235c886b6fbfaac

@webmaster128 webmaster128 added this to the 0.30.1 milestone Mar 7, 2023
@NoahSaso
Copy link
Contributor

NoahSaso commented Mar 7, 2023

hey @loin3, thanks for doing this :)

eagerly awaiting this over at DAO DAO because our users run into this bug all the time

@webmaster128
Copy link
Member

@NoahSaso if you need this quickly as part of the upcoming 0.30.0 release, have a look at #1367. We should implement this differently. If you are in the mood, feel free to jump in.

@webmaster128
Copy link
Member

Sorry, I mixed up issue and PR here. I was referring to

Thank you for this PR. Since we only care about JSON strings and not the whole JSON document, I think it is cleaner and safer to use the replacer argument in JSON.stringify.

Here is some example how this can be used to manipulate the inner strings as part of the stringification: https://gist.github.com/Tanapruk/4ab1505ead2491229235c886b6fbfaac

@loin3
Copy link
Contributor Author

loin3 commented Mar 8, 2023

I agree that this implementation should be changed to something tidy way. because modifying the byte code directly is very ugly.

here is the reason why I should modify byte code directly.
utf8 byte code of character & is 38 and unicode of byte codes is 92, 117, 46, 46, 50, 54 (\u0026).
json marshaller in go automatically escape the character & to unicode. so when signature verifying, incoming messages's byte code should contain 92, 117, 46, 46, 50, 54 (\u0026) rather than 38.
but the problem is JSON.stringfy authmatically change unicode (\u0026) to character &. so even though I used unicode, for example {memo: "alice \u0026 bob"}, unicode authmatically changed to "alice & bob".

@webmaster128
Copy link
Member

Oh, I see. This makes sense, thank you. In this case the current implementation makes sense. I'll have another look and throw a bunch of low level unit tests on the implementation to better understand it.

Thanks a lot!

@webmaster128
Copy link
Member

Oh damn, sorry, wrong PR. I did not aim to merge this yet. Reverted the merge. I'll look into this ASAP.

@webmaster128
Copy link
Member

I used this work in #1388. There I migrated from binary to string based replacement and increased low level test coverage. Reviews appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants