-
Notifications
You must be signed in to change notification settings - Fork 765
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
Signing data returns wrong signature #710
Comments
Why is this issue closed? we still get this bug on version 1.3.7 |
@shahafn can you provide all of the transaction's values? |
I don't have this particular transaction, but it is still the case that the above tx hash & private key produce this signature. Isn't it possible to inject this tx hash to your signature algorithm to reproduce it? |
Do you know how you got that hash at least? Was it a tx id? |
That is actually pretty easy to get a transaction whose signature will have 'r' or 's' shorter than 32 bytes. I ran this code in a truffle console and it took seconds:
This meant to me that I would have to manually pad the values with zero bytes as all other tools require 32-byte size for a signature field, so I switched to a different library. So the question is whether there is a rationale behind this or is it an actual bug? There is even a test for it, 'should accept lesser r values', which seems completely ill-advised to me, as I would expect the result of |
Thanks @alex-forshtat-tbk! I wasn't aware that this was so common and easy to reproduce. I'll reopen this issue and investigate it later. |
Can confirm that I have |
@alcuadrado I close it because there is an option called For example: <Buffer 00 00 00 18 16 2b ...... 45 a8 e8>, // allowLess false
<Buffer 18 16 2b ...... 45 a8 e8>, // allowLess true If you check the fields options, only const fields = [
{
name: 'nonce',
length: 32,
allowLess: true,
default: new Buffer([]),
},
{
name: 'gasPrice',
length: 32,
allowLess: true,
default: new Buffer([]),
},
{
name: 'gasLimit',
alias: 'gas',
length: 32,
allowLess: true,
default: new Buffer([]),
},
{
name: 'to',
allowZero: true,
length: 20,
default: new Buffer([]),
},
{
name: 'value',
length: 32,
allowLess: true,
default: new Buffer([]),
},
{
name: 'data',
alias: 'input',
allowZero: true,
default: new Buffer([]),
},
{
name: 'v',
allowZero: true,
default: new Buffer([opts.chain || opts.common ? this._common.chainId() : 0x1c]),
},
{
name: 'r',
length: 32,
allowZero: true,
allowLess: true,
default: new Buffer([]),
},
{
name: 's',
length: 32,
allowZero: true,
allowLess: true,
default: new Buffer([]),
},
] Seems like we have to check the length by ourselves. I'd made some change in cloned repo: sc0Vu/ethereumjs-tx@9dce2ab |
@sc0Vu this is related with RLP expects numbers to be big-endian without leading zeros, that's why they are removed. This is intended behavior, at least for now. IMO the internal representation is too coupled with the RLP serialization and leads to confusing situations like this. But changing this would be a major task. @s1na have you encountered something similar in other libraries? |
@alcuadrado Hm, not sure I had faced this exact issue before.
Fully agree with this. And yeah I can imagine de-coupling them would be a bigger task than this issue, but I think we should pursue it nevertheless. Currently the |
I saw that you opened #709, let's move this discussion there. @sc0Vu I updated your first message with an explanation about this. I'm closing this again. If someone encounters the same problem, please see my note in the first message of this issue. |
Unfortunately there is still a issue with R & S values with leading zeros. i have created a detailed example that makes it easy to understand: https://gist.github.com/SurfingNerd/2be70efd789912b5a9a51d662c38ed40 |
I couldn't disagree more with closing this issue and opening another, with a way larger scope and vaguely referencing this issue in it's description. This is a bug in a library, and if it is still there => this issue should remain open. |
Will reopen. |
I created https://github.com/ethereumjs/ethereumjs-tx/issues/164 that documents this behavior. |
This should now be resolved in #812 by storing R & S as |
Hi,
Thanks for this great library. Recently I try to sign transaction, it returned signature with wrong length (r: 31 bytes, s: 32 bytes). After debug deeply, found out that if the first bytes is 0, the library will remove.
Data:
Do you have any idea about this?
Thanks!
UPDATE by @alcuadrado: These two signatures are valid. They are equivalent when RLP-encoded, and that's how the Ethereum network sees them. This is currently (2019-05-10) a known limitation of this library, it trims all leading zeros of
r
ands
.WORKAROUND: You can transform
r
ands
into big ints before comparing them.The text was updated successfully, but these errors were encountered: