@@ -558,6 +558,24 @@ describe('isValidSignature', function () {
558
558
const s = Buffer . from ( '129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca66' , 'hex' )
559
559
assert . equal ( ethUtils . isValidSignature ( 29 , r , s ) , false )
560
560
} )
561
+ it ( 'should fail when on homestead and s > secp256k1n/2' , function ( ) {
562
+ const SECP256K1_N_DIV_2 = new BN ( '7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0' , 16 )
563
+
564
+ const r = Buffer . from ( '99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9' , 'hex' )
565
+ const s = Buffer . from ( SECP256K1_N_DIV_2 . add ( new BN ( '1' , 16 ) ) . toString ( 16 ) , 'hex' )
566
+
567
+ const v = 27
568
+ assert . equal ( ethUtils . isValidSignature ( v , r , s , true ) , false )
569
+ } )
570
+ it ( 'should not fail when not on homestead but s > secp256k1n/2' , function ( ) {
571
+ const SECP256K1_N_DIV_2 = new BN ( '7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0' , 16 )
572
+
573
+ const r = Buffer . from ( '99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9' , 'hex' )
574
+ const s = Buffer . from ( SECP256K1_N_DIV_2 . add ( new BN ( '1' , 16 ) ) . toString ( 16 ) , 'hex' )
575
+
576
+ const v = 27
577
+ assert . equal ( ethUtils . isValidSignature ( v , r , s , false ) , true )
578
+ } )
561
579
it ( 'should work otherwise' , function ( ) {
562
580
const r = Buffer . from ( '99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9' , 'hex' )
563
581
const s = Buffer . from ( '129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca66' , 'hex' )
0 commit comments