Skip to content

Commit f64306a

Browse files
committed
eckey: speed up _pubkey_tweak_add by using ecmult_gen_var
Rather than using the generic double multiply (with na=1), use the newly introduced fast variable-time generator point multiplication and add it up to the base public key manually. On arm64, this improves the performance of the `secp256k1_ec_pubkey_tweak_add` API function by about 80%: ----- Before (prior this commit): ----- ``` $ ./build/bin/bench tweak Benchmark , Min(us) , Avg(us) , Max(us) ec_pk_tweak_add , 16.1 , 16.2 , 16.6 ``` ----- After (this commit): ----- ``` $ ./build/bin/bench tweak Benchmark , Min(us) , Avg(us) , Max(us) ec_pk_tweak_add , 8.94 , 8.98 , 9.29 ``` Note that the following API functions also benefit from the improved code path: - secp256k1_xonly_pubkey_tweak_add - secp256k1_xonly_pubkey_tweak_add_check (this one is consensus-critical for P2TR script path spends, see BIP341) - secp256k1_keypair_xonly_tweak_add - secp256k1_musig_pubkey_ec_tweak_add - secp256k1_musig_pubkey_xonly_tweak_add
1 parent 8de10c7 commit f64306a

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/eckey_impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ static int secp256k1_eckey_privkey_tweak_add(secp256k1_scalar *key, const secp25
6161

6262
static int secp256k1_eckey_pubkey_tweak_add(secp256k1_ge *key, const secp256k1_scalar *tweak) {
6363
secp256k1_gej pt;
64-
secp256k1_gej_set_ge(&pt, key);
65-
secp256k1_ecmult(&pt, &pt, &secp256k1_scalar_one, tweak);
64+
secp256k1_ecmult_gen_var(&pt, tweak);
65+
secp256k1_gej_add_ge_var(&pt, &pt, key, NULL);
6666

6767
if (secp256k1_gej_is_infinity(&pt)) {
6868
return 0;

0 commit comments

Comments
 (0)