|
| 1 | +// Copyright (c) 2025 The Bitcoin Core developers |
| 2 | +// Distributed under the MIT software license, see the accompanying |
| 3 | +// file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 4 | + |
| 5 | +#include <bench/bench.h> |
| 6 | +#include <pubkey.h> |
| 7 | +#include <script/interpreter.h> |
| 8 | +#include <script/script.h> |
| 9 | + |
| 10 | +typedef std::vector<unsigned char> valtype; |
| 11 | + |
| 12 | +static void DoubleTweak(benchmark::Bench& bench) |
| 13 | +{ |
| 14 | + const XOnlyPubKey naked_key{ParseHex( |
| 15 | + "50929B74C1A04954B78B4B6035E97A5E078A5A0F28EC96D547BFEE9ACE803AC0")}; |
| 16 | + |
| 17 | + const std::vector<unsigned char> data(MAX_SCRIPT_ELEMENT_SIZE, 0x42); |
| 18 | + |
| 19 | + const uint256 merkle_root{ParseHex( |
| 20 | + "E79925EF2A0DF8D2C0C08BFA7474D016384C5FC64C51EFC5E950AA1A97B88B61")}; |
| 21 | + |
| 22 | + const XOnlyPubKey result_key{ParseHex( |
| 23 | + "F2DFC709E477C8D73A3625BC05C370B196703E466EB8655977FF69807EEF8F0E")}; |
| 24 | + |
| 25 | + bench.unit("ccv_doubletweak").run([&] { |
| 26 | + bool ret = result_key.CheckDoubleTweak(naked_key, data, &merkle_root); |
| 27 | + assert(ret); |
| 28 | + }); |
| 29 | + |
| 30 | + const XOnlyPubKey schnorr_key{ParseHex( |
| 31 | + "F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9")}; |
| 32 | + const valtype msg{ParseHex( |
| 33 | + "0000000000000000000000000000000000000000000000000000000000000000")}; |
| 34 | + const valtype sig{ParseHex( |
| 35 | + "E907831F80848D1069A5371B402410364BDF1C5F8307B0084C55F1CE2DCA821525F66A4A85EA8B71E482A74F382D2CE5EBEEE8FDB2172F477DF4900D310536C0")}; |
| 36 | + |
| 37 | + bench.unit("verify").run("schnorr-good-verify", [&] { |
| 38 | + auto ret = schnorr_key.VerifySchnorr(uint256(msg), sig); |
| 39 | + assert(ret); |
| 40 | + }); |
| 41 | +} |
| 42 | + |
| 43 | + |
| 44 | +BENCHMARK(DoubleTweak, benchmark::PriorityLevel::HIGH); |
0 commit comments