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

Tx: fix assignment of v,r,s in fromValuesArray #1077

Merged
merged 4 commits into from
Feb 12, 2021

Conversation

ryanio
Copy link
Contributor

@ryanio ryanio commented Feb 1, 2021

This PR is a follow-up fix to #1042, thanks to @jochem-brouwer for noticing this, where the logic in checking for values of v,r,s in fromValuesArray was flawed.

This bug would have been caught by _validateTxV a long time ago (prior to #1041) if the function did not return if v was zero. The proper behavior in this package is for those values to be undefined if unavailable, zero is not a valid value as it's not being checked anywhere else for zero, only undefined.

@codecov
Copy link

codecov bot commented Feb 1, 2021

Codecov Report

Merging #1077 (ad16b76) into master (22c8a4a) will increase coverage by 0.09%.
The diff coverage is 100.00%.

Impacted file tree graph

Flag Coverage Δ
block 81.22% <ø> (-0.05%) ⬇️
blockchain 83.44% <ø> (-0.08%) ⬇️
client 86.68% <ø> (ø)
common 86.34% <ø> (-0.64%) ⬇️
devp2p 84.40% <ø> (+0.29%) ⬆️
ethash 82.08% <ø> (ø)
tx 91.93% <100.00%> (+1.78%) ⬆️
vm 82.32% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

v: !v?.equals(emptyBuffer) ? new BN(v) : undefined,
r: !r?.equals(emptyBuffer) ? new BN(r) : undefined,
s: !s?.equals(emptyBuffer) ? new BN(s) : undefined,
v: v && !v.equals(emptyBuffer) ? new BN(v) : undefined,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work if v is 0. This is problematic in EIP-2930.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I am not sure if there exists legacy transactions with a v value of 0... They do exist on EIP-2930 transactions, so it can also be "fixed" there, but I am generally more in favor to be correct here; if one inputs any value (also for r and s) which is 0, then it should create a BN(0).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah hm okay, then maybe I shouldn't remove the validation for v to be zero in this commit? 14581b0

I think I'd prefer that tx v3 continues to support legacy transactions only, and then v4 can support EIP-2930. These accidental BN(0) bugs are not fun and I don't think v,r,s should ever be initialized with BN(0), only undefined for unsigned transactions, otherwise we need to add more checks around the library (like in isSigned). What do you think?

Copy link
Member

@holgerd77 holgerd77 Feb 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I am not sure if there exists legacy transactions with a v value of 0... They do exist on EIP-2930

Are you maybe mixing this up with this v - 27 thing (never understood that completely), I can't imagine that EIP-2930 is changing on the signature format?

Maybe @alcuadrado can have a short look here as well

holgerd77
holgerd77 previously approved these changes Feb 2, 2021
Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, argh, this does need another release I guess? 😋

@holgerd77 holgerd77 dismissed their stale review February 2, 2021 12:13

concurrent review by Jochem

@holgerd77
Copy link
Member

Ah, just seeing that @jochem-brouwer is also reviewing right now with some remarks, will then leave this to him to give an approval since he has generally some better insight here

@ryanio ryanio force-pushed the fix-tx-isSigned-fromValuesArray branch from a1d9f2c to 1c6aee1 Compare February 12, 2021 02:09
Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I read this correctly from the comments that the bug initially addressed was not fixed at all, so this needs as urgent a release as the initial PR, right?

@holgerd77 holgerd77 merged commit 97c30f1 into master Feb 12, 2021
@holgerd77 holgerd77 deleted the fix-tx-isSigned-fromValuesArray branch February 12, 2021 13:53
@ryanio
Copy link
Contributor Author

ryanio commented Feb 12, 2021

@holgerd77 yes, another bug fix release for this PR would be great, sorry for the troubles and thanks :) the first PR fixed one half of it (static constructor fromTxData) but fromValuesArray was still flawed and should now be fixed.

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

Successfully merging this pull request may close these issues.

3 participants