Skip to content

Commit

Permalink
Update secp256k1 to v0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
joii2020 committed Dec 12, 2024
1 parent cd764d7 commit cb799a1
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 26 deletions.
13 changes: 2 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 $@ $^

Expand Down Expand Up @@ -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 $@
Expand Down
2 changes: 1 addition & 1 deletion c/dump_secp256k1_data_20210801.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* directly, the final binary will include all functions rather than those used.
*/
#define HAVE_CONFIG_H 1
#include <secp256k1.c>
#include <dump_precomputed_ecmult.h>

#define ERROR_IO -1

Expand Down
20 changes: 8 additions & 12 deletions c/secp256k1_helper_20210801.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/
#define HAVE_CONFIG_H 1
#define USE_EXTERNAL_DEFAULT_CALLBACKS
#define SECP256K1_GE_STORAGE_PTR
#include <secp256k1.c>
#include "modules/recovery/main_impl.h"

void secp256k1_default_illegal_callback_fn(const char* str, void* data) {
(void)str;
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion deps/secp256k1-20210801
2 changes: 1 addition & 1 deletion tests/omni_lock_rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const CKB_HASH_PERSONALIZATION: &[u8] = b"ckb-default-hash";
const BINARIES: &[(&str, &str)] = &[
(
"omni_lock",
"768f306681da232ceb0b94f436c5f813377179762a831c5ad8797bd4fd2d118d",
"acd0b02f1338948304bae16f9ce748885458a22cd33ef2cd758134259de23b29",
),
];

Expand Down

0 comments on commit cb799a1

Please sign in to comment.