From cb0252c491445bf6fbe1935bd9ae254793aae4b4 Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Thu, 4 Dec 2025 03:21:45 +0100 Subject: [PATCH] compute base output key using `secp256k1_ec_pubkey_tweak_add` Calculating P_k = B_spend + t_k * G can be done in one shot using the function for additive pubkey tweaking (-> tweak B_spend with t_k), which is simpler and should also be slightly faster than multiplying and adding up successively. --- src/secp256k1_extension.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/secp256k1_extension.cpp b/src/secp256k1_extension.cpp index 9956d9b..66d7680 100644 --- a/src/secp256k1_extension.cpp +++ b/src/secp256k1_extension.cpp @@ -622,17 +622,9 @@ inline void ScanSilentPaymentsScalarFun(DataChunk &args, ExpressionState &state, return false; } - // Create public key from base shared secret - secp256k1_pubkey base_shared_pubkey; - if (secp256k1_ec_pubkey_create(ctx, &base_shared_pubkey, base_shared_secret) != 1) { - mask.SetInvalid(idx); - return false; - } - - // Combine with spend public key to get base output key - const secp256k1_pubkey *base_pubkeys[2] = {&spend_pubkey, &base_shared_pubkey}; - secp256k1_pubkey base_output_key; - if (secp256k1_ec_pubkey_combine(ctx, &base_output_key, base_pubkeys, 2) != 1) { + // Get base output key by tweaking spend public key with base shared secret + secp256k1_pubkey base_output_key = spend_pubkey; + if (secp256k1_ec_pubkey_tweak_add(ctx, &base_output_key, base_shared_secret) != 1) { mask.SetInvalid(idx); return false; }