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

Wrong data pushed for very long literal ByteString #794

Open
Hecate2 opened this issue Sep 28, 2023 · 3 comments
Open

Wrong data pushed for very long literal ByteString #794

Hecate2 opened this issue Sep 28, 2023 · 3 comments

Comments

@Hecate2
Copy link
Contributor

Hecate2 commented Sep 28, 2023

public static ByteString HashedName() => (ByteString)"\x9e\x09\x23\xa3\x9f\x51\x5e\x9a\x8c\xeb\xc9\xfb\x69\x4b\x9a\xbf\x7e\x4b\x8c\x3f\x7a\xb6\xf8\x1b\x56\xea\xbd\xac\x50\x4b\x08\xdc";
# Method Start HashedName.MinimalForwarder.MinimalForwarder
# Code EIP712.cs line 11: "(ByteString)"\x9e\x09\x23\xa3\x9f\x51\x5e\x9a\x8c\xeb\xc9\xfb\x69\x4b\x9a\xbf\x7e\x4b\x8c\x3f\x7a\xb6\xf8\x1b\x56\xea\xbd\xac\x50\x4b\x08\xdc""
8008 PUSHDATA1 C2-9E-09-23-C2-A3-C2-9F-51-5E-C2-9A-C2-8C-C3-AB-C3-89-C3-BB-69-4B-C2-9A-C2-BF-7E-4B-C2-8C-3F-7A-C2-B6-C3-B8-1B-56-C3-AA-C2-BD-C2-AC-50-4B-08-C3-9C

Many additional 0xC2 and 0xC3 inside, and 9C instead of DC at the end of pushed data.

@Hecate2
Copy link
Contributor Author

Hecate2 commented Sep 28, 2023

The workaround is to

(ByteString)new byte[] { 0x9e, 0x09, 0x23, 0xa3, 0x9f, 0x51, 0x5e, 0x9a, 0x8c, 0xeb, 0xc9, 0xfb, 0x69, 0x4b, 0x9a, 0xbf, 0x7e, 0x4b, 0x8c, 0x3f, 0x7a, 0xb6, 0xf8, 0x1b, 0x56, 0xea, 0xbd, 0xac, 0x50, 0x4b, 0x08, 0xdc };

@Hecate2
Copy link
Contributor Author

Hecate2 commented Sep 28, 2023

HashedName.zip
For the zip file of contract above, we can set a breakpoint at


and see that constant.Value is

"\u009e\t#£\u009fQ^\u009a\u008cëÉûiK\u009a¿~K\u008c?z¶ø\u001bV꽬PK\bÜ"

while syntax is

"\x9e\x09\x23\xa3\x9f\x51\x5e\x9a\x8c\xeb\xc9\xfb\x69\x4b\x9a\xbf\x7e\x4b\x8c\x3f\x7a\xb6\xf8\x1b\x56\xea\xbd\xac\x50\x4b\x08\xdc"

Then at

return Push(Utility.StrictUTF8.GetBytes(s));

we pushes UTF-8-encoded string, which is c29e0923c2a3c29f515ec29ac28cc3abc389c3bb694bc29ac2bf7e4bc28c3f7ac2b6c3b81b56c3aac2bdc2ac504b08c39c (49 bytes)

The problem is that all syntaxes of literal strings are simply handled as human-readable strings. Actually there can be bytes in a literal string.

@shargon
Copy link
Member

shargon commented Sep 28, 2023

Yes, it seems that it convert the string to UTF8

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

No branches or pull requests

2 participants