7#ifndef SECP256K1_MODULE_SILENTPAYMENTS_BENCH_H
8#define SECP256K1_MODULE_SILENTPAYMENTS_BENCH_H
10#include "../../../include/secp256k1_silentpayments.h"
12#include "../../util.h"
18#define MAX_P2TR_OUTPUTS_PER_BLOCK 23250
20#define SP_BENCH_MAX_INPUTS 1
21#define SP_BENCH_MAX_OUTPUTS MAX_P2TR_OUTPUTS_PER_BLOCK
26 unsigned char scan_key[32];
34 unsigned char label[33];
35 unsigned char label_tweak[32];
40const unsigned char*
label_lookup(
const unsigned char* key,
const void* cache_ptr) {
43 return data->label_tweak;
52 0x16, 0x9e, 0x1e, 0x83, 0xe9, 0x30, 0x85, 0x33, 0x91,
53 0xbc, 0x6f, 0x35, 0xf6, 0x05, 0xc6, 0x75, 0x4c, 0xfe,
54 0xad, 0x57, 0xcf, 0x83, 0x87, 0x63, 0x9d, 0x3b, 0x40,
55 0x96, 0xc5, 0x4f, 0x18, 0xf4, 0x00, 0x00, 0x00, 0x00,
57 const unsigned char spend_pubkey[33] = {
58 0x02,0xee,0x97,0xdf,0x83,0xb2,0x54,0x6a,
59 0xf5,0xa7,0xd0,0x62,0x15,0xd9,0x8b,0xcb,
60 0x63,0x7f,0xe0,0x5d,0xd0,0xfa,0x37,0x3b,
61 0xd8,0x20,0xe6,0x64,0xd3,0x72,0xde,0x9a,0x01
63 const unsigned char scan_key[32] = {
64 0xa8,0x90,0x54,0xc9,0x5b,0xe3,0xc3,0x01,
65 0x56,0x65,0x74,0xf2,0xaa,0x93,0xad,0xe0,
66 0x51,0x85,0x09,0x03,0xa6,0x9c,0xbd,0xd1,
67 0xd4,0x7e,0xae,0x26,0x3d,0x7b,0xc0,0x31
69 unsigned char scalar[32];
71 size_t pubkeylen = 33;
73 for (i = 0; i < 32; i++) {
79 data->tx_inputs_ptrs[0] = &
data->tx_inputs[0];
81 memcpy(
data->scan_key, scan_key, 32);
91 unsigned char other_scan_seckey[32] = {99};
98 index_first_k =
data->num_outputs -
data->num_matches;
106 &labeled_spend_pubkey, &
data->spend_pubkey, &label));
113 keypairs_ptrs[0] = &input_keypair;
114 for (i = 0; i <
data->num_outputs; i++) {
115 data->tx_outputs_ptrs[i] = &
data->tx_outputs[i];
116 recipients_ptrs[i] = &recipients[i];
118 if (i >= index_first_k) {
121 unsigned char tweak[32] = {0};
128 recipients[i].
index = i;
133 for (i = 0; i <
data->num_outputs; i++) {
134 data->found_outputs_ptrs[i] = &
data->found_outputs[i];
137 for (i = 0; i <
data->num_matches / 2; i++) {
138 int pos = index_first_k + i;
140 data->tx_outputs_ptrs[pos] =
data->tx_outputs_ptrs[
data->num_outputs - i - 1];
141 data->tx_outputs_ptrs[
data->num_outputs - i - 1] = tmp;
144 free(recipients_ptrs);
153 free(
data->tx_outputs);
154 free(
data->tx_outputs_ptrs);
155 free(
data->found_outputs);
156 free(
data->found_outputs_ptrs);
162 uint32_t n_found = 0;
165 const void *label_context =
data;
169 for (i = 0; i < iters; i++) {
173 data->found_outputs_ptrs, &n_found,
175 data->scan_key, &prevouts_summary, &
data->spend_pubkey,
176 label_lookup_fn, label_context)
178 CHECK(n_found == (uint32_t)
data->num_matches);
188 if (d ||
have_flag(argc, argv,
"silentpayments") ||
have_flag(argc, argv,
"silentpayments_scan_nomatch")) {
191 for (o = 0; o <
ARRAY_SIZE(num_outputs_bench); o++) {
192 const int num_outputs = num_outputs_bench[o];
194 data.num_outputs = num_outputs;
195 data.num_matches = 0;
196 sprintf(str,
"silentpayments_scan_nomatch_N=%i", num_outputs);
198 if (iters <= 2 && num_outputs > 10) {
199 printf(
"Skipping benchmark \"%s\" due to SECP256K1_BENCH_ITERS <= 2\n", str);
206 if (d ||
have_flag(argc, argv,
"silentpayments") ||
have_flag(argc, argv,
"silentpayments_scan_worstcase")) {
208 const int num_matches_bench[] = {10, 100, 1000, 2323};
210 const int num_matches = num_matches_bench[
k];
213 data.num_matches = num_matches;
214 sprintf(str,
"silentpayments_scan_worstcase_K=%i", num_matches);
217 printf(
"Skipping benchmark \"%s\" due to SECP256K1_BENCH_ITERS <= 2\n", str);
static const PrecomputedData data
Precomputed COutPoint and CCoins values.
static void run_benchmark(char *name, void(*benchmark)(void *), void(*setup)(void *), void(*teardown)(void *), void *data, int count, int iter)
#define CHECK(cond)
Unconditional failure on condition failure.
static int tweak(const secp256k1_context *ctx, secp256k1_xonly_pubkey *agg_pk, secp256k1_musig_keyagg_cache *cache)
static int have_flag(int argc, char **argv, char *flag)
static SECP256K1_INLINE int secp256k1_memcmp_var(const void *s1, const void *s2, size_t n)
Semantics like memcmp.
SECP256K1_API void secp256k1_context_destroy(secp256k1_context *ctx) SECP256K1_ARG_NONNULL(1)
Destroy a secp256k1 context object (created in dynamically allocated memory).
SECP256K1_API secp256k1_context * secp256k1_context_create(unsigned int flags) SECP256K1_WARN_UNUSED_RESULT
Create a secp256k1 context object (in dynamically allocated memory).
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_parse(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *input, size_t inputlen) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Parse a variable-length public key into the pubkey object.
#define SECP256K1_CONTEXT_NONE
Context flags to pass to secp256k1_context_create, secp256k1_context_preallocated_size,...
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_create(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *seckey) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Compute the public key for a secret key.
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_tweak_add(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *tweak32) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Tweak a public key by adding tweak times the generator to it.
SECP256K1_API int secp256k1_silentpayments_recipient_label_serialize(const secp256k1_context *ctx, unsigned char *out33, const secp256k1_silentpayments_label *label) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Serialize a Silent Payments label.
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_silentpayments_recipient_prevouts_summary_create(const secp256k1_context *ctx, secp256k1_silentpayments_prevouts_summary *prevouts_summary, const unsigned char *outpoint_smallest36, const secp256k1_xonly_pubkey *const *xonly_pubkeys, size_t n_xonly_pubkeys, const secp256k1_pubkey *const *pubkeys, size_t n_pubkeys) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Compute Silent Payments prevouts summary from prevout public keys and transaction inputs.
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_silentpayments_sender_create_outputs(const secp256k1_context *ctx, secp256k1_xonly_pubkey **generated_outputs, const secp256k1_silentpayments_recipient **recipients, size_t n_recipients, const unsigned char *outpoint_smallest36, const secp256k1_keypair *const *keypairs, size_t n_keypairs, const unsigned char *const *seckeys, size_t n_seckeys) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(5)
Create Silent Payments outputs for recipient(s).
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_silentpayments_recipient_create_labeled_spend_pubkey(const secp256k1_context *ctx, secp256k1_pubkey *labeled_spend_pubkey, const secp256k1_pubkey *unlabeled_spend_pubkey, const secp256k1_silentpayments_label *label) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Create Silent Payments labeled spend public key.
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_silentpayments_recipient_scan_outputs(const secp256k1_context *ctx, secp256k1_silentpayments_found_output **found_outputs, uint32_t *n_found_outputs, const secp256k1_xonly_pubkey *const *tx_outputs, size_t n_tx_outputs, const unsigned char *scan_key32, const secp256k1_silentpayments_prevouts_summary *prevouts_summary, const secp256k1_pubkey *unlabeled_spend_pubkey, secp256k1_silentpayments_label_lookup label_lookup, const void *label_context) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(6) SECP256K1_ARG_NONNULL(7) SECP256K1_ARG_NONNULL(8)
Scan for Silent Payments transaction outputs.
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_silentpayments_recipient_label_create(const secp256k1_context *ctx, secp256k1_silentpayments_label *label, unsigned char *label_tweak32, const unsigned char *scan_key32, uint32_t m) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Create Silent Payments label tweak and label.
const unsigned char *(* secp256k1_silentpayments_label_lookup)(const unsigned char *label33, const void *label_context)
Type of callback function for label lookups.
static void bench_silentpayments_scan_setup(void *arg)
#define SP_BENCH_MAX_INPUTS
#define MAX_P2TR_OUTPUTS_PER_BLOCK
static void bench_silentpayments_scan(void *arg, int iters)
const unsigned char * label_lookup(const unsigned char *key, const void *cache_ptr)
static void bench_silentpayments_scan_teardown(void *arg, int iters)
#define SP_BENCH_MAX_OUTPUTS
static void run_silentpayments_bench(int iters, int argc, char **argv)
static unsigned char smallest_outpoint[36]
secp256k1_silentpayments_found_output ** found_outputs_ptrs
secp256k1_pubkey spend_pubkey
secp256k1_silentpayments_found_output * found_outputs
secp256k1_xonly_pubkey ** tx_outputs_ptrs
secp256k1_xonly_pubkey * tx_outputs
Opaque data structure that holds a keypair consisting of a secret and a public key.
Opaque data structure that holds a parsed and valid public key.
Opaque data structure that holds a Silent Payments label.
Opaque data structure that holds Silent Payments prevouts summary data.
The data from a single recipient address.
secp256k1_pubkey scan_pubkey
secp256k1_pubkey spend_pubkey
Opaque data structure that holds a parsed and valid "x-only" public key.