8

If I have a signed transaction such as 0xf86c098504a817c800825208943535353535353535353535353535353535353535880de0b6b3a76400008025a028ef61340bd939bc2195fe537567866003e1a15d3c71ff63e1590620aa636276a067cbe9d8997f761aecb703304b3800ccf555c9f3dc64214b297fb1966a3b6d83 (taken from https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md), how do I go about extracting the v,r and s values from this without using some external library?

1 Answer 1

6

This part of the signed transaction contains the v, r, and s fields:

25a028ef61340bd939bc2195fe537567866003e1a15d3c71ff63e1590620aa636276a067cbe9d8997f761aecb703304b3800ccf555c9f3dc64214b297fb1966a3b6d83

We can go through each byte (One byte is two characters in the above transaction)

The values are:

v=0x25=37

r_length=(0xa0-0x80)=0x20=32 (bytes)

r=0x28ef61340bd939bc2195fe537567866003e1a15d3c71ff63e1590620aa636276

s_length=0xa0-0x80=32

s=0x67cbe9d8997f761aecb703304b3800ccf555c9f3dc64214b297fb1966a3b6d83

The encoding of an Ethereum transaction is called RLP and you can find the find it definition in the Ethereum Yellow Paper.

3
  • 1
    Brilliant, thank you. Just one more question: How did you know which part of the transaction contained the v,r, and s fields?
    – user49342
    Commented Apr 11, 2019 at 4:06
  • 1
    Nevermind, I got it - it's because v is 1 byte, r and s are 32 bytes. Plus the 2 bytes indicating the length of r and s that makes 67 bytes, which is the length of the string you posted. Thanks!
    – user49342
    Commented Apr 11, 2019 at 4:18
  • Yes. But the RLP encoding also shows that the v value has a length of one byte since values from 1 to 127 are simple encoded as their byte value; values above that has a value indicating the length of the number in bytes followed by the actual value. Also, the three last values of a signed transaction are always v, r, s in that order. Commented Apr 11, 2019 at 7:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.