signature – How to Extract v, r, s Values from a Signed Transaction

signature

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?

Best Answer

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.