-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(jsonrpc): ensure toJsonHex returns valid hex for empty byte arrays #6225
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
Conversation
@cranycrane Hi, from unformatted-data-encoding, we can see that:
So for empty array or null,
And about |
Here is an example for
You will get:
For |
Thanks for your response! I understand Ethereum vs. TRON TRON returns Proposal: To align with Ethereum, TRON should return A similar issue with |
Hi, thanks for your advice. About the stateRoot, I found there is a commit as 1ea99a2. And for the another issue #6126 , it also discussed the value of Besides, you also have mentioned that |
@cranycrane Hi, would you mind close this pr soon? |
Yes, thank you. I will continue in that discussion there. |
@cranycrane |
What does this PR do?
This PR fixes the toJsonHex method to return "0x00" instead of "0x" when the input byte array is empty or null. This ensures that all returned hex values follow a valid format.
Why are these changes required?
Previously, when an empty byte array (new byte[0]) was passed, the method returned "0x", which is not a valid hex representation. This could cause issues with JSON-RPC clients that expect an even-length hex string. The fix ensures compatibility and proper formatting, which causes error, when parsing incorrect hex string.
This PR has been tested by:
✅ Unit Tests
✅ Manual Testing
Follow up
No additional changes are required at this time. However, it may be beneficial to audit other methods returning hex strings to ensure consistency across the project.