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

Util: rename/adjust hexStringToBytes to prefixedHexStringToBytes #2827

Closed
holgerd77 opened this issue Jun 27, 2023 · 0 comments · Fixed by #2830
Closed

Util: rename/adjust hexStringToBytes to prefixedHexStringToBytes #2827

holgerd77 opened this issue Jun 27, 2023 · 0 comments · Fixed by #2830

Comments

@holgerd77
Copy link
Member

holgerd77 commented Jun 27, 2023

We have made bad experiences with being loose on hex string prefixes - also on the input side - and allow for lazy input and addition or removal, getting more strict here was therefore a substantial part of one of former breaking release rounds.

The current hexStringToBytes() method does a lazy if (hex.startsWith('0x')) { hex = hex.slice(2) } conversion here.

This leads to the problematic situation that it is just not deterministically decidable if a 0x string is either a prefix or part of the string itself, in case both is allowed.

So let's say one has the - let's assume - prefixed hex string:

0x0x1234

The following would then be the - unprefixed hex string:

0x1234

So it is just not decidable if 0x is part of the string or it is a prefix and it is highly recommendable to request from users to decide on the format before-hand. The prefixed version is preferred here since once can always throw if a non-prefixed version is provided, and so do an always-working format check.

This is not only a theoretical example. People can put arbitrary byte data on some fields (e.g. extraData) or might even do this on purpose 😋 to annoy developers and cause things to break.

So, long story short: we should definitely update here before the breaking releases and rename to prefixedHexStringToBytes(), remove the 0x stripping and throw for all non-0x-strings passed.

I will already add/reference the updated name to the release notes.

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

Successfully merging a pull request may close this issue.

1 participant