neo-devpack-dotnet
neo-devpack-dotnet copied to clipboard
Wrong data pushed for very long literal ByteString
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.
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 };
HashedName.zip
For the zip file of contract above, we can set a breakpoint at
https://github.com/neo-project/neo-devpack-dotnet/blob/a77456b47636acfebe1fc78cad57f6ebfdc60109/src/Neo.Compiler.CSharp/MethodConvert.cs#L1234
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
https://github.com/neo-project/neo-devpack-dotnet/blob/a77456b47636acfebe1fc78cad57f6ebfdc60109/src/Neo.Compiler.CSharp/MethodConvert.cs#L3410
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.
Yes, it seems that it convert the string to UTF8