-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Return r, s, and v without leading 0's #1288
Conversation
@@ -42,14 +42,14 @@ var isNot = function(value) { | |||
}; | |||
|
|||
var trimLeadingZero = function (hex) { | |||
while (hex && hex.startsWith('0x00')) { | |||
hex = '0x' + hex.slice(4); | |||
while (hex && hex.startsWith('0x0')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with this is what if the rs, value is 0x00001234
Then a even number is made uneven
rawTx[7] = trimLeadingZero(rawTx[7]); | ||
rawTx[8] = trimLeadingZero(rawTx[8]); | ||
rawTx[7] = makeEven(trimLeadingZero(rawTx[7])); | ||
rawTx[8] = makeEven(trimLeadingZero(rawTx[8])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And are you sure passing a modified value into RLP.decode
is not going to break anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean RLP.encode
?
It looks like it dynamically calculates the length, so I don't see any problems: https://github.com/MaiaVictor/eth-lib/blob/master/lib/rlp.js#L27
In fact, I believe leaving out 0 bytes at the beginning of an int in the RLP-encoded data is a more standard approach. (not sure if it's required though)
The tests pass here. |
Additionally allowing the odd numbers again will make this problem reappear: #1258 Though its very important that signatures are correctly validated! |
Let's separate the two places where
This PR intends to not change the functionality of # 1 - the change there was only a refactor. That means that the #1258 problem should not reappear, and I agree that This PR only changes the functionality of # 2, trimming all leading 0s. This brings it in line with what the nodes themselves return when returning (non-rlp-encoded) values of |
Ill merge this. |
@frozeman No, some more work would have to be done, maybe in web3 or maybe in eth-lib. #1290 is the test that should pass. Some options I see, highest preference first:
|
On further investigation, it looks like eth-lib itself is responsible for encoding the signature. So the best solution is to fix eth-lib's |
Submitted a PR at VictorTaelin/eth-lib#4 That repo has 3 open pull requests that go back to October, and has never merged or closed an incoming pull request. Maybe eth-lib needs to be forked into the ethereum org to be maintained? Edit: BTW, I confirmed that PR 4 does cause this PR's test to pass. |
I will talk to @MaiaVictor, but we could also leftpad this before sending it to eth-lib |
I merged eth-lib and the tests pass. Ill create a new version soon |
These values are quantities, not data. Other nodes return r, s, and v as hex-encoded quantites.
See #1170