Skip to content

Commit b1bab69

Browse files
committed
Merge #81: Update vendored version of secp256k1-zkp
c1feb16 add CHANGELOG entries for 0.11.0 (Andrew Poelstra) 53d2ec6 update libsecp-zkp to 6152622613fdf1c5af6f31f74c427c4e9ee120ce (Andrew Poelstra) e0b45ac secp256k1-zkp-sys: redo patch files for latest upstream (Andrew Poelstra) Pull request description: ACKs for top commit: jonasnick: ACK c1feb16 Tree-SHA512: d241f333d2e1a0add3deb866d8428c14f29c246c66bfeb043f81aa896c99d85774377719a567b364575a90a96a6722cfb3d8016147e7943cddce149a9b62dbab
2 parents 8733740 + c1feb16 commit b1bab69

File tree

234 files changed

+28986
-17145
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

234 files changed

+28986
-17145
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.11.0 - 2024-07-09
2+
3+
- Update upstream to 6152622613fdf1c5af6f31f74c427c4e9ee120ce
4+
15
# 0.10.1 - 2024-01-10
26

37
- Fix compilation when `cfg(fuzzing)` is set

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "secp256k1-zkp"
3-
version = "0.10.1"
3+
version = "0.11.0"
44
authors = [ "Dawid Ciężarkiewicz <[email protected]>",
55
"Andrew Poelstra <[email protected]>",
66
"Lucas Soriano <[email protected]>",
@@ -34,7 +34,7 @@ rand = ["actual-rand", "secp256k1/rand"]
3434
actual-serde = { package = "serde", version = "1.0", default-features = false, optional = true }
3535
actual-rand = { package = "rand", version = "0.8", default-features = false, optional = true }
3636
secp256k1 = "0.29.0"
37-
secp256k1-zkp-sys = { version = "0.9.0", default-features = false, path = "./secp256k1-zkp-sys" }
37+
secp256k1-zkp-sys = { version = "0.10.0", default-features = false, path = "./secp256k1-zkp-sys" }
3838
internals = { package = "bitcoin-private", version = "0.1.0" }
3939

4040
[dev-dependencies]

secp256k1-zkp-sys/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.10.0 - 2024-07-09
2+
3+
- Update upstream to 6152622613fdf1c5af6f31f74c427c4e9ee120ce
4+
15
# 0.9.1 - 2023-01-03
26

37
- Many changes; restart CHANGELOG.

secp256k1-zkp-sys/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "secp256k1-zkp-sys"
3-
version = "0.9.1"
3+
version = "0.10.0"
44
authors = [ "Dawid Ciężarkiewicz <[email protected]>",
55
"Andrew Poelstra <[email protected]>",
66
"Steven Roose <[email protected]>",
@@ -13,7 +13,7 @@ description = "FFI for `libsecp256k1-zkp` library."
1313
keywords = [ "secp256k1", "libsecp256k1-zkp", "ffi" ]
1414
readme = "README.md"
1515
build = "build.rs"
16-
links = "rustsecp256k1zkp_v0_8_0"
16+
links = "rustsecp256k1zkp_v0_10_0"
1717

1818
# Should make docs.rs show all functions, even those behind non-default features
1919
[package.metadata.docs.rs]
+36-26
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
1-
13,37d12
2-
< static secp256k1_scratch* secp256k1_scratch_create(const secp256k1_callback* error_callback, size_t size) {
3-
< const size_t base_alloc = ROUND_TO_ALIGN(sizeof(secp256k1_scratch));
4-
< void *alloc = checked_malloc(error_callback, base_alloc + size);
5-
< secp256k1_scratch* ret = (secp256k1_scratch *)alloc;
6-
< if (ret != NULL) {
7-
< memset(ret, 0, sizeof(*ret));
8-
< memcpy(ret->magic, "scratch", 8);
9-
< ret->data = (void *) ((char *) alloc + base_alloc);
10-
< ret->max_size = size;
11-
< }
12-
< return ret;
13-
< }
14-
<
15-
< static void secp256k1_scratch_destroy(const secp256k1_callback* error_callback, secp256k1_scratch* scratch) {
16-
< if (scratch != NULL) {
17-
< VERIFY_CHECK(scratch->alloc_size == 0); /* all checkpoints should be applied */
18-
< if (secp256k1_memcmp_var(scratch->magic, "scratch", 8) != 0) {
19-
< secp256k1_callback_call(error_callback, "invalid scratch space");
20-
< return;
21-
< }
22-
< memset(scratch->magic, 0, sizeof(scratch->magic));
23-
< free(scratch);
24-
< }
25-
< }
26-
<
1+
diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/scratch_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/scratch_impl.h
2+
index f71a20b..5389571 100644
3+
--- a/secp256k1-zkp-sys/depend/secp256k1/src/scratch_impl.h
4+
+++ b/secp256k1-zkp-sys/depend/secp256k1/src/scratch_impl.h
5+
@@ -10,31 +10,6 @@
6+
#include "util.h"
7+
#include "scratch.h"
8+
9+
-static secp256k1_scratch* secp256k1_scratch_create(const secp256k1_callback* error_callback, size_t size) {
10+
- const size_t base_alloc = ROUND_TO_ALIGN(sizeof(secp256k1_scratch));
11+
- void *alloc = checked_malloc(error_callback, base_alloc + size);
12+
- secp256k1_scratch* ret = (secp256k1_scratch *)alloc;
13+
- if (ret != NULL) {
14+
- memset(ret, 0, sizeof(*ret));
15+
- memcpy(ret->magic, "scratch", 8);
16+
- ret->data = (void *) ((char *) alloc + base_alloc);
17+
- ret->max_size = size;
18+
- }
19+
- return ret;
20+
-}
21+
-
22+
-static void secp256k1_scratch_destroy(const secp256k1_callback* error_callback, secp256k1_scratch* scratch) {
23+
- if (scratch != NULL) {
24+
- if (secp256k1_memcmp_var(scratch->magic, "scratch", 8) != 0) {
25+
- secp256k1_callback_call(error_callback, "invalid scratch space");
26+
- return;
27+
- }
28+
- VERIFY_CHECK(scratch->alloc_size == 0); /* all checkpoints should be applied */
29+
- memset(scratch->magic, 0, sizeof(scratch->magic));
30+
- free(scratch);
31+
- }
32+
-}
33+
-
34+
static size_t secp256k1_scratch_checkpoint(const secp256k1_callback* error_callback, const secp256k1_scratch* scratch) {
35+
if (secp256k1_memcmp_var(scratch->magic, "scratch", 8) != 0) {
36+
secp256k1_callback_call(error_callback, "invalid scratch space");
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# This file was automatically created by vendor-libsecp.sh
2-
1d256089004a19bdbead7c5676e52c8e07b09fce
2+
6152622613fdf1c5af6f31f74c427c4e9ee120ce
+78-43
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,78 @@
1-
139,149d138
2-
< secp256k1_context* secp256k1_context_create(unsigned int flags) {
3-
< size_t const prealloc_size = secp256k1_context_preallocated_size(flags);
4-
< secp256k1_context* ctx = (secp256k1_context*)checked_malloc(&default_error_callback, prealloc_size);
5-
< if (EXPECT(secp256k1_context_preallocated_create(ctx, flags) == NULL, 0)) {
6-
< free(ctx);
7-
< return NULL;
8-
< }
9-
<
10-
< return ctx;
11-
< }
12-
<
13-
164,174d152
14-
< secp256k1_context* secp256k1_context_clone(const secp256k1_context* ctx) {
15-
< secp256k1_context* ret;
16-
< size_t prealloc_size;
17-
<
18-
< VERIFY_CHECK(ctx != NULL);
19-
< prealloc_size = secp256k1_context_preallocated_clone_size(ctx);
20-
< ret = (secp256k1_context*)checked_malloc(&ctx->error_callback, prealloc_size);
21-
< ret = secp256k1_context_preallocated_clone(ctx, ret);
22-
< return ret;
23-
< }
24-
<
25-
183,189d160
26-
< void secp256k1_context_destroy(secp256k1_context* ctx) {
27-
< if (ctx != NULL) {
28-
< secp256k1_context_preallocated_destroy(ctx);
29-
< free(ctx);
30-
< }
31-
< }
32-
<
33-
206,215d176
34-
< }
35-
<
36-
< secp256k1_scratch_space* secp256k1_scratch_space_create(const secp256k1_context* ctx, size_t max_size) {
37-
< VERIFY_CHECK(ctx != NULL);
38-
< return secp256k1_scratch_create(&ctx->error_callback, max_size);
39-
< }
40-
<
41-
< void secp256k1_scratch_space_destroy(const secp256k1_context *ctx, secp256k1_scratch_space* scratch) {
42-
< VERIFY_CHECK(ctx != NULL);
43-
< secp256k1_scratch_destroy(&ctx->error_callback, scratch);
1+
diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/secp256k1.c b/secp256k1-zkp-sys/depend/secp256k1/src/secp256k1.c
2+
index 4c57826..dacaed2 100644
3+
--- a/secp256k1-zkp-sys/depend/secp256k1/src/secp256k1.c
4+
+++ b/secp256k1-zkp-sys/depend/secp256k1/src/secp256k1.c
5+
@@ -158,17 +158,6 @@ secp256k1_context* secp256k1_context_preallocated_create(void* prealloc, unsigne
6+
return ret;
7+
}
8+
9+
-secp256k1_context* secp256k1_context_create(unsigned int flags) {
10+
- size_t const prealloc_size = secp256k1_context_preallocated_size(flags);
11+
- secp256k1_context* ctx = (secp256k1_context*)checked_malloc(&default_error_callback, prealloc_size);
12+
- if (EXPECT(secp256k1_context_preallocated_create(ctx, flags) == NULL, 0)) {
13+
- free(ctx);
14+
- return NULL;
15+
- }
16+
-
17+
- return ctx;
18+
-}
19+
-
20+
secp256k1_context* secp256k1_context_preallocated_clone(const secp256k1_context* ctx, void* prealloc) {
21+
secp256k1_context* ret;
22+
VERIFY_CHECK(ctx != NULL);
23+
@@ -180,19 +169,6 @@ secp256k1_context* secp256k1_context_preallocated_clone(const secp256k1_context*
24+
return ret;
25+
}
26+
27+
-secp256k1_context* secp256k1_context_clone(const secp256k1_context* ctx) {
28+
- secp256k1_context* ret;
29+
- size_t prealloc_size;
30+
-
31+
- VERIFY_CHECK(ctx != NULL);
32+
- ARG_CHECK(secp256k1_context_is_proper(ctx));
33+
-
34+
- prealloc_size = secp256k1_context_preallocated_clone_size(ctx);
35+
- ret = (secp256k1_context*)checked_malloc(&ctx->error_callback, prealloc_size);
36+
- ret = secp256k1_context_preallocated_clone(ctx, ret);
37+
- return ret;
38+
-}
39+
-
40+
void secp256k1_context_preallocated_destroy(secp256k1_context* ctx) {
41+
ARG_CHECK_VOID(ctx == NULL || secp256k1_context_is_proper(ctx));
42+
43+
@@ -204,18 +180,6 @@ void secp256k1_context_preallocated_destroy(secp256k1_context* ctx) {
44+
secp256k1_ecmult_gen_context_clear(&ctx->ecmult_gen_ctx);
45+
}
46+
47+
-void secp256k1_context_destroy(secp256k1_context* ctx) {
48+
- ARG_CHECK_VOID(ctx == NULL || secp256k1_context_is_proper(ctx));
49+
-
50+
- /* Defined as noop */
51+
- if (ctx == NULL) {
52+
- return;
53+
- }
54+
-
55+
- secp256k1_context_preallocated_destroy(ctx);
56+
- free(ctx);
57+
-}
58+
-
59+
void secp256k1_context_set_illegal_callback(secp256k1_context* ctx, void (*fun)(const char* message, void* data), const void* data) {
60+
/* We compare pointers instead of checking secp256k1_context_is_proper() here
61+
because setting callbacks is allowed on *copies* of the static context:
62+
@@ -240,16 +204,6 @@ void secp256k1_context_set_error_callback(secp256k1_context* ctx, void (*fun)(co
63+
ctx->error_callback.data = data;
64+
}
65+
66+
-secp256k1_scratch_space* secp256k1_scratch_space_create(const secp256k1_context* ctx, size_t max_size) {
67+
- VERIFY_CHECK(ctx != NULL);
68+
- return secp256k1_scratch_create(&ctx->error_callback, max_size);
69+
-}
70+
-
71+
-void secp256k1_scratch_space_destroy(const secp256k1_context *ctx, secp256k1_scratch_space* scratch) {
72+
- VERIFY_CHECK(ctx != NULL);
73+
- secp256k1_scratch_destroy(&ctx->error_callback, scratch);
74+
-}
75+
-
76+
/* Mark memory as no-longer-secret for the purpose of analysing constant-time behaviour
77+
* of the software.
78+
*/
+105-22
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,105 @@
1-
226,228d225
2-
< SECP256K1_API secp256k1_context* secp256k1_context_create(
3-
< unsigned int flags
4-
< ) SECP256K1_WARN_UNUSED_RESULT;
5-
231,233d227
6-
< SECP256K1_API secp256k1_context* secp256k1_context_clone(
7-
< const secp256k1_context* ctx
8-
< ) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT;
9-
248,250d241
10-
< SECP256K1_API void secp256k1_context_destroy(
11-
< secp256k1_context* ctx
12-
< ) SECP256K1_ARG_NONNULL(1);
13-
327,330d317
14-
< SECP256K1_API SECP256K1_WARN_UNUSED_RESULT secp256k1_scratch_space* secp256k1_scratch_space_create(
15-
< const secp256k1_context* ctx,
16-
< size_t size
17-
< ) SECP256K1_ARG_NONNULL(1);
18-
338,341d324
19-
< SECP256K1_API void secp256k1_scratch_space_destroy(
20-
< const secp256k1_context* ctx,
21-
< secp256k1_scratch_space* scratch
22-
< ) SECP256K1_ARG_NONNULL(1);
1+
diff --git a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1.h b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1.h
2+
index f4053f2..aa2d18b 100644
3+
--- a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1.h
4+
+++ b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1.h
5+
@@ -257,70 +257,6 @@ SECP256K1_DEPRECATED("Use secp256k1_context_static instead");
6+
*/
7+
SECP256K1_API void secp256k1_selftest(void);
8+
9+
-
10+
-/** Create a secp256k1 context object (in dynamically allocated memory).
11+
- *
12+
- * This function uses malloc to allocate memory. It is guaranteed that malloc is
13+
- * called at most once for every call of this function. If you need to avoid dynamic
14+
- * memory allocation entirely, see secp256k1_context_static and the functions in
15+
- * secp256k1_preallocated.h.
16+
- *
17+
- * Returns: pointer to a newly created context object.
18+
- * In: flags: Always set to SECP256K1_CONTEXT_NONE (see below).
19+
- *
20+
- * The only valid non-deprecated flag in recent library versions is
21+
- * SECP256K1_CONTEXT_NONE, which will create a context sufficient for all functionality
22+
- * offered by the library. All other (deprecated) flags will be treated as equivalent
23+
- * to the SECP256K1_CONTEXT_NONE flag. Though the flags parameter primarily exists for
24+
- * historical reasons, future versions of the library may introduce new flags.
25+
- *
26+
- * If the context is intended to be used for API functions that perform computations
27+
- * involving secret keys, e.g., signing and public key generation, then it is highly
28+
- * recommended to call secp256k1_context_randomize on the context before calling
29+
- * those API functions. This will provide enhanced protection against side-channel
30+
- * leakage, see secp256k1_context_randomize for details.
31+
- *
32+
- * Do not create a new context object for each operation, as construction and
33+
- * randomization can take non-negligible time.
34+
- */
35+
-SECP256K1_API secp256k1_context *secp256k1_context_create(
36+
- unsigned int flags
37+
-) SECP256K1_WARN_UNUSED_RESULT;
38+
-
39+
-/** Copy a secp256k1 context object (into dynamically allocated memory).
40+
- *
41+
- * This function uses malloc to allocate memory. It is guaranteed that malloc is
42+
- * called at most once for every call of this function. If you need to avoid dynamic
43+
- * memory allocation entirely, see the functions in secp256k1_preallocated.h.
44+
- *
45+
- * Cloning secp256k1_context_static is not possible, and should not be emulated by
46+
- * the caller (e.g., using memcpy). Create a new context instead.
47+
- *
48+
- * Returns: pointer to a newly created context object.
49+
- * Args: ctx: pointer to a context to copy (not secp256k1_context_static).
50+
- */
51+
-SECP256K1_API secp256k1_context *secp256k1_context_clone(
52+
- const secp256k1_context *ctx
53+
-) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT;
54+
-
55+
-/** Destroy a secp256k1 context object (created in dynamically allocated memory).
56+
- *
57+
- * The context pointer may not be used afterwards.
58+
- *
59+
- * The context to destroy must have been created using secp256k1_context_create
60+
- * or secp256k1_context_clone. If the context has instead been created using
61+
- * secp256k1_context_preallocated_create or secp256k1_context_preallocated_clone, the
62+
- * behaviour is undefined. In that case, secp256k1_context_preallocated_destroy must
63+
- * be used instead.
64+
- *
65+
- * Args: ctx: pointer to a context to destroy, constructed using
66+
- * secp256k1_context_create or secp256k1_context_clone
67+
- * (i.e., not secp256k1_context_static).
68+
- */
69+
-SECP256K1_API void secp256k1_context_destroy(
70+
- secp256k1_context *ctx
71+
-) SECP256K1_ARG_NONNULL(1);
72+
-
73+
/** Set a callback function to be called when an illegal argument is passed to
74+
* an API call. It will only trigger for violations that are mentioned
75+
* explicitly in the header.
76+
@@ -392,29 +328,6 @@ SECP256K1_API void secp256k1_context_set_error_callback(
77+
const void *data
78+
) SECP256K1_ARG_NONNULL(1);
79+
80+
-/** Create a secp256k1 scratch space object.
81+
- *
82+
- * Returns: a newly created scratch space.
83+
- * Args: ctx: pointer to a context object.
84+
- * In: size: amount of memory to be available as scratch space. Some extra
85+
- * (<100 bytes) will be allocated for extra accounting.
86+
- */
87+
-SECP256K1_API SECP256K1_WARN_UNUSED_RESULT secp256k1_scratch_space *secp256k1_scratch_space_create(
88+
- const secp256k1_context *ctx,
89+
- size_t size
90+
-) SECP256K1_ARG_NONNULL(1);
91+
-
92+
-/** Destroy a secp256k1 scratch space.
93+
- *
94+
- * The pointer may not be used afterwards.
95+
- * Args: ctx: pointer to a context object.
96+
- * scratch: space to destroy
97+
- */
98+
-SECP256K1_API void secp256k1_scratch_space_destroy(
99+
- const secp256k1_context *ctx,
100+
- secp256k1_scratch_space *scratch
101+
-) SECP256K1_ARG_NONNULL(1);
102+
-
103+
/** Parse a variable-length public key into the pubkey object.
104+
*
105+
* Returns: 1 if the public key was fully valid.

0 commit comments

Comments
 (0)