mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-26 11:13:23 -03:00
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 <pap.lorinc@gmail.com>
This commit is contained in:
parent
8d57361157
commit
f14900b6e4
1 changed files with 29 additions and 0 deletions
|
@ -12,6 +12,7 @@
|
||||||
#include <script/script.h>
|
#include <script/script.h>
|
||||||
#include <script/sign.h>
|
#include <script/sign.h>
|
||||||
#include <uint256.h>
|
#include <uint256.h>
|
||||||
|
#include <test/util/random.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
|
|
||||||
enum class InputType {
|
enum class InputType {
|
||||||
|
@ -66,5 +67,33 @@ static void SignTransactionSingleInput(benchmark::Bench& bench, InputType input_
|
||||||
static void SignTransactionECDSA(benchmark::Bench& bench) { SignTransactionSingleInput(bench, InputType::P2WPKH); }
|
static void SignTransactionECDSA(benchmark::Bench& bench) { SignTransactionSingleInput(bench, InputType::P2WPKH); }
|
||||||
static void SignTransactionSchnorr(benchmark::Bench& bench) { SignTransactionSingleInput(bench, InputType::P2TR); }
|
static void SignTransactionSchnorr(benchmark::Bench& bench) { SignTransactionSingleInput(bench, InputType::P2TR); }
|
||||||
|
|
||||||
|
static void SignSchnorrTapTweakBenchmark(benchmark::Bench& bench, bool use_null_merkle_root)
|
||||||
|
{
|
||||||
|
ECC_Context ecc_context{};
|
||||||
|
|
||||||
|
auto key = GenerateRandomKey();
|
||||||
|
auto msg = InsecureRand256();
|
||||||
|
auto merkle_root = use_null_merkle_root ? uint256() : InsecureRand256();
|
||||||
|
auto aux = InsecureRand256();
|
||||||
|
std::vector<unsigned char> sig(64);
|
||||||
|
|
||||||
|
bench.minEpochIterations(100).run([&] {
|
||||||
|
bool success = key.SignSchnorr(msg, sig, &merkle_root, aux);
|
||||||
|
assert(success);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static void SignSchnorrWithMerkleRoot(benchmark::Bench& bench)
|
||||||
|
{
|
||||||
|
SignSchnorrTapTweakBenchmark(bench, /*use_null_merkle_root=*/false);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void SignSchnorrWithNullMerkleRoot(benchmark::Bench& bench)
|
||||||
|
{
|
||||||
|
SignSchnorrTapTweakBenchmark(bench, /*use_null_merkle_root=*/true);
|
||||||
|
}
|
||||||
|
|
||||||
BENCHMARK(SignTransactionECDSA, benchmark::PriorityLevel::HIGH);
|
BENCHMARK(SignTransactionECDSA, benchmark::PriorityLevel::HIGH);
|
||||||
BENCHMARK(SignTransactionSchnorr, benchmark::PriorityLevel::HIGH);
|
BENCHMARK(SignTransactionSchnorr, benchmark::PriorityLevel::HIGH);
|
||||||
|
BENCHMARK(SignSchnorrWithMerkleRoot, benchmark::PriorityLevel::HIGH);
|
||||||
|
BENCHMARK(SignSchnorrWithNullMerkleRoot, benchmark::PriorityLevel::HIGH);
|
||||||
|
|
Loading…
Add table
Reference in a new issue