Skip to content

Commit de6af6a

Browse files
Merge #1748: bench: improve context creation in ECDH benchmark
dfe284e bench: improve context creation in ECDH benchmark (Sebastian Falbesoner) Pull request description: Calling `secp256k1_context_create` with `SECP256K1_FLAGS_TYPE_CONTEXT` seems to be confusing and not strictly API-compliant, as the only allowed (non-deprecated) value is `SECP256K1_CONTEXT_NONE`, even if the former happens to map to the latter currently. Fix this by not dynamically creating a context in the first place and switch to using the static context, as it is sufficient for this benchmark and presumably matches what the "no capabilities" comment intended back then. Alternatives are: * keep the signing context and only fix the name, i.e. s/_FLAGS_TYPE_CONTEXT/_CONTEXT_NONE/ * use `secp256k1_context_static` everywhere directly and get rid of the `ctx` field in the `bench_ecdh_data` struct (less flexible for future changes, deviates from other bench structures) Found while reviewing #1698, see #1698 (comment). ACKs for top commit: sipa: utACK dfe284e stratospher: ACK dfe284e. not sure whether the alternative is preferred though. real-or-random: utACK dfe284e furszy: ACK dfe284e Tree-SHA512: 106d115ec11577fcd66e93293289545aa0fa78480f4bdc8c440963e4e6b050c81d4775268cfa0e1ab44db4c08a5768a0ff80f74b866e550ddd22a4e17ccb9014
2 parents 5817885 + dfe284e commit de6af6a

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/modules/ecdh/bench_impl.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "../../../include/secp256k1_ecdh.h"
1111

1212
typedef struct {
13-
secp256k1_context *ctx;
13+
const secp256k1_context *ctx;
1414
secp256k1_pubkey point;
1515
unsigned char scalar[32];
1616
} bench_ecdh_data;
@@ -46,12 +46,9 @@ static void run_ecdh_bench(int iters, int argc, char** argv) {
4646
bench_ecdh_data data;
4747
int d = argc == 1;
4848

49-
/* create a context with no capabilities */
50-
data.ctx = secp256k1_context_create(SECP256K1_FLAGS_TYPE_CONTEXT);
49+
data.ctx = secp256k1_context_static;
5150

5251
if (d || have_flag(argc, argv, "ecdh")) run_benchmark("ecdh", bench_ecdh, bench_ecdh_setup, NULL, &data, 10, iters);
53-
54-
secp256k1_context_destroy(data.ctx);
5552
}
5653

5754
#endif /* SECP256K1_MODULE_ECDH_BENCH_H */

0 commit comments

Comments
 (0)