@@ -106,6 +106,43 @@ describe('ecrecover', function() {
106
106
ecrecover ( echash , 27 , s , r )
107
107
} )
108
108
} )
109
+ it ( 'should return the right sender when using very high chain id / v values' , function ( ) {
110
+ // This data is from a transaction of the YoloV3 network, block 77, txhash c6121a23ca17b8ff70d4706c7d134920c1da43c8329444c96b4c63a55af1c760
111
+ /*
112
+ {
113
+ nonce: '0x8',
114
+ gasPrice: '0x3b9aca00',
115
+ gasLimit: '0x1a965',
116
+ to: undefined,
117
+ value: '0x0',
118
+ data: '0x608060405234801561001057600080fd5b50610101806100206000396000f3fe608060405260043610601f5760003560e01c8063776d1a0114603b576020565b5b6000543660008037600080366000845af43d6000803e3d6000f35b348015604657600080fd5b50608660048036036020811015605b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506088565b005b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505056fea26469706673582212206d3160e3f009c6ebac579877e529c0a1ca8313678f08fe311659d440067d26ea64736f6c63430007040033',
119
+ v: '0xf2ded8deec6714',
120
+ r: '0xec212841e0b7aaffc3b3e33a08adf32fa07159e856ef23db85175a4f6d71dc0f',
121
+ s: '0x4b8e02b96b94064a5aa2f8d72bd0040616ba8e482a5dd96422e38c9a4611f8d5'
122
+ }
123
+ */
124
+ const senderPubKey = Buffer . from (
125
+ '78988201fbceed086cfca7b64e382d08d0bd776898731443d2907c097745b7324c54f522087f5964412cddba019f192de0fd57a0ffa63f098c2b200e53594b15' ,
126
+ 'hex'
127
+ )
128
+ const msgHash = Buffer . from (
129
+ '8ae8cb685a7a9f29494b07b287c3f6a103b73fa178419d10d1184861a40f6afe' ,
130
+ 'hex'
131
+ )
132
+ const v = Buffer . from ( 'f2ded8deec6714' , 'hex' )
133
+ const r = Buffer . from ( 'ec212841e0b7aaffc3b3e33a08adf32fa07159e856ef23db85175a4f6d71dc0f' , 'hex' )
134
+ const s = Buffer . from ( '4b8e02b96b94064a5aa2f8d72bd0040616ba8e482a5dd96422e38c9a4611f8d5' , 'hex' )
135
+ const chainID = Buffer . from ( '796f6c6f763378' , 'hex' )
136
+ const sender = ecrecover ( msgHash , v , r , s , chainID )
137
+ assert . ok ( sender . equals ( senderPubKey ) , 'sender pubkey correct' )
138
+ const chainIDNumber = parseInt ( chainID . toString ( 'hex' ) , 16 )
139
+ const vNumber = parseInt ( v . toString ( 'hex' ) , 16 )
140
+ assert . throws ( ( ) => {
141
+ // If we would use numbers for the `v` and `chainId` parameters, then it should throw.
142
+ // (The numbers are too high to perform arithmetic on)
143
+ ecrecover ( msgHash , vNumber , r , s , chainIDNumber )
144
+ } )
145
+ } )
109
146
} )
110
147
111
148
describe ( 'hashPersonalMessage' , function ( ) {
0 commit comments