Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update vendored version of secp256k1-zkp #81

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.11.0 - 2024-07-09

- Update upstream to 6152622613fdf1c5af6f31f74c427c4e9ee120ce

# 0.10.1 - 2024-01-10

- Fix compilation when `cfg(fuzzing)` is set
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "secp256k1-zkp"
version = "0.10.1"
version = "0.11.0"
authors = [ "Dawid Ciężarkiewicz <[email protected]>",
"Andrew Poelstra <[email protected]>",
"Lucas Soriano <[email protected]>",
Expand Down Expand Up @@ -34,7 +34,7 @@ rand = ["actual-rand", "secp256k1/rand"]
actual-serde = { package = "serde", version = "1.0", default-features = false, optional = true }
actual-rand = { package = "rand", version = "0.8", default-features = false, optional = true }
secp256k1 = "0.29.0"
secp256k1-zkp-sys = { version = "0.9.0", default-features = false, path = "./secp256k1-zkp-sys" }
secp256k1-zkp-sys = { version = "0.10.0", default-features = false, path = "./secp256k1-zkp-sys" }
internals = { package = "bitcoin-private", version = "0.1.0" }

[dev-dependencies]
Expand Down
4 changes: 4 additions & 0 deletions secp256k1-zkp-sys/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.10.0 - 2024-07-09

- Update upstream to 6152622613fdf1c5af6f31f74c427c4e9ee120ce

# 0.9.1 - 2023-01-03

- Many changes; restart CHANGELOG.
Expand Down
4 changes: 2 additions & 2 deletions secp256k1-zkp-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "secp256k1-zkp-sys"
version = "0.9.1"
version = "0.10.0"
authors = [ "Dawid Ciężarkiewicz <[email protected]>",
"Andrew Poelstra <[email protected]>",
"Steven Roose <[email protected]>",
Expand All @@ -13,7 +13,7 @@ description = "FFI for `libsecp256k1-zkp` library."
keywords = [ "secp256k1", "libsecp256k1-zkp", "ffi" ]
readme = "README.md"
build = "build.rs"
links = "rustsecp256k1zkp_v0_8_0"
links = "rustsecp256k1zkp_v0_10_0"

# Should make docs.rs show all functions, even those behind non-default features
[package.metadata.docs.rs]
Expand Down
62 changes: 36 additions & 26 deletions secp256k1-zkp-sys/depend/scratch_impl.h.patch
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
13,37d12
< static secp256k1_scratch* secp256k1_scratch_create(const secp256k1_callback* error_callback, size_t size) {
< const size_t base_alloc = ROUND_TO_ALIGN(sizeof(secp256k1_scratch));
< void *alloc = checked_malloc(error_callback, base_alloc + size);
< secp256k1_scratch* ret = (secp256k1_scratch *)alloc;
< if (ret != NULL) {
< memset(ret, 0, sizeof(*ret));
< memcpy(ret->magic, "scratch", 8);
< ret->data = (void *) ((char *) alloc + base_alloc);
< ret->max_size = size;
< }
< return ret;
< }
<
< static void secp256k1_scratch_destroy(const secp256k1_callback* error_callback, secp256k1_scratch* scratch) {
< if (scratch != NULL) {
< VERIFY_CHECK(scratch->alloc_size == 0); /* all checkpoints should be applied */
< if (secp256k1_memcmp_var(scratch->magic, "scratch", 8) != 0) {
< secp256k1_callback_call(error_callback, "invalid scratch space");
< return;
< }
< memset(scratch->magic, 0, sizeof(scratch->magic));
< free(scratch);
< }
< }
<
diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/scratch_impl.h b/secp256k1-zkp-sys/depend/secp256k1/src/scratch_impl.h
index f71a20b..5389571 100644
--- a/secp256k1-zkp-sys/depend/secp256k1/src/scratch_impl.h
+++ b/secp256k1-zkp-sys/depend/secp256k1/src/scratch_impl.h
@@ -10,31 +10,6 @@
#include "util.h"
#include "scratch.h"

-static secp256k1_scratch* secp256k1_scratch_create(const secp256k1_callback* error_callback, size_t size) {
- const size_t base_alloc = ROUND_TO_ALIGN(sizeof(secp256k1_scratch));
- void *alloc = checked_malloc(error_callback, base_alloc + size);
- secp256k1_scratch* ret = (secp256k1_scratch *)alloc;
- if (ret != NULL) {
- memset(ret, 0, sizeof(*ret));
- memcpy(ret->magic, "scratch", 8);
- ret->data = (void *) ((char *) alloc + base_alloc);
- ret->max_size = size;
- }
- return ret;
-}
-
-static void secp256k1_scratch_destroy(const secp256k1_callback* error_callback, secp256k1_scratch* scratch) {
- if (scratch != NULL) {
- if (secp256k1_memcmp_var(scratch->magic, "scratch", 8) != 0) {
- secp256k1_callback_call(error_callback, "invalid scratch space");
- return;
- }
- VERIFY_CHECK(scratch->alloc_size == 0); /* all checkpoints should be applied */
- memset(scratch->magic, 0, sizeof(scratch->magic));
- free(scratch);
- }
-}
-
static size_t secp256k1_scratch_checkpoint(const secp256k1_callback* error_callback, const secp256k1_scratch* scratch) {
if (secp256k1_memcmp_var(scratch->magic, "scratch", 8) != 0) {
secp256k1_callback_call(error_callback, "invalid scratch space");
2 changes: 1 addition & 1 deletion secp256k1-zkp-sys/depend/secp256k1-HEAD-revision.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This file was automatically created by vendor-libsecp.sh
1d256089004a19bdbead7c5676e52c8e07b09fce
6152622613fdf1c5af6f31f74c427c4e9ee120ce
121 changes: 78 additions & 43 deletions secp256k1-zkp-sys/depend/secp256k1.c.patch
Original file line number Diff line number Diff line change
@@ -1,43 +1,78 @@
139,149d138
< secp256k1_context* secp256k1_context_create(unsigned int flags) {
< size_t const prealloc_size = secp256k1_context_preallocated_size(flags);
< secp256k1_context* ctx = (secp256k1_context*)checked_malloc(&default_error_callback, prealloc_size);
< if (EXPECT(secp256k1_context_preallocated_create(ctx, flags) == NULL, 0)) {
< free(ctx);
< return NULL;
< }
<
< return ctx;
< }
<
164,174d152
< secp256k1_context* secp256k1_context_clone(const secp256k1_context* ctx) {
< secp256k1_context* ret;
< size_t prealloc_size;
<
< VERIFY_CHECK(ctx != NULL);
< prealloc_size = secp256k1_context_preallocated_clone_size(ctx);
< ret = (secp256k1_context*)checked_malloc(&ctx->error_callback, prealloc_size);
< ret = secp256k1_context_preallocated_clone(ctx, ret);
< return ret;
< }
<
183,189d160
< void secp256k1_context_destroy(secp256k1_context* ctx) {
< if (ctx != NULL) {
< secp256k1_context_preallocated_destroy(ctx);
< free(ctx);
< }
< }
<
206,215d176
< }
<
< secp256k1_scratch_space* secp256k1_scratch_space_create(const secp256k1_context* ctx, size_t max_size) {
< VERIFY_CHECK(ctx != NULL);
< return secp256k1_scratch_create(&ctx->error_callback, max_size);
< }
<
< void secp256k1_scratch_space_destroy(const secp256k1_context *ctx, secp256k1_scratch_space* scratch) {
< VERIFY_CHECK(ctx != NULL);
< secp256k1_scratch_destroy(&ctx->error_callback, scratch);
diff --git a/secp256k1-zkp-sys/depend/secp256k1/src/secp256k1.c b/secp256k1-zkp-sys/depend/secp256k1/src/secp256k1.c
index 4c57826..dacaed2 100644
--- a/secp256k1-zkp-sys/depend/secp256k1/src/secp256k1.c
+++ b/secp256k1-zkp-sys/depend/secp256k1/src/secp256k1.c
@@ -158,17 +158,6 @@ secp256k1_context* secp256k1_context_preallocated_create(void* prealloc, unsigne
return ret;
}

-secp256k1_context* secp256k1_context_create(unsigned int flags) {
- size_t const prealloc_size = secp256k1_context_preallocated_size(flags);
- secp256k1_context* ctx = (secp256k1_context*)checked_malloc(&default_error_callback, prealloc_size);
- if (EXPECT(secp256k1_context_preallocated_create(ctx, flags) == NULL, 0)) {
- free(ctx);
- return NULL;
- }
-
- return ctx;
-}
-
secp256k1_context* secp256k1_context_preallocated_clone(const secp256k1_context* ctx, void* prealloc) {
secp256k1_context* ret;
VERIFY_CHECK(ctx != NULL);
@@ -180,19 +169,6 @@ secp256k1_context* secp256k1_context_preallocated_clone(const secp256k1_context*
return ret;
}

-secp256k1_context* secp256k1_context_clone(const secp256k1_context* ctx) {
- secp256k1_context* ret;
- size_t prealloc_size;
-
- VERIFY_CHECK(ctx != NULL);
- ARG_CHECK(secp256k1_context_is_proper(ctx));
-
- prealloc_size = secp256k1_context_preallocated_clone_size(ctx);
- ret = (secp256k1_context*)checked_malloc(&ctx->error_callback, prealloc_size);
- ret = secp256k1_context_preallocated_clone(ctx, ret);
- return ret;
-}
-
void secp256k1_context_preallocated_destroy(secp256k1_context* ctx) {
ARG_CHECK_VOID(ctx == NULL || secp256k1_context_is_proper(ctx));

@@ -204,18 +180,6 @@ void secp256k1_context_preallocated_destroy(secp256k1_context* ctx) {
secp256k1_ecmult_gen_context_clear(&ctx->ecmult_gen_ctx);
}

-void secp256k1_context_destroy(secp256k1_context* ctx) {
- ARG_CHECK_VOID(ctx == NULL || secp256k1_context_is_proper(ctx));
-
- /* Defined as noop */
- if (ctx == NULL) {
- return;
- }
-
- secp256k1_context_preallocated_destroy(ctx);
- free(ctx);
-}
-
void secp256k1_context_set_illegal_callback(secp256k1_context* ctx, void (*fun)(const char* message, void* data), const void* data) {
/* We compare pointers instead of checking secp256k1_context_is_proper() here
because setting callbacks is allowed on *copies* of the static context:
@@ -240,16 +204,6 @@ void secp256k1_context_set_error_callback(secp256k1_context* ctx, void (*fun)(co
ctx->error_callback.data = data;
}

-secp256k1_scratch_space* secp256k1_scratch_space_create(const secp256k1_context* ctx, size_t max_size) {
- VERIFY_CHECK(ctx != NULL);
- return secp256k1_scratch_create(&ctx->error_callback, max_size);
-}
-
-void secp256k1_scratch_space_destroy(const secp256k1_context *ctx, secp256k1_scratch_space* scratch) {
- VERIFY_CHECK(ctx != NULL);
- secp256k1_scratch_destroy(&ctx->error_callback, scratch);
-}
-
/* Mark memory as no-longer-secret for the purpose of analysing constant-time behaviour
* of the software.
*/
127 changes: 105 additions & 22 deletions secp256k1-zkp-sys/depend/secp256k1.h.patch
Original file line number Diff line number Diff line change
@@ -1,22 +1,105 @@
226,228d225
< SECP256K1_API secp256k1_context* secp256k1_context_create(
< unsigned int flags
< ) SECP256K1_WARN_UNUSED_RESULT;
231,233d227
< SECP256K1_API secp256k1_context* secp256k1_context_clone(
< const secp256k1_context* ctx
< ) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT;
248,250d241
< SECP256K1_API void secp256k1_context_destroy(
< secp256k1_context* ctx
< ) SECP256K1_ARG_NONNULL(1);
327,330d317
< SECP256K1_API SECP256K1_WARN_UNUSED_RESULT secp256k1_scratch_space* secp256k1_scratch_space_create(
< const secp256k1_context* ctx,
< size_t size
< ) SECP256K1_ARG_NONNULL(1);
338,341d324
< SECP256K1_API void secp256k1_scratch_space_destroy(
< const secp256k1_context* ctx,
< secp256k1_scratch_space* scratch
< ) SECP256K1_ARG_NONNULL(1);
diff --git a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1.h b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1.h
index f4053f2..aa2d18b 100644
--- a/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1.h
+++ b/secp256k1-zkp-sys/depend/secp256k1/include/secp256k1.h
@@ -257,70 +257,6 @@ SECP256K1_DEPRECATED("Use secp256k1_context_static instead");
*/
SECP256K1_API void secp256k1_selftest(void);

-
-/** Create a secp256k1 context object (in dynamically allocated memory).
- *
- * This function uses malloc to allocate memory. It is guaranteed that malloc is
- * called at most once for every call of this function. If you need to avoid dynamic
- * memory allocation entirely, see secp256k1_context_static and the functions in
- * secp256k1_preallocated.h.
- *
- * Returns: pointer to a newly created context object.
- * In: flags: Always set to SECP256K1_CONTEXT_NONE (see below).
- *
- * The only valid non-deprecated flag in recent library versions is
- * SECP256K1_CONTEXT_NONE, which will create a context sufficient for all functionality
- * offered by the library. All other (deprecated) flags will be treated as equivalent
- * to the SECP256K1_CONTEXT_NONE flag. Though the flags parameter primarily exists for
- * historical reasons, future versions of the library may introduce new flags.
- *
- * If the context is intended to be used for API functions that perform computations
- * involving secret keys, e.g., signing and public key generation, then it is highly
- * recommended to call secp256k1_context_randomize on the context before calling
- * those API functions. This will provide enhanced protection against side-channel
- * leakage, see secp256k1_context_randomize for details.
- *
- * Do not create a new context object for each operation, as construction and
- * randomization can take non-negligible time.
- */
-SECP256K1_API secp256k1_context *secp256k1_context_create(
- unsigned int flags
-) SECP256K1_WARN_UNUSED_RESULT;
-
-/** Copy a secp256k1 context object (into dynamically allocated memory).
- *
- * This function uses malloc to allocate memory. It is guaranteed that malloc is
- * called at most once for every call of this function. If you need to avoid dynamic
- * memory allocation entirely, see the functions in secp256k1_preallocated.h.
- *
- * Cloning secp256k1_context_static is not possible, and should not be emulated by
- * the caller (e.g., using memcpy). Create a new context instead.
- *
- * Returns: pointer to a newly created context object.
- * Args: ctx: pointer to a context to copy (not secp256k1_context_static).
- */
-SECP256K1_API secp256k1_context *secp256k1_context_clone(
- const secp256k1_context *ctx
-) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT;
-
-/** Destroy a secp256k1 context object (created in dynamically allocated memory).
- *
- * The context pointer may not be used afterwards.
- *
- * The context to destroy must have been created using secp256k1_context_create
- * or secp256k1_context_clone. If the context has instead been created using
- * secp256k1_context_preallocated_create or secp256k1_context_preallocated_clone, the
- * behaviour is undefined. In that case, secp256k1_context_preallocated_destroy must
- * be used instead.
- *
- * Args: ctx: pointer to a context to destroy, constructed using
- * secp256k1_context_create or secp256k1_context_clone
- * (i.e., not secp256k1_context_static).
- */
-SECP256K1_API void secp256k1_context_destroy(
- secp256k1_context *ctx
-) SECP256K1_ARG_NONNULL(1);
-
/** Set a callback function to be called when an illegal argument is passed to
* an API call. It will only trigger for violations that are mentioned
* explicitly in the header.
@@ -392,29 +328,6 @@ SECP256K1_API void secp256k1_context_set_error_callback(
const void *data
) SECP256K1_ARG_NONNULL(1);

-/** Create a secp256k1 scratch space object.
- *
- * Returns: a newly created scratch space.
- * Args: ctx: pointer to a context object.
- * In: size: amount of memory to be available as scratch space. Some extra
- * (<100 bytes) will be allocated for extra accounting.
- */
-SECP256K1_API SECP256K1_WARN_UNUSED_RESULT secp256k1_scratch_space *secp256k1_scratch_space_create(
- const secp256k1_context *ctx,
- size_t size
-) SECP256K1_ARG_NONNULL(1);
-
-/** Destroy a secp256k1 scratch space.
- *
- * The pointer may not be used afterwards.
- * Args: ctx: pointer to a context object.
- * scratch: space to destroy
- */
-SECP256K1_API void secp256k1_scratch_space_destroy(
- const secp256k1_context *ctx,
- secp256k1_scratch_space *scratch
-) SECP256K1_ARG_NONNULL(1);
-
/** Parse a variable-length public key into the pubkey object.
*
* Returns: 1 if the public key was fully valid.
Loading
Loading