@@ -2649,7 +2649,6 @@ void test_ecmult_multi(secp256k1_scratch *scratch, secp256k1_ecmult_multi_func e
26492649 secp256k1_gej r ;
26502650 secp256k1_gej r2 ;
26512651 ecmult_multi_data data ;
2652- secp256k1_scratch * scratch_empty ;
26532652
26542653 data .sc = sc ;
26552654 data .pt = pt ;
@@ -2684,11 +2683,6 @@ void test_ecmult_multi(secp256k1_scratch *scratch, secp256k1_ecmult_multi_func e
26842683 secp256k1_gej_add_var (& r , & r , & r2 , NULL );
26852684 CHECK (secp256k1_gej_is_infinity (& r ));
26862685
2687- /* Try to multiply 1 point, but scratch space is empty */
2688- scratch_empty = secp256k1_scratch_create (& ctx -> error_callback , 0 );
2689- CHECK (!ecmult_multi (& ctx -> ecmult_ctx , scratch_empty , & r , & szero , ecmult_multi_callback , & data , 1 ));
2690- secp256k1_scratch_destroy (scratch_empty );
2691-
26922686 /* Try to multiply 1 point, but callback returns false */
26932687 CHECK (!ecmult_multi (& ctx -> ecmult_ctx , scratch , & r , & szero , ecmult_multi_false_callback , & data , 1 ));
26942688
@@ -2886,6 +2880,24 @@ void test_ecmult_multi(secp256k1_scratch *scratch, secp256k1_ecmult_multi_func e
28862880 }
28872881}
28882882
2883+ void test_ecmult_multi_batch_single (secp256k1_ecmult_multi_func ecmult_multi ) {
2884+ secp256k1_scalar szero ;
2885+ secp256k1_scalar sc [32 ];
2886+ secp256k1_ge pt [32 ];
2887+ secp256k1_gej r ;
2888+ ecmult_multi_data data ;
2889+ secp256k1_scratch * scratch_empty ;
2890+
2891+ data .sc = sc ;
2892+ data .pt = pt ;
2893+ secp256k1_scalar_set_int (& szero , 0 );
2894+
2895+ /* Try to multiply 1 point, but scratch space is empty.*/
2896+ scratch_empty = secp256k1_scratch_create (& ctx -> error_callback , 0 );
2897+ CHECK (!ecmult_multi (& ctx -> ecmult_ctx , scratch_empty , & r , & szero , ecmult_multi_callback , & data , 1 ));
2898+ secp256k1_scratch_destroy (scratch_empty );
2899+ }
2900+
28892901void test_secp256k1_pippenger_bucket_window_inv (void ) {
28902902 int i ;
28912903
@@ -3009,19 +3021,25 @@ void test_ecmult_multi_batching(void) {
30093021 }
30103022 data .sc = sc ;
30113023 data .pt = pt ;
3024+ secp256k1_gej_neg (& r2 , & r2 );
30123025
3013- /* Test with empty scratch space */
3026+ /* Test with empty scratch space. It should compute the correct result using
3027+ * ecmult_mult_simple algorithm which doesn't require a scratch space. */
30143028 scratch = secp256k1_scratch_create (& ctx -> error_callback , 0 );
3015- CHECK (!secp256k1_ecmult_multi_var (& ctx -> ecmult_ctx , scratch , & r , & scG , ecmult_multi_callback , & data , 1 ));
3029+ CHECK (secp256k1_ecmult_multi_var (& ctx -> ecmult_ctx , scratch , & r , & scG , ecmult_multi_callback , & data , n_points ));
3030+ secp256k1_gej_add_var (& r , & r , & r2 , NULL );
3031+ CHECK (secp256k1_gej_is_infinity (& r ));
30163032 secp256k1_scratch_destroy (scratch );
30173033
30183034 /* Test with space for 1 point in pippenger. That's not enough because
3019- * ecmult_multi selects strauss which requires more memory. */
3035+ * ecmult_multi selects strauss which requires more memory. It should
3036+ * therefore select the simple algorithm. */
30203037 scratch = secp256k1_scratch_create (& ctx -> error_callback , secp256k1_pippenger_scratch_size (1 , 1 ) + PIPPENGER_SCRATCH_OBJECTS * ALIGNMENT );
3021- CHECK (!secp256k1_ecmult_multi_var (& ctx -> ecmult_ctx , scratch , & r , & scG , ecmult_multi_callback , & data , 1 ));
3038+ CHECK (secp256k1_ecmult_multi_var (& ctx -> ecmult_ctx , scratch , & r , & scG , ecmult_multi_callback , & data , n_points ));
3039+ secp256k1_gej_add_var (& r , & r , & r2 , NULL );
3040+ CHECK (secp256k1_gej_is_infinity (& r ));
30223041 secp256k1_scratch_destroy (scratch );
30233042
3024- secp256k1_gej_neg (& r2 , & r2 );
30253043 for (i = 1 ; i <= n_points ; i ++ ) {
30263044 if (i > ECMULT_PIPPENGER_THRESHOLD ) {
30273045 int bucket_window = secp256k1_pippenger_bucket_window (i );
@@ -3049,7 +3067,9 @@ void run_ecmult_multi_tests(void) {
30493067 test_ecmult_multi (scratch , secp256k1_ecmult_multi_var );
30503068 test_ecmult_multi (NULL , secp256k1_ecmult_multi_var );
30513069 test_ecmult_multi (scratch , secp256k1_ecmult_pippenger_batch_single );
3070+ test_ecmult_multi_batch_single (secp256k1_ecmult_pippenger_batch_single );
30523071 test_ecmult_multi (scratch , secp256k1_ecmult_strauss_batch_single );
3072+ test_ecmult_multi_batch_single (secp256k1_ecmult_strauss_batch_single );
30533073 secp256k1_scratch_destroy (scratch );
30543074
30553075 /* Run test_ecmult_multi with space for exactly one point */
0 commit comments