@@ -53,7 +53,7 @@ func MakeSigner(config *params.ChainConfig, blockNumber *big.Int) Signer {
5353// SignECDSA signs the transaction using the given signer and private key
5454func SignECDSA (s Signer , tx * Transaction , prv * ecdsa.PrivateKey ) (* Transaction , error ) {
5555 h := s .Hash (tx )
56- sig , err := crypto .SignEthereum (h [:], prv )
56+ sig , err := crypto .Sign (h [:], prv )
5757 if err != nil {
5858 return nil , err
5959 }
@@ -91,11 +91,6 @@ func Sender(signer Signer, tx *Transaction) (common.Address, error) {
9191 return addr , nil
9292}
9393
94- // SignatureValues returns the ECDSA signature values contained in the transaction.
95- func SignatureValues (signer Signer , tx * Transaction ) (v byte , r * big.Int , s * big.Int ) {
96- return normaliseV (signer , tx .data .V ), new (big.Int ).Set (tx .data .R ), new (big.Int ).Set (tx .data .S )
97- }
98-
9994type Signer interface {
10095 // Hash returns the rlp encoded hash for signatures
10196 Hash (tx * Transaction ) common.Hash
@@ -143,17 +138,16 @@ func (s EIP155Signer) PublicKey(tx *Transaction) ([]byte, error) {
143138 return nil , ErrInvalidChainId
144139 }
145140
146- V := normaliseV ( s , tx .data .V )
141+ V := byte ( new (big. Int ). Sub ( tx .data .V , s . chainIdMul ). Uint64 () - 35 )
147142 if ! crypto .ValidateSignatureValues (V , tx .data .R , tx .data .S , true ) {
148143 return nil , ErrInvalidSig
149144 }
150-
151145 // encode the signature in uncompressed format
152146 R , S := tx .data .R .Bytes (), tx .data .S .Bytes ()
153147 sig := make ([]byte , 65 )
154148 copy (sig [32 - len (R ):32 ], R )
155149 copy (sig [64 - len (S ):64 ], S )
156- sig [64 ] = V - 27
150+ sig [64 ] = V
157151
158152 // recover the public key from the signature
159153 hash := s .Hash (tx )
@@ -167,8 +161,8 @@ func (s EIP155Signer) PublicKey(tx *Transaction) ([]byte, error) {
167161 return pub , nil
168162}
169163
170- // WithSignature returns a new transaction with the given signature.
171- // This signature needs to be formatted as described in the yellow paper (v+27) .
164+ // WithSignature returns a new transaction with the given signature. This signature
165+ // needs to be in the [R || S || V] format where V is 0 or 1 .
172166func (s EIP155Signer ) WithSignature (tx * Transaction , sig []byte ) (* Transaction , error ) {
173167 if len (sig ) != 65 {
174168 panic (fmt .Sprintf ("wrong size for snature: got %d, want 65" , len (sig )))
@@ -179,7 +173,7 @@ func (s EIP155Signer) WithSignature(tx *Transaction, sig []byte) (*Transaction,
179173 cpy .data .S = new (big.Int ).SetBytes (sig [32 :64 ])
180174 cpy .data .V = new (big.Int ).SetBytes ([]byte {sig [64 ]})
181175 if s .chainId .BitLen () > 0 {
182- cpy .data .V = big .NewInt (int64 (sig [64 ] - 27 + 35 ))
176+ cpy .data .V = big .NewInt (int64 (sig [64 ] + 35 ))
183177 cpy .data .V .Add (cpy .data .V , s .chainIdMul )
184178 }
185179 return cpy , nil
@@ -201,7 +195,7 @@ func (s EIP155Signer) Hash(tx *Transaction) common.Hash {
201195
202196func (s EIP155Signer ) SigECDSA (tx * Transaction , prv * ecdsa.PrivateKey ) (* Transaction , error ) {
203197 h := s .Hash (tx )
204- sig , err := crypto .SignEthereum (h [:], prv )
198+ sig , err := crypto .Sign (h [:], prv )
205199 if err != nil {
206200 return nil , err
207201 }
@@ -217,22 +211,22 @@ func (s HomesteadSigner) Equal(s2 Signer) bool {
217211 return ok
218212}
219213
220- // WithSignature returns a new transaction with the given snature.
221- // This snature needs to be formatted as described in the yellow paper (v+27) .
214+ // WithSignature returns a new transaction with the given signature. This signature
215+ // needs to be in the [R || S || V] format where V is 0 or 1 .
222216func (hs HomesteadSigner ) WithSignature (tx * Transaction , sig []byte ) (* Transaction , error ) {
223217 if len (sig ) != 65 {
224218 panic (fmt .Sprintf ("wrong size for snature: got %d, want 65" , len (sig )))
225219 }
226220 cpy := & Transaction {data : tx .data }
227221 cpy .data .R = new (big.Int ).SetBytes (sig [:32 ])
228222 cpy .data .S = new (big.Int ).SetBytes (sig [32 :64 ])
229- cpy .data .V = new (big.Int ).SetBytes ([]byte {sig [64 ]})
223+ cpy .data .V = new (big.Int ).SetBytes ([]byte {sig [64 ] + 27 })
230224 return cpy , nil
231225}
232226
233227func (hs HomesteadSigner ) SignECDSA (tx * Transaction , prv * ecdsa.PrivateKey ) (* Transaction , error ) {
234228 h := hs .Hash (tx )
235- sig , err := crypto .SignEthereum (h [:], prv )
229+ sig , err := crypto .Sign (h [:], prv )
236230 if err != nil {
237231 return nil , err
238232 }
@@ -243,7 +237,7 @@ func (hs HomesteadSigner) PublicKey(tx *Transaction) ([]byte, error) {
243237 if tx .data .V .BitLen () > 8 {
244238 return nil , ErrInvalidSig
245239 }
246- V := byte (tx .data .V .Uint64 ())
240+ V := byte (tx .data .V .Uint64 () - 27 )
247241 if ! crypto .ValidateSignatureValues (V , tx .data .R , tx .data .S , true ) {
248242 return nil , ErrInvalidSig
249243 }
@@ -252,7 +246,7 @@ func (hs HomesteadSigner) PublicKey(tx *Transaction) ([]byte, error) {
252246 sig := make ([]byte , 65 )
253247 copy (sig [32 - len (r ):32 ], r )
254248 copy (sig [64 - len (s ):64 ], s )
255- sig [64 ] = V - 27
249+ sig [64 ] = V
256250
257251 // recover the public key from the snature
258252 hash := hs .Hash (tx )
@@ -273,22 +267,22 @@ func (s FrontierSigner) Equal(s2 Signer) bool {
273267 return ok
274268}
275269
276- // WithSignature returns a new transaction with the given snature.
277- // This snature needs to be formatted as described in the yellow paper (v+27) .
270+ // WithSignature returns a new transaction with the given signature. This signature
271+ // needs to be in the [R || S || V] format where V is 0 or 1 .
278272func (fs FrontierSigner ) WithSignature (tx * Transaction , sig []byte ) (* Transaction , error ) {
279273 if len (sig ) != 65 {
280274 panic (fmt .Sprintf ("wrong size for snature: got %d, want 65" , len (sig )))
281275 }
282276 cpy := & Transaction {data : tx .data }
283277 cpy .data .R = new (big.Int ).SetBytes (sig [:32 ])
284278 cpy .data .S = new (big.Int ).SetBytes (sig [32 :64 ])
285- cpy .data .V = new (big.Int ).SetBytes ([]byte {sig [64 ]})
279+ cpy .data .V = new (big.Int ).SetBytes ([]byte {sig [64 ] + 27 })
286280 return cpy , nil
287281}
288282
289283func (fs FrontierSigner ) SignECDSA (tx * Transaction , prv * ecdsa.PrivateKey ) (* Transaction , error ) {
290284 h := fs .Hash (tx )
291- sig , err := crypto .SignEthereum (h [:], prv )
285+ sig , err := crypto .Sign (h [:], prv )
292286 if err != nil {
293287 return nil , err
294288 }
@@ -313,7 +307,7 @@ func (fs FrontierSigner) PublicKey(tx *Transaction) ([]byte, error) {
313307 return nil , ErrInvalidSig
314308 }
315309
316- V := byte (tx .data .V .Uint64 ())
310+ V := byte (tx .data .V .Uint64 () - 27 )
317311 if ! crypto .ValidateSignatureValues (V , tx .data .R , tx .data .S , false ) {
318312 return nil , ErrInvalidSig
319313 }
@@ -322,7 +316,7 @@ func (fs FrontierSigner) PublicKey(tx *Transaction) ([]byte, error) {
322316 sig := make ([]byte , 65 )
323317 copy (sig [32 - len (r ):32 ], r )
324318 copy (sig [64 - len (s ):64 ], s )
325- sig [64 ] = V - 27
319+ sig [64 ] = V
326320
327321 // recover the public key from the snature
328322 hash := fs .Hash (tx )
@@ -336,18 +330,6 @@ func (fs FrontierSigner) PublicKey(tx *Transaction) ([]byte, error) {
336330 return pub , nil
337331}
338332
339- // normaliseV returns the Ethereum version of the V parameter
340- func normaliseV (s Signer , v * big.Int ) byte {
341- if s , ok := s .(EIP155Signer ); ok {
342- stdV := v .BitLen () <= 8 && (v .Uint64 () == 27 || v .Uint64 () == 28 )
343- if s .chainId .BitLen () > 0 && ! stdV {
344- nv := byte ((new (big.Int ).Sub (v , s .chainIdMul ).Uint64 ()) - 35 + 27 )
345- return nv
346- }
347- }
348- return byte (v .Uint64 ())
349- }
350-
351333// deriveChainId derives the chain id from the given v parameter
352334func deriveChainId (v * big.Int ) * big.Int {
353335 if v .BitLen () <= 64 {
0 commit comments