From cb799a17e6e1e38d072a44a7d68d825d3c94bd13 Mon Sep 17 00:00:00 2001 From: Joii Date: Thu, 12 Dec 2024 22:01:29 +0800 Subject: [PATCH] Update secp256k1 to v0.6.0 --- Makefile | 13 ++----------- c/dump_secp256k1_data_20210801.c | 2 +- c/secp256k1_helper_20210801.h | 20 ++++++++------------ deps/secp256k1-20210801 | 2 +- tests/omni_lock_rust/build.rs | 2 +- 5 files changed, 13 insertions(+), 26 deletions(-) diff --git a/Makefile b/Makefile index 1c46576..86a1195 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,6 @@ LD := $(TARGET)-gcc OBJCOPY := $(TARGET)-objcopy CFLAGS := -fPIC -O3 -fno-builtin-printf -fno-builtin-memcmp -nostdinc -nostdlib -nostartfiles -fvisibility=hidden -fdata-sections -ffunction-sections -I deps/secp256k1/src -I deps/secp256k1 -I deps/ckb-c-std-lib -I deps/ckb-c-std-lib/libc -I deps/ckb-c-std-lib/molecule -I c -I build -Wall -Werror -Wno-nonnull -Wno-nonnull-compare -Wno-unused-function -g LDFLAGS := -Wl,-static -fdata-sections -ffunction-sections -Wl,--gc-sections -SECP256K1_SRC_20210801 := deps/secp256k1-20210801/src/ecmult_static_pre_context.h OMNI_LOCK_CFLAGS :=$(subst ckb-c-std-lib,ckb-c-stdlib-20210801,$(CFLAGS)) -I deps/sparse-merkle-tree/c @@ -35,18 +34,10 @@ build/always_success: c/always_success.c build/secp256k1_data_info_20210801.h: build/dump_secp256k1_data_20210801 $< -build/dump_secp256k1_data_20210801: c/dump_secp256k1_data_20210801.c $(SECP256K1_SRC_20210801) +build/dump_secp256k1_data_20210801: c/dump_secp256k1_data_20210801.c mkdir -p build gcc -I deps/secp256k1-20210801/src -I deps/secp256k1-20210801 -o $@ $< - -$(SECP256K1_SRC_20210801): - cd deps/secp256k1-20210801 && \ - ./autogen.sh && \ - CC=$(CC) LD=$(LD) ./configure --with-bignum=no --enable-ecmult-static-precomputation --enable-endomorphism --enable-module-recovery --host=$(TARGET) && \ - make src/ecmult_static_pre_context.h src/ecmult_static_context.h - - build/impl.o: deps/ckb-c-std-lib/libc/src/impl.c $(CC) -c $(filter-out -DCKB_DECLARATION_ONLY, $(CFLAGS_MBEDTLS)) $(LDFLAGS_MBEDTLS) -o $@ $^ @@ -76,7 +67,7 @@ omni_lock_mol: ${MOLC} --language - --schema-file c/omni_lock.mol --format json > build/omni_lock_mol2.json moleculec-c2 --input build/omni_lock_mol2.json | clang-format -style=Google > c/omni_lock_mol2.h -build/omni_lock: c/omni_lock.c c/omni_lock_supply.h c/omni_lock_acp.h c/secp256k1_lock.h build/secp256k1_data_info_20210801.h $(SECP256K1_SRC_20210801) c/ckb_identity.h +build/omni_lock: c/omni_lock.c c/omni_lock_supply.h c/omni_lock_acp.h c/secp256k1_lock.h build/secp256k1_data_info_20210801.h c/ckb_identity.h $(CC) $(OMNI_LOCK_CFLAGS) $(LDFLAGS) -o $@ $< cp $@ $@.debug $(OBJCOPY) --strip-debug --strip-all $@ diff --git a/c/dump_secp256k1_data_20210801.c b/c/dump_secp256k1_data_20210801.c index 10f4236..5abd8fa 100644 --- a/c/dump_secp256k1_data_20210801.c +++ b/c/dump_secp256k1_data_20210801.c @@ -7,7 +7,7 @@ * directly, the final binary will include all functions rather than those used. */ #define HAVE_CONFIG_H 1 -#include +#include #define ERROR_IO -1 diff --git a/c/secp256k1_helper_20210801.h b/c/secp256k1_helper_20210801.h index 3b1e9f4..bb32324 100644 --- a/c/secp256k1_helper_20210801.h +++ b/c/secp256k1_helper_20210801.h @@ -15,7 +15,9 @@ */ #define HAVE_CONFIG_H 1 #define USE_EXTERNAL_DEFAULT_CALLBACKS +#define SECP256K1_GE_STORAGE_PTR #include +#include "modules/recovery/main_impl.h" void secp256k1_default_illegal_callback_fn(const char* str, void* data) { (void)str; @@ -68,19 +70,13 @@ int ckb_secp256k1_custom_verify_only_initialize(secp256k1_context* context, return CKB_SECP256K1_HELPER_ERROR_LOADING_DATA; } - context->illegal_callback = default_illegal_callback; - context->error_callback = default_error_callback; + update_secp256k1_ge_storage(data); - secp256k1_ecmult_context_init(&context->ecmult_ctx); - secp256k1_ecmult_gen_context_init(&context->ecmult_gen_ctx); - - /* Recasting data to (uint8_t*) for pointer math */ - uint8_t* p = data; - secp256k1_ge_storage(*pre_g)[] = (secp256k1_ge_storage(*)[])p; - secp256k1_ge_storage(*pre_g_128)[] = - (secp256k1_ge_storage(*)[])(&p[CKB_SECP256K1_DATA_PRE_SIZE]); - context->ecmult_ctx.pre_g = pre_g; - context->ecmult_ctx.pre_g_128 = pre_g_128; + secp256k1_context* ctx = secp256k1_context_preallocated_create( + (void*)context, SECP256K1_CONTEXT_VERIFY); + if (!ctx) { + return CKB_SECP256K1_HELPER_ERROR_LOADING_DATA; + } return 0; } diff --git a/deps/secp256k1-20210801 b/deps/secp256k1-20210801 index fa76917..0ced364 160000 --- a/deps/secp256k1-20210801 +++ b/deps/secp256k1-20210801 @@ -1 +1 @@ -Subproject commit fa76917903ed9f2dab69ee28b30f742fe440962b +Subproject commit 0ced36409add106da5c53f1097f5d65da7b20734 diff --git a/tests/omni_lock_rust/build.rs b/tests/omni_lock_rust/build.rs index b0b2821..8bff608 100644 --- a/tests/omni_lock_rust/build.rs +++ b/tests/omni_lock_rust/build.rs @@ -15,7 +15,7 @@ const CKB_HASH_PERSONALIZATION: &[u8] = b"ckb-default-hash"; const BINARIES: &[(&str, &str)] = &[ ( "omni_lock", - "768f306681da232ceb0b94f436c5f813377179762a831c5ad8797bd4fd2d118d", + "acd0b02f1338948304bae16f9ce748885458a22cd33ef2cd758134259de23b29", ), ];