Skip to content

Commit 0b3b57d

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

File tree

5 files changed

+27
-32
lines changed

5 files changed

+27
-32
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: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@
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 <precomputed_ecmult.c>
1111

1212
#define ERROR_IO -1
1313

1414
int main(int argc, char* argv[]) {
15-
size_t pre_size = sizeof(secp256k1_ecmult_static_pre_context);
16-
size_t pre128_size = sizeof(secp256k1_ecmult_static_pre128_context);
15+
size_t pre_size = sizeof(secp256k1_pre_g);
16+
size_t pre128_size = sizeof(secp256k1_pre_g_128);
1717

1818
FILE* fp_data = fopen("build/secp256k1_data_20210801", "wb");
1919
if (!fp_data) {
2020
return ERROR_IO;
2121
}
22-
fwrite(secp256k1_ecmult_static_pre_context, pre_size, 1, fp_data);
23-
fwrite(secp256k1_ecmult_static_pre128_context, pre128_size, 1, fp_data);
22+
fwrite(secp256k1_pre_g, pre_size, 1, fp_data);
23+
fwrite(secp256k1_pre_g_128, pre128_size, 1, fp_data);
2424
fclose(fp_data);
2525

2626
FILE* fp = fopen("build/secp256k1_data_info_20210801.h", "w");
@@ -37,8 +37,8 @@ int main(int argc, char* argv[]) {
3737
blake2b_state blake2b_ctx;
3838
uint8_t hash[32];
3939
blake2b_init(&blake2b_ctx, 32);
40-
blake2b_update(&blake2b_ctx, secp256k1_ecmult_static_pre_context, pre_size);
41-
blake2b_update(&blake2b_ctx, secp256k1_ecmult_static_pre128_context,
40+
blake2b_update(&blake2b_ctx, secp256k1_pre_g, pre_size);
41+
blake2b_update(&blake2b_ctx, secp256k1_pre_g_128,
4242
pre128_size);
4343
blake2b_final(&blake2b_ctx, hash, 32);
4444

c/secp256k1_helper_20210801.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,16 @@
1515
*/
1616
#define HAVE_CONFIG_H 1
1717
#define USE_EXTERNAL_DEFAULT_CALLBACKS
18+
#define SECP256K1_PRECOMPUTED_ECMULT_H
19+
#include "group.h"
20+
#define WINDOW_G ECMULT_WINDOW_SIZE
21+
secp256k1_ge_storage* secp256k1_pre_g = NULL;
22+
secp256k1_ge_storage* secp256k1_pre_g_128 = NULL;
23+
#undef SECP256K1_NO_BUILD
1824
#include <secp256k1.c>
25+
#include "modules/recovery/main_impl.h"
26+
const secp256k1_ge_storage secp256k1_ecmult_gen_prec_table[COMB_BLOCKS]
27+
[COMB_POINTS];
1928

2029
void secp256k1_default_illegal_callback_fn(const char* str, void* data) {
2130
(void)str;
@@ -68,19 +77,14 @@ int ckb_secp256k1_custom_verify_only_initialize(secp256k1_context* context,
6877
return CKB_SECP256K1_HELPER_ERROR_LOADING_DATA;
6978
}
7079

71-
context->illegal_callback = default_illegal_callback;
72-
context->error_callback = default_error_callback;
80+
secp256k1_pre_g = (secp256k1_ge_storage*)data;
81+
secp256k1_pre_g_128 = (secp256k1_ge_storage*)(data + CKB_SECP256K1_DATA_PRE_SIZE);
7382

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;
83+
secp256k1_context* ctx = secp256k1_context_preallocated_create(
84+
(void*)context, SECP256K1_CONTEXT_VERIFY);
85+
if (!ctx) {
86+
return CKB_SECP256K1_HELPER_ERROR_LOADING_DATA;
87+
}
8488

8589
return 0;
8690
}

deps/secp256k1-20210801

Submodule secp256k1-20210801 updated 169 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+
"4fc2132f040de19a5355004252a0447421299844dc8e215cb7170c4a7174d7c7",
1919
),
2020
];
2121

0 commit comments

Comments
 (0)