1

I meet with a problem, does someone can 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)] }

2

This error happened because, in this case, S has leading zero bytes

R: 4f 9d d7 50 69 b5 1d 36 ....
S: 00 44 28 04 75 c3 d3 55 ....
   ↑ not allowed while RLP decoding

While decoding, geth treated R & S as integer, meaning leading zero is not legal to process.

In order to solve this issue, you simply have to remove leading zeros and RLP it.


you understand raw transaction as :

RLP{ RLP(nonce) + RLP(Gas price) + RLP(Gas limit) + RLP(to address) + RLP(value) + RLP(data) + V + [a0 + FixLeadingZero(R)] + [a0 + FixLeadingZero(S)] }

but that isn't right, 0xa0 is not a fixed byte, it's the first byte of RLP code, which represent the length of trailing data. ( For more detail of RLP implementation you can check out here : https://github.com/ethereum/wiki/wiki/%5BEnglish%5D-RLP )

Since R & S is usually 32 bytes, so first byte usually is 0x80 + 32 = 0xa0, but as i mentioned above, it won't always be that way.

In this case, since we trim 1 byte, so the first byte of RLP code is 0x80 + 31 = 0x9f

So after triming, S in raw transaction shouldn't be : a044280475c3d355c44829ac93118b4ebe044356185c1c08724c8bcfebbd4b3d

it should be : 9f44280475c3d355c44829ac93118b4ebe044356185c1c08724c8bcfebbd4b3d

and the format of raw transaction should be :

raw transaction = RLP( RLP(nonce) + RLP(gas price) + RLP(gas limit) +
                       RLP(to) + RLP(value) + RLP(data) +
                       V + RLP(trimLeadingZero(R)) + RLP(trimLeadingZero(S)) )

where + means concatenate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.