@@ -2572,7 +2572,6 @@ void test_ecmult_multi(secp256k1_scratch *scratch, secp256k1_ecmult_multi_func e
2572
2572
secp256k1_gej r ;
2573
2573
secp256k1_gej r2 ;
2574
2574
ecmult_multi_data data ;
2575
- secp256k1_scratch * scratch_empty ;
2576
2575
2577
2576
data .sc = sc ;
2578
2577
data .pt = pt ;
@@ -2607,11 +2606,6 @@ void test_ecmult_multi(secp256k1_scratch *scratch, secp256k1_ecmult_multi_func e
2607
2606
secp256k1_gej_add_var (& r , & r , & r2 , NULL );
2608
2607
CHECK (secp256k1_gej_is_infinity (& r ));
2609
2608
2610
- /* Try to multiply 1 point, but scratch space is empty */
2611
- scratch_empty = secp256k1_scratch_create (& ctx -> error_callback , 0 );
2612
- CHECK (!ecmult_multi (& ctx -> ecmult_ctx , scratch_empty , & r , & szero , ecmult_multi_callback , & data , 1 ));
2613
- secp256k1_scratch_destroy (scratch_empty );
2614
-
2615
2609
/* Try to multiply 1 point, but callback returns false */
2616
2610
CHECK (!ecmult_multi (& ctx -> ecmult_ctx , scratch , & r , & szero , ecmult_multi_false_callback , & data , 1 ));
2617
2611
@@ -2809,6 +2803,24 @@ void test_ecmult_multi(secp256k1_scratch *scratch, secp256k1_ecmult_multi_func e
2809
2803
}
2810
2804
}
2811
2805
2806
+ void test_ecmult_multi_batch_single (secp256k1_ecmult_multi_func ecmult_multi ) {
2807
+ secp256k1_scalar szero ;
2808
+ secp256k1_scalar sc [32 ];
2809
+ secp256k1_ge pt [32 ];
2810
+ secp256k1_gej r ;
2811
+ ecmult_multi_data data ;
2812
+ secp256k1_scratch * scratch_empty ;
2813
+
2814
+ data .sc = sc ;
2815
+ data .pt = pt ;
2816
+ secp256k1_scalar_set_int (& szero , 0 );
2817
+
2818
+ /* Try to multiply 1 point, but scratch space is empty.*/
2819
+ scratch_empty = secp256k1_scratch_create (& ctx -> error_callback , 0 );
2820
+ CHECK (!ecmult_multi (& ctx -> ecmult_ctx , scratch_empty , & r , & szero , ecmult_multi_callback , & data , 1 ));
2821
+ secp256k1_scratch_destroy (scratch_empty );
2822
+ }
2823
+
2812
2824
void test_secp256k1_pippenger_bucket_window_inv (void ) {
2813
2825
int i ;
2814
2826
@@ -2932,19 +2944,25 @@ void test_ecmult_multi_batching(void) {
2932
2944
}
2933
2945
data .sc = sc ;
2934
2946
data .pt = pt ;
2947
+ secp256k1_gej_neg (& r2 , & r2 );
2935
2948
2936
- /* Test with empty scratch space */
2949
+ /* Test with empty scratch space. It should compute the correct result using
2950
+ * ecmult_mult_simple algorithm which doesn't require a scratch space. */
2937
2951
scratch = secp256k1_scratch_create (& ctx -> error_callback , 0 );
2938
- CHECK (!secp256k1_ecmult_multi_var (& ctx -> ecmult_ctx , scratch , & r , & scG , ecmult_multi_callback , & data , 1 ));
2952
+ CHECK (secp256k1_ecmult_multi_var (& ctx -> ecmult_ctx , scratch , & r , & scG , ecmult_multi_callback , & data , n_points ));
2953
+ secp256k1_gej_add_var (& r , & r , & r2 , NULL );
2954
+ CHECK (secp256k1_gej_is_infinity (& r ));
2939
2955
secp256k1_scratch_destroy (scratch );
2940
2956
2941
2957
/* Test with space for 1 point in pippenger. That's not enough because
2942
- * ecmult_multi selects strauss which requires more memory. */
2958
+ * ecmult_multi selects strauss which requires more memory. It should
2959
+ * therefore select the simple algorithm. */
2943
2960
scratch = secp256k1_scratch_create (& ctx -> error_callback , secp256k1_pippenger_scratch_size (1 , 1 ) + PIPPENGER_SCRATCH_OBJECTS * ALIGNMENT );
2944
- CHECK (!secp256k1_ecmult_multi_var (& ctx -> ecmult_ctx , scratch , & r , & scG , ecmult_multi_callback , & data , 1 ));
2961
+ CHECK (secp256k1_ecmult_multi_var (& ctx -> ecmult_ctx , scratch , & r , & scG , ecmult_multi_callback , & data , n_points ));
2962
+ secp256k1_gej_add_var (& r , & r , & r2 , NULL );
2963
+ CHECK (secp256k1_gej_is_infinity (& r ));
2945
2964
secp256k1_scratch_destroy (scratch );
2946
2965
2947
- secp256k1_gej_neg (& r2 , & r2 );
2948
2966
for (i = 1 ; i <= n_points ; i ++ ) {
2949
2967
if (i > ECMULT_PIPPENGER_THRESHOLD ) {
2950
2968
int bucket_window = secp256k1_pippenger_bucket_window (i );
@@ -2972,7 +2990,9 @@ void run_ecmult_multi_tests(void) {
2972
2990
test_ecmult_multi (scratch , secp256k1_ecmult_multi_var );
2973
2991
test_ecmult_multi (NULL , secp256k1_ecmult_multi_var );
2974
2992
test_ecmult_multi (scratch , secp256k1_ecmult_pippenger_batch_single );
2993
+ test_ecmult_multi_batch_single (secp256k1_ecmult_pippenger_batch_single );
2975
2994
test_ecmult_multi (scratch , secp256k1_ecmult_strauss_batch_single );
2995
+ test_ecmult_multi_batch_single (secp256k1_ecmult_strauss_batch_single );
2976
2996
secp256k1_scratch_destroy (scratch );
2977
2997
2978
2998
/* Run test_ecmult_multi with space for exactly one point */
0 commit comments