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

rlp: non-canonical integer (leading zero bytes) for *big.Int, decoding into (types.Transaction)(types.txdata).R #24

Closed
foreso-GitHub opened this issue May 30, 2018 · 13 comments

Comments

@foreso-GitHub
Copy link

Sometime, such error will happen when we do a lot of transactions in one time. What's the meaning of it? How to avoid such error?

"rlp: non-canonical integer (leading zero bytes) for *big.Int, decoding into (types.Transaction)(types.txdata).R"

@mdranger
Copy link
Collaborator

This error is caused by the individual values r and s have single leading 0s. This was observed by Eth earlier:
web3/web3.js#1170
We have already taken care of this in Chain3/lib/utils/account.js
line 251-253:
rawTx[vPos] = makeEven(bufferToHex(newV));
rawTx[vPos+1] = makeEven(bufferToHex(newsign.r));
rawTx[vPos+2] = makeEven(bufferToHex(newsign.s));
Can you send me a signed results of the transaction?

@foreso-GitHub
Copy link
Author

Thanks mdranger. Sorry, I did not keep it. Will send you if I keep it next time.

@mdranger
Copy link
Collaborator

Please let us know if you still see this. Thanks.

@foreso-GitHub
Copy link
Author

It is hard to reproduce, normally happens when we execute a lot of transfer by one address continuously. JFYI.
Will try to catch the signed result when it happens next time.

@foreso-GitHub
Copy link
Author

Similar error happen again when I executed a erc20 transfer.

rawTx: {"from":"0x460420a40a694e2efbc5defdb8a0a76f3134ecfb","to":"0x3de4c3b9add4f95c74adeb538537f68b7c6dccb4","value":"0x0","nonce":"0x19","gasPrice":"0x17d7840","gasLimit":"0x9c40","data":"0xa9059cbb000000000000000000000000dbc02f7819d8f88dd473974ca516afc78700d3bf00000000000000000000000000000000000000000000000564d702d38f5e0000","chainId":"101"}

Error: rlp: non-canonical integer (leading zero bytes) for *big.Int, decoding into (types.Transaction)(types.txdata).R
at Object.InvalidResponse (C:\work\SparkChain\Codes\spc-moac-end\node_modules\chain3\lib\chain3\errors.js:41:16)
at C:\work\SparkChain\Codes\spc-moac-end\node_modules\chain3\lib\chain3\requestmanager.js:81:36
at XMLHttpRequest.request.onreadystatechange (C:\work\SparkChain\Codes\spc-moac-end\node_modules\chain3\lib\chain3\httpprovider.js:128:7)
at XMLHttpRequestEventTarget.dispatchEvent (C:\work\SparkChain\Codes\spc-moac-end\node_modules\xhr2\lib\xhr2.js:64:18)
at XMLHttpRequest._setReadyState (C:\work\SparkChain\Codes\spc-moac-end\node_modules\xhr2\lib\xhr2.js:354:12)
at XMLHttpRequest._onHttpResponseEnd (C:\work\SparkChain\Codes\spc-moac-end\node_modules\xhr2\lib\xhr2.js:509:12)
at IncomingMessage. (C:\work\SparkChain\Codes\spc-moac-end\node_modules\xhr2\lib\xhr2.js:469:24)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
err: Error: rlp: non-canonical integer (leading zero bytes) for *big.Int, decoding into (types.Transaction)(types.txdata).R

@foreso-GitHub foreso-GitHub reopened this May 31, 2018
@foreso-GitHub
Copy link
Author

@mdranger

@foreso-GitHub
Copy link
Author

Here is the signed tx:
"0xf8ac198084017d7840829c40943de4c3b9add4f95c74adeb538537f68b7c6dccb480b844a9059cbb000000000000000000000000dbc02f7819d8f88dd473974ca516afc78700d3bf00000000000000000000000000000000000000000000000564d702d38f5e0000808081eea000e66f458bf1bab4d691f1f500c5a5d884de6a9c05a0f3fa0a523e6c6dbb83afa001719cf7dcbd31d71cef6fcfb2491059194042b602fb154803749f1ac1754e97"

@mdranger
Copy link
Collaborator

when decoded the signed TX back, we can see the R and S are like this:
R: '0x00e66f458bf1bab4d691f1f500c5a5d884de6a9c05a0f3fa0a523e6c6dbb83af'
S: '0x01719cf7dcbd31d71cef6fcfb2491059194042b602fb154803749f1ac1754e97'
It may caused by the '0x00' prefix, which should be removed.
R: '0xe66f458bf1bab4d691f1f500c5a5d884de6a9c05a0f3fa0a523e6c6dbb83af'

@mdranger
Copy link
Collaborator

We added the following lines in the lib/utils/account.js file,
//To fix an error of 2 leading 0s
//
var trimLeadingZero = function (hex) {
while (hex && hex.startsWith('0x00')) {
hex = '0x' + hex.slice(4);
}
return hex;
};

line 258:
rawTx[vPos] = trimLeadingZero(makeEven(bufferToHex(newV)));
rawTx[vPos+1] = trimLeadingZero(makeEven(bufferToHex(newsign.r)));
rawTx[vPos+2] = trimLeadingZero(makeEven(bufferToHex(newsign.s)));

We will update the package soon.
Thanks.

@foreso-GitHub
Copy link
Author

Great! My pleasure.

@mdranger
Copy link
Collaborator

mdranger commented Jun 1, 2018

The Chain3 is updated to 0.1.7 to fix this problem.

@FutureOfAI
Copy link

FutureOfAI commented Jun 8, 2019

when decoded the signed TX back, we can see the R and S are like this:
R: '0x00e66f458bf1bab4d691f1f500c5a5d884de6a9c05a0f3fa0a523e6c6dbb83af'
S: '0x01719cf7dcbd31d71cef6fcfb2491059194042b602fb154803749f1ac1754e97'
It may caused by the '0x00' prefix, which should be removed.
R: '0xe66f458bf1bab4d691f1f500c5a5d884de6a9c05a0f3fa0a523e6c6dbb83af'

I have same problem as you, can you help me how to deal with leading zero in raw-transaction?
My raw transaction is: f86b0285012a05f2008261a8948b733353ce21ebd8eb5ffd9f49d57830942e88158769ec95a3fa70008025a04f9dd75069b51d36ec47b5bf68e6c45f8b854cf17a661e734e7a7c651240eeaca00044280475c3d355c44829ac93118b4ebe044356185c1c08724c8bcfebbd4b3d

Boardcast shows error: non-canonical integer (leading zero bytes) for *big.Int, decoding into (types.Transaction)(types.txdata).S"

including raw-transaction:
R is 4f9dd75069b51d36ec47b5bf68e6c45f8b854cf17a661e734e7a7c651240eeac
S is 0044280475c3d355c44829ac93118b4ebe044356185c1c08724c8bcfebbd4b3d

How can I deal with leading zero, and how can I re-construction raw-transaction after correct it?
Does the process like this?
RLP{ RLP(nonce) + RLP(Gas price) + RLP(Gas limit) + RLP(to address) + RLP(value) + RLP(data) + V + [a0 + FixLeadingZero(R)] + [a0 + FixLeadingZero(S)] }

@anysoft
Copy link

anysoft commented Dec 9, 2019

when decoded the signed TX back, we can see the R and S are like this:
R: '0x00e66f458bf1bab4d691f1f500c5a5d884de6a9c05a0f3fa0a523e6c6dbb83af'
S: '0x01719cf7dcbd31d71cef6fcfb2491059194042b602fb154803749f1ac1754e97'
It may caused by the '0x00' prefix, which should be removed.
R: '0xe66f458bf1bab4d691f1f500c5a5d884de6a9c05a0f3fa0a523e6c6dbb83af'

I have same problem as you, can you help me how to deal with leading zero in raw-transaction?
My raw transaction is: f86b0285012a05f2008261a8948b733353ce21ebd8eb5ffd9f49d57830942e88158769ec95a3fa70008025a04f9dd75069b51d36ec47b5bf68e6c45f8b854cf17a661e734e7a7c651240eeaca00044280475c3d355c44829ac93118b4ebe044356185c1c08724c8bcfebbd4b3d

Boardcast shows error: non-canonical integer (leading zero bytes) for *big.Int, decoding into (types.Transaction)(types.txdata).S"

including raw-transaction:
R is 4f9dd75069b51d36ec47b5bf68e6c45f8b854cf17a661e734e7a7c651240eeac
S is 0044280475c3d355c44829ac93118b4ebe044356185c1c08724c8bcfebbd4b3d

How can I deal with leading zero, and how can I re-construction raw-transaction after correct it?
Does the process like this?
RLP{ RLP(nonce) + RLP(Gas price) + RLP(Gas limit) + RLP(to address) + RLP(value) + RLP(data) + V + [a0 + FixLeadingZero(R)] + [a0 + FixLeadingZero(S)] }

you can convert r and s to biginteger then convert the result to bytes to del leading zero bytes

because the signed r and s must be 32bytes . sometimes them need add zero bytes for padding
to serial and broadcast the tx we need del them.

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

No branches or pull requests

4 participants