Skip to content

Commit f14900b

Browse files
josibakel0rinc
andcommitted
bench: add benchmark for signing with a taptweak
Add benchmarks for signing with null and non-null merkle_root arguments. Null and non-null merkle_root arguments will apply the taptweaks H_TapTweak(P) and H_TapTweak(P | merkle_root), respectively, to the private key during signing. This benchmark is added to verify there are no significant performance changes after moving the taptweak signing logic in a later commit. Co-authored-by: l0rinc <[email protected]>
1 parent 8d57361 commit f14900b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/bench/sign_transaction.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <script/script.h>
1313
#include <script/sign.h>
1414
#include <uint256.h>
15+
#include <test/util/random.h>
1516
#include <util/translation.h>
1617

1718
enum class InputType {
@@ -66,5 +67,33 @@ static void SignTransactionSingleInput(benchmark::Bench& bench, InputType input_
6667
static void SignTransactionECDSA(benchmark::Bench& bench) { SignTransactionSingleInput(bench, InputType::P2WPKH); }
6768
static void SignTransactionSchnorr(benchmark::Bench& bench) { SignTransactionSingleInput(bench, InputType::P2TR); }
6869

70+
static void SignSchnorrTapTweakBenchmark(benchmark::Bench& bench, bool use_null_merkle_root)
71+
{
72+
ECC_Context ecc_context{};
73+
74+
auto key = GenerateRandomKey();
75+
auto msg = InsecureRand256();
76+
auto merkle_root = use_null_merkle_root ? uint256() : InsecureRand256();
77+
auto aux = InsecureRand256();
78+
std::vector<unsigned char> sig(64);
79+
80+
bench.minEpochIterations(100).run([&] {
81+
bool success = key.SignSchnorr(msg, sig, &merkle_root, aux);
82+
assert(success);
83+
});
84+
}
85+
86+
static void SignSchnorrWithMerkleRoot(benchmark::Bench& bench)
87+
{
88+
SignSchnorrTapTweakBenchmark(bench, /*use_null_merkle_root=*/false);
89+
}
90+
91+
static void SignSchnorrWithNullMerkleRoot(benchmark::Bench& bench)
92+
{
93+
SignSchnorrTapTweakBenchmark(bench, /*use_null_merkle_root=*/true);
94+
}
95+
6996
BENCHMARK(SignTransactionECDSA, benchmark::PriorityLevel::HIGH);
7097
BENCHMARK(SignTransactionSchnorr, benchmark::PriorityLevel::HIGH);
98+
BENCHMARK(SignSchnorrWithMerkleRoot, benchmark::PriorityLevel::HIGH);
99+
BENCHMARK(SignSchnorrWithNullMerkleRoot, benchmark::PriorityLevel::HIGH);

0 commit comments

Comments
 (0)