Skip to content

Commit cb799a1

Browse files
committed
Update secp256k1 to v0.6.0
1 parent cd764d7 commit cb799a1

File tree

5 files changed

+13
-26
lines changed

5 files changed

+13
-26
lines changed

Makefile

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ LD := $(TARGET)-gcc
44
OBJCOPY := $(TARGET)-objcopy
55
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
66
LDFLAGS := -Wl,-static -fdata-sections -ffunction-sections -Wl,--gc-sections
7-
SECP256K1_SRC_20210801 := deps/secp256k1-20210801/src/ecmult_static_pre_context.h
87

98

109
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
3534
build/secp256k1_data_info_20210801.h: build/dump_secp256k1_data_20210801
3635
$<
3736

38-
build/dump_secp256k1_data_20210801: c/dump_secp256k1_data_20210801.c $(SECP256K1_SRC_20210801)
37+
build/dump_secp256k1_data_20210801: c/dump_secp256k1_data_20210801.c
3938
mkdir -p build
4039
gcc -I deps/secp256k1-20210801/src -I deps/secp256k1-20210801 -o $@ $<
4140

42-
43-
$(SECP256K1_SRC_20210801):
44-
cd deps/secp256k1-20210801 && \
45-
./autogen.sh && \
46-
CC=$(CC) LD=$(LD) ./configure --with-bignum=no --enable-ecmult-static-precomputation --enable-endomorphism --enable-module-recovery --host=$(TARGET) && \
47-
make src/ecmult_static_pre_context.h src/ecmult_static_context.h
48-
49-
5041
build/impl.o: deps/ckb-c-std-lib/libc/src/impl.c
5142
$(CC) -c $(filter-out -DCKB_DECLARATION_ONLY, $(CFLAGS_MBEDTLS)) $(LDFLAGS_MBEDTLS) -o $@ $^
5243

@@ -76,7 +67,7 @@ omni_lock_mol:
7667
${MOLC} --language - --schema-file c/omni_lock.mol --format json > build/omni_lock_mol2.json
7768
moleculec-c2 --input build/omni_lock_mol2.json | clang-format -style=Google > c/omni_lock_mol2.h
7869

79-
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
70+
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
8071
$(CC) $(OMNI_LOCK_CFLAGS) $(LDFLAGS) -o $@ $<
8172
cp $@ $@.debug
8273
$(OBJCOPY) --strip-debug --strip-all $@

c/dump_secp256k1_data_20210801.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* directly, the final binary will include all functions rather than those used.
88
*/
99
#define HAVE_CONFIG_H 1
10-
#include <secp256k1.c>
10+
#include <dump_precomputed_ecmult.h>
1111

1212
#define ERROR_IO -1
1313

c/secp256k1_helper_20210801.h

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
*/
1616
#define HAVE_CONFIG_H 1
1717
#define USE_EXTERNAL_DEFAULT_CALLBACKS
18+
#define SECP256K1_GE_STORAGE_PTR
1819
#include <secp256k1.c>
20+
#include "modules/recovery/main_impl.h"
1921

2022
void secp256k1_default_illegal_callback_fn(const char* str, void* data) {
2123
(void)str;
@@ -68,19 +70,13 @@ int ckb_secp256k1_custom_verify_only_initialize(secp256k1_context* context,
6870
return CKB_SECP256K1_HELPER_ERROR_LOADING_DATA;
6971
}
7072

71-
context->illegal_callback = default_illegal_callback;
72-
context->error_callback = default_error_callback;
73+
update_secp256k1_ge_storage(data);
7374

74-
secp256k1_ecmult_context_init(&context->ecmult_ctx);
75-
secp256k1_ecmult_gen_context_init(&context->ecmult_gen_ctx);
76-
77-
/* Recasting data to (uint8_t*) for pointer math */
78-
uint8_t* p = data;
79-
secp256k1_ge_storage(*pre_g)[] = (secp256k1_ge_storage(*)[])p;
80-
secp256k1_ge_storage(*pre_g_128)[] =
81-
(secp256k1_ge_storage(*)[])(&p[CKB_SECP256K1_DATA_PRE_SIZE]);
82-
context->ecmult_ctx.pre_g = pre_g;
83-
context->ecmult_ctx.pre_g_128 = pre_g_128;
75+
secp256k1_context* ctx = secp256k1_context_preallocated_create(
76+
(void*)context, SECP256K1_CONTEXT_VERIFY);
77+
if (!ctx) {
78+
return CKB_SECP256K1_HELPER_ERROR_LOADING_DATA;
79+
}
8480

8581
return 0;
8682
}

deps/secp256k1-20210801

Submodule secp256k1-20210801 updated 170 files

tests/omni_lock_rust/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const CKB_HASH_PERSONALIZATION: &[u8] = b"ckb-default-hash";
1515
const BINARIES: &[(&str, &str)] = &[
1616
(
1717
"omni_lock",
18-
"768f306681da232ceb0b94f436c5f813377179762a831c5ad8797bd4fd2d118d",
18+
"acd0b02f1338948304bae16f9ce748885458a22cd33ef2cd758134259de23b29",
1919
),
2020
];
2121

0 commit comments

Comments
 (0)