-
Notifications
You must be signed in to change notification settings - Fork 238
Ensures all transaction properties that are strings are 0x prefixed #144
Conversation
9c0cc79
to
7bbc261
Compare
@danjm can you also fix conflicts here? Eventually also drop a note on your preferred review/merge order. |
85df7a9
to
eb7ae3c
Compare
7bbc261
to
61c64fe
Compare
@chikeichan awaiting your final approval |
…ith different types
27c104a
to
f0cfb2e
Compare
I just saw this. I have mixed feelings about the goal tbh for two reasons:
@holgerd77 what do you think? |
TBH I also had mixed feelings but didn't say anything. Yes, as @s1na mentioned, the preferred way would be to restrict the API on the base layer. We had all sorts of problems in the past with becoming too loose including serious bugs and the current thinking - also influenced by experienced devs like @axic with longer experience on the libraries - is to go to more disambiguous API definitions. |
This is a very good point. Especially in javascript, where sometimes This PR introduces a breaking change. So given that we are doing that, why not just throw when there's no I believe every use of unprefixed strings here is an error, and users will appreciate this change. Currently, if strings don't have the
The default encoding of Also, if we are going to throw in this case, I'd do it in ethereumjs-util, as the reasoning is the same for anything calling |
Yep, also think we should throw in such cases. |
@holgerd77 @s1na @alcuadrado So it sounds like there is consensus that we should close this in favour of a PR in |
I started working on a PR in |
The PR I mentioned in my previous comment has already been merged, so I'll close this one. |
fixes #90
This PR ensures that when tx properties are passed to the constructor in either an array or object, the properties that are strings are '0x' prefixed. Without this, the following two sets of inputs would create different transactions (i.e. with different hashes and serializations):
Problem being solved.
These properties are converted to buffers during instantiation by
ethUtil.definedProperties
. When strings are prefixed by '0x', they will be converted byBuffer.from(exports.padToEven(exports.stripHexPrefix(v)), 'hex');
, otherwise they will be converted byBuffer.from(v)
. This will convert the string with different encoding https://nodejs.org/api/buffer.html#buffer_class_method_buffer_from_string_encodingThis could cause unexpected discrepencies in transactions when '0x' prefixes are forgotten, as indicated in the issue motivating this PR: #90