在之前的個個與簽名相關的地方我都對v的定義感到十分困惑,知道查看了黃皮書以后才對它的作用有了一定地了解,如下:
(v
is the recovery id: a 1 byte value specifying the sign and finiteness of the curve point; this value is in the range of [27, 30], however the Ethereum protocol declares the upper two possibilities, representing infinite values, invalid)
v是恢復id: 1字節值,指定曲線點的符號和有限性.這個值在[27,30]的范圍內,但是Ethereum協議聲明了上面的兩種可能性,表示無限的值,無效
查看黃皮書可見:
specify the parity and finitness of the coordinates of curve point for which r is the x-value
指定r為x值(s為y值)的曲線點坐標的奇偶性和有限度,因為當r值確定時,在橢圓曲線上是有兩個點的,v是用於說明那個點才是真正符合結果的點
r為點的x坐標,s為點的y坐標,v坐標的奇偶檢驗標識符,27表示偶數y, 28表示奇數y
the value is in the range of [27,30],however we declare the upper two possibilities,representing infinite values,invalid
這個值在[27,30]的范圍內,但是我們聲明上面兩種表示無限值的可能性無效(即只有當r,s代表的點是有限的時,v才是有效的)
v用做奇偶校驗,27表示偶數y, 28表示奇數y。
當發生分叉后,the message hash有兩種,一種是沒分叉時當v 為{27,28}時,只hash前六個元素,而是(nonce, gasprice, startgas, to, value, data)
;另一種是分叉后hash九個元素(還要再加上
CHAIN_ID
,r=0,s=0)
而且,如果,則說明to address = 0x0,那么p =
,即input;不然就為
,即data
簽名后得到的(即v)有兩種值的可能,當其作為標識符時,它的結果為{27,28};但是如果它與分叉chainId有關時,它的值為 chainId*2 =35 或chainId *2 +36,它也能表示y的奇偶性,作為奇偶檢驗,35表示偶數y, 36表示奇數y
當復原recover時,v也會根據上面的兩種可能來進行變化,如果是與chainId有關,則在輸入recover函數前,要先使用 來進行轉換
在不同的客戶端可見返回的值也有所不同:
In Geth, v
is always 00
or 01
. In testrpc, v
is always 1a
(27) or 1b
(28).