From d57d034bc669fed94b2ef758541a41bddb6aff98 Mon Sep 17 00:00:00 2001 From: joii Date: Mon, 26 Feb 2024 16:01:28 +0800 Subject: [PATCH 1/5] Rename secp256k1_data_20210801 to secp256k1_data --- Makefile | 10 +++++----- Makefile.clang | 10 +++++----- ...secp256k1_data_20210801.c => dump_secp256k1_data.c} | 4 ++-- c/omni_lock.c | 4 ++-- c/{secp256k1_helper_20210801.h => secp256k1_helper.h} | 2 +- test-vectors/tx_btc_P2PKH_compressed.json | 2 +- test-vectors/tx_btc_P2PKH_uncompressed.json | 2 +- test-vectors/tx_btc_Segwit_Bech32.json | 2 +- test-vectors/tx_btc_Segwit_P2SH.json | 2 +- test-vectors/tx_cobuild_btc_compressed.json | 2 +- test-vectors/tx_eth.json | 2 +- test-vectors/tx_eth_displaying.json | 2 +- tests/omni_lock/ckb_syscall_omni_lock_sim.h | 2 +- tests/omni_lock_rust/tests/misc.rs | 3 +-- tests/omni_lock_rust/tests/test_otx.rs | 2 +- 15 files changed, 25 insertions(+), 26 deletions(-) rename c/{dump_secp256k1_data_20210801.c => dump_secp256k1_data.c} (92%) rename c/{secp256k1_helper_20210801.h => secp256k1_helper.h} (97%) diff --git a/Makefile b/Makefile index d4f62ca..d0723d6 100644 --- a/Makefile +++ b/Makefile @@ -35,10 +35,10 @@ build/always_success: c/always_success.c $(OBJCOPY) --only-keep-debug $@ $@.debug $(OBJCOPY) --strip-debug --strip-all $@ -build/secp256k1_data_info_20210801.h: build/dump_secp256k1_data_20210801 +build/secp256k1_data_info.h: build/dump_secp256k1_data $< -build/dump_secp256k1_data_20210801: c/dump_secp256k1_data_20210801.c $(SECP256K1_SRC_20210801) +build/dump_secp256k1_data: c/dump_secp256k1_data.c $(SECP256K1_SRC_20210801) mkdir -p build gcc -I deps/secp256k1-20210801/src -I deps/secp256k1-20210801 -o $@ $< @@ -80,7 +80,7 @@ omni_lock_mol: build/cobuild.o: c/cobuild.c c/cobuild.h $(CC) -c $(OMNI_LOCK_CFLAGS) -o $@ $< -build/omni_lock.o: c/omni_lock.c c/omni_lock_supply.h c/omni_lock_acp.h build/secp256k1_data_info_20210801.h $(SECP256K1_SRC_20210801) c/ckb_identity.h +build/omni_lock.o: c/omni_lock.c c/omni_lock_supply.h c/omni_lock_acp.h build/secp256k1_data_info.h $(SECP256K1_SRC_20210801) c/ckb_identity.h $(CC) -c $(OMNI_LOCK_CFLAGS) -o $@ $< build/omni_lock: build/omni_lock.o build/cobuild.o @@ -95,8 +95,8 @@ cobuild_mol: moleculec-c2 --input build/cobuild_basic_mol2.json | clang-format -style=Google > c/cobuild_basic_mol2.h clean: clean2 - rm -rf build/secp256k1_data_info_20210801.h build/dump_secp256k1_data_20210801 - rm -f build/secp256k1_data_20210801 + rm -rf build/secp256k1_data_info.h build/dump_secp256k1_data + rm -f build/secp256k1_data cd deps/secp256k1-20210801 && [ -f "Makefile" ] && make clean clean2: diff --git a/Makefile.clang b/Makefile.clang index be58ad9..5d8ce4c 100644 --- a/Makefile.clang +++ b/Makefile.clang @@ -36,10 +36,10 @@ build/always_success: c/always_success.c $(OBJCOPY) --only-keep-debug $@ $@.debug $(OBJCOPY) --strip-debug --strip-all $@ -build/secp256k1_data_info_20210801.h: build/dump_secp256k1_data_20210801 +build/secp256k1_data_info.h: build/dump_secp256k1_data $< -build/dump_secp256k1_data_20210801: c/dump_secp256k1_data_20210801.c $(SECP256K1_SRC_20210801) +build/dump_secp256k1_data: c/dump_secp256k1_data.c $(SECP256K1_SRC_20210801) mkdir -p build $(CC) -I deps/secp256k1-20210801/src -I deps/secp256k1-20210801 -o $@ $< @@ -81,7 +81,7 @@ omni_lock_mol: build/cobuild.o: c/cobuild.c c/cobuild.h $(CC) -c $(OMNI_LOCK_CFLAGS) -o $@ $< -build/omni_lock.o: c/omni_lock.c c/omni_lock_supply.h c/omni_lock_acp.h build/secp256k1_data_info_20210801.h $(SECP256K1_SRC_20210801) c/ckb_identity.h +build/omni_lock.o: c/omni_lock.c c/omni_lock_supply.h c/omni_lock_acp.h build/secp256k1_data_info.h $(SECP256K1_SRC_20210801) c/ckb_identity.h $(CC) -c $(OMNI_LOCK_CFLAGS) -o $@ $< build/omni_lock: build/omni_lock.o build/cobuild.o @@ -97,8 +97,8 @@ cobuild_mol: moleculec-c2 --input build/cobuild_basic_mol2.json | clang-format -style=Google > c/cobuild_basic_mol2.h clean: clean2 - rm -rf build/secp256k1_data_info_20210801.h build/dump_secp256k1_data_20210801 - rm -f build/secp256k1_data_20210801 + rm -rf build/secp256k1_data_info.h build/dump_secp256k1_data + rm -f build/secp256k1_data cd deps/secp256k1-20210801 && [ -f "Makefile" ] && make clean clean2: diff --git a/c/dump_secp256k1_data_20210801.c b/c/dump_secp256k1_data.c similarity index 92% rename from c/dump_secp256k1_data_20210801.c rename to c/dump_secp256k1_data.c index 5cd23a3..f91ffb3 100644 --- a/c/dump_secp256k1_data_20210801.c +++ b/c/dump_secp256k1_data.c @@ -15,7 +15,7 @@ int main(int argc, char* argv[]) { size_t pre_size = sizeof(secp256k1_ecmult_static_pre_context); size_t pre128_size = sizeof(secp256k1_ecmult_static_pre128_context); - FILE* fp_data = fopen("build/secp256k1_data_20210801", "wb"); + FILE* fp_data = fopen("build/secp256k1_data", "wb"); if (!fp_data) { return ERROR_IO; } @@ -23,7 +23,7 @@ int main(int argc, char* argv[]) { fwrite(secp256k1_ecmult_static_pre128_context, pre128_size, 1, fp_data); fclose(fp_data); - FILE* fp = fopen("build/secp256k1_data_info_20210801.h", "w"); + FILE* fp = fopen("build/secp256k1_data_info.h", "w"); if (!fp) { return ERROR_IO; } diff --git a/c/omni_lock.c b/c/omni_lock.c index 92b58d5..38bb32c 100644 --- a/c/omni_lock.c +++ b/c/omni_lock.c @@ -20,9 +20,9 @@ int ckb_exit(signed char); #else #include "ckb_syscalls.h" #endif -// secp256k1_helper_20210801.h is not part of ckb-c-stdlib, can't be included in ckb_identity.h +// secp256k1_helper.h is not part of ckb-c-stdlib, can't be included in ckb_identity.h // An upgraded version is provided. -#include "secp256k1_helper_20210801.h" +#include "secp256k1_helper.h" #include "ckb_swappable_signatures.h" #include "ckb_identity.h" diff --git a/c/secp256k1_helper_20210801.h b/c/secp256k1_helper.h similarity index 97% rename from c/secp256k1_helper_20210801.h rename to c/secp256k1_helper.h index 4c4a6d3..ae562a8 100644 --- a/c/secp256k1_helper_20210801.h +++ b/c/secp256k1_helper.h @@ -2,7 +2,7 @@ #define CKB_SECP256K1_HELPER_H_ #include "ckb_syscalls.h" -#include "secp256k1_data_info_20210801.h" +#include "secp256k1_data_info.h" #define CKB_SECP256K1_HELPER_ERROR_LOADING_DATA -101 #define CKB_SECP256K1_HELPER_ERROR_ILLEGAL_CALLBACK -102 diff --git a/test-vectors/tx_btc_P2PKH_compressed.json b/test-vectors/tx_btc_P2PKH_compressed.json index f5d94ba..ad6a44b 100644 --- a/test-vectors/tx_btc_P2PKH_compressed.json +++ b/test-vectors/tx_btc_P2PKH_compressed.json @@ -80,7 +80,7 @@ }, "type": null }, - "data": "0x{{ data ../build/secp256k1_data_20210801 }}", + "data": "0x{{ data ../build/secp256k1_data }}", "header": null }, { diff --git a/test-vectors/tx_btc_P2PKH_uncompressed.json b/test-vectors/tx_btc_P2PKH_uncompressed.json index 7a59c9c..80ebf64 100644 --- a/test-vectors/tx_btc_P2PKH_uncompressed.json +++ b/test-vectors/tx_btc_P2PKH_uncompressed.json @@ -80,7 +80,7 @@ }, "type": null }, - "data": "0x{{ data ../build/secp256k1_data_20210801 }}", + "data": "0x{{ data ../build/secp256k1_data }}", "header": null }, { diff --git a/test-vectors/tx_btc_Segwit_Bech32.json b/test-vectors/tx_btc_Segwit_Bech32.json index 5d72eb6..7329676 100644 --- a/test-vectors/tx_btc_Segwit_Bech32.json +++ b/test-vectors/tx_btc_Segwit_Bech32.json @@ -80,7 +80,7 @@ }, "type": null }, - "data": "0x{{ data ../build/secp256k1_data_20210801 }}", + "data": "0x{{ data ../build/secp256k1_data }}", "header": null }, { diff --git a/test-vectors/tx_btc_Segwit_P2SH.json b/test-vectors/tx_btc_Segwit_P2SH.json index 78467b3..44450eb 100644 --- a/test-vectors/tx_btc_Segwit_P2SH.json +++ b/test-vectors/tx_btc_Segwit_P2SH.json @@ -80,7 +80,7 @@ }, "type": null }, - "data": "0x{{ data ../build/secp256k1_data_20210801 }}", + "data": "0x{{ data ../build/secp256k1_data }}", "header": null }, { diff --git a/test-vectors/tx_cobuild_btc_compressed.json b/test-vectors/tx_cobuild_btc_compressed.json index ad11366..6d7c9c2 100644 --- a/test-vectors/tx_cobuild_btc_compressed.json +++ b/test-vectors/tx_cobuild_btc_compressed.json @@ -80,7 +80,7 @@ }, "type": null }, - "data": "0x{{ data ../build/secp256k1_data_20210801 }}", + "data": "0x{{ data ../build/secp256k1_data }}", "header": null }, { diff --git a/test-vectors/tx_eth.json b/test-vectors/tx_eth.json index d78eecd..2c8149b 100644 --- a/test-vectors/tx_eth.json +++ b/test-vectors/tx_eth.json @@ -80,7 +80,7 @@ }, "type": null }, - "data": "0x{{ data ../build/secp256k1_data_20210801 }}", + "data": "0x{{ data ../build/secp256k1_data }}", "header": null }, { diff --git a/test-vectors/tx_eth_displaying.json b/test-vectors/tx_eth_displaying.json index 876ca3a..fc83e85 100644 --- a/test-vectors/tx_eth_displaying.json +++ b/test-vectors/tx_eth_displaying.json @@ -80,7 +80,7 @@ }, "type": null }, - "data": "0x{{ data ../build/secp256k1_data_20210801 }}", + "data": "0x{{ data ../build/secp256k1_data }}", "header": null }, { diff --git a/tests/omni_lock/ckb_syscall_omni_lock_sim.h b/tests/omni_lock/ckb_syscall_omni_lock_sim.h index cca2a1a..c635151 100644 --- a/tests/omni_lock/ckb_syscall_omni_lock_sim.h +++ b/tests/omni_lock/ckb_syscall_omni_lock_sim.h @@ -657,7 +657,7 @@ int ckb_load_cell_data(void* addr, uint64_t* len, size_t offset, size_t index, size_t source) { if (source == CKB_SOURCE_CELL_DEP && index == SPECIAL_SECP256K1_INDEX) { ASSERT(*len == 1048576); - FILE* input = fopen("build/secp256k1_data_20210801", "rb"); + FILE* input = fopen("build/secp256k1_data", "rb"); size_t read_item = fread(addr, *len, 1, input); ASSERT(read_item == 1); diff --git a/tests/omni_lock_rust/tests/misc.rs b/tests/omni_lock_rust/tests/misc.rs index f9f69fe..d017f4c 100644 --- a/tests/omni_lock_rust/tests/misc.rs +++ b/tests/omni_lock_rust/tests/misc.rs @@ -111,8 +111,7 @@ pub const COMMON_PREFIX: &str = "CKB transaction: 0x"; lazy_static! { pub static ref OMNI_LOCK: Bytes = Bytes::from(&include_bytes!("../../../build/omni_lock")[..]); pub static ref SIMPLE_UDT: Bytes = Bytes::from(&include_bytes!("../../../build/simple_udt")[..]); - pub static ref SECP256K1_DATA_BIN: Bytes = - Bytes::from(&include_bytes!("../../../build/secp256k1_data_20210801")[..]); + pub static ref SECP256K1_DATA_BIN: Bytes = Bytes::from(&include_bytes!("../../../build/secp256k1_data")[..]); pub static ref ALWAYS_SUCCESS: Bytes = Bytes::from(&include_bytes!("../../../build/always_success")[..]); pub static ref VALIDATE_SIGNATURE_RSA: Bytes = Bytes::from(&include_bytes!("../../../build/validate_signature_rsa")[..]); diff --git a/tests/omni_lock_rust/tests/test_otx.rs b/tests/omni_lock_rust/tests/test_otx.rs index 06e0444..d568bb1 100644 --- a/tests/omni_lock_rust/tests/test_otx.rs +++ b/tests/omni_lock_rust/tests/test_otx.rs @@ -179,7 +179,7 @@ pub fn println_rtx(tx_resolved: &ckb_types::core::cell::ResolvedTransaction) { } static BINARY_ALWAYS_SUCCESS: &[u8] = include_bytes!("../../../build/always_success"); -static BINARY_SECP256K1_DATA: &[u8] = include_bytes!("../../../build/secp256k1_data_20210801"); +static BINARY_SECP256K1_DATA: &[u8] = include_bytes!("../../../build/secp256k1_data"); static BINARY_OMNI_LOCK: &[u8] = include_bytes!("../../../build/omni_lock"); pub const IDENTITY_FLAGS_PUBKEY_HASH: u8 = 0; From 283494e9b80146d75012d5e8266ad96f9b5edfa1 Mon Sep 17 00:00:00 2001 From: joii Date: Mon, 26 Feb 2024 16:10:13 +0800 Subject: [PATCH 2/5] Submodules ckb-c-stdlib-20210801 secp256k1-20210801 renamed: remove the -20210801 at the end --- .gitmodules | 12 +++++------- Makefile | 18 +++++++++--------- Makefile.clang | 18 +++++++++--------- deps/{ckb-c-stdlib-20210801 => ckb-c-stdlib} | 0 deps/{secp256k1-20210801 => secp256k1} | 0 tests/omni_lock/CMakeLists.txt | 10 +++++----- tests/omni_lock/exec_fuzzer/Makefile | 6 +++--- 7 files changed, 31 insertions(+), 33 deletions(-) rename deps/{ckb-c-stdlib-20210801 => ckb-c-stdlib} (100%) rename deps/{secp256k1-20210801 => secp256k1} (100%) diff --git a/.gitmodules b/.gitmodules index b0c8ac4..6d068a4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,12 +1,10 @@ -[submodule "deps/ckb-c-stdlib-20210801"] - path = deps/ckb-c-stdlib-20210801 - url = https://github.com/nervosnetwork/ckb-c-stdlib.git - branch = master [submodule "deps/sparse-merkle-tree"] path = deps/sparse-merkle-tree url = https://github.com/nervosnetwork/sparse-merkle-tree.git branch = master -[submodule "deps/secp256k1-20210801"] - path = deps/secp256k1-20210801 +[submodule "deps/ckb-c-stdlib"] + path = deps/ckb-c-stdlib + url = https://github.com/nervosnetwork/ckb-c-stdlib.git +[submodule "deps/secp256k1"] + path = deps/secp256k1 url = https://github.com/nervosnetwork/secp256k1.git - branch = schnorr diff --git a/Makefile b/Makefile index d0723d6..f0a2f98 100644 --- a/Makefile +++ b/Makefile @@ -4,11 +4,11 @@ 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 := -nostdlib -nostartfiles -fno-builtin -Wl,-static -Wl,--gc-sections -SECP256K1_SRC_20210801 := deps/secp256k1-20210801/src/ecmult_static_pre_context.h +SECP256K1_SRC := deps/secp256k1/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 -OMNI_LOCK_CFLAGS := $(subst secp256k1,secp256k1-20210801,$(OMNI_LOCK_CFLAGS)) +OMNI_LOCK_CFLAGS :=$(subst ckb-c-std-lib,ckb-c-stdlib,$(CFLAGS)) -I deps/sparse-merkle-tree/c +OMNI_LOCK_CFLAGS := $(subst secp256k1,secp256k1,$(OMNI_LOCK_CFLAGS)) # enable log OMNI_LOCK_CFLAGS += -DCKB_C_STDLIB_PRINTF -DCKB_C_STDLIB_PRINTF_BUFFER_SIZE=1024 @@ -38,13 +38,13 @@ build/always_success: c/always_success.c build/secp256k1_data_info.h: build/dump_secp256k1_data $< -build/dump_secp256k1_data: c/dump_secp256k1_data.c $(SECP256K1_SRC_20210801) +build/dump_secp256k1_data: c/dump_secp256k1_data.c $(SECP256K1_SRC) mkdir -p build - gcc -I deps/secp256k1-20210801/src -I deps/secp256k1-20210801 -o $@ $< + gcc -I deps/secp256k1/src -I deps/secp256k1 -o $@ $< -$(SECP256K1_SRC_20210801): - cd deps/secp256k1-20210801 && \ +$(SECP256K1_SRC): + cd deps/secp256k1 && \ ./autogen.sh && \ CC=$(CC) LD=$(LD) ./configure --enable-ecmult-static-precomputation --with-ecmult-window=6 --enable-module-recovery --host=$(TARGET) && \ make src/ecmult_static_pre_context.h src/ecmult_static_context.h @@ -80,7 +80,7 @@ omni_lock_mol: build/cobuild.o: c/cobuild.c c/cobuild.h $(CC) -c $(OMNI_LOCK_CFLAGS) -o $@ $< -build/omni_lock.o: c/omni_lock.c c/omni_lock_supply.h c/omni_lock_acp.h build/secp256k1_data_info.h $(SECP256K1_SRC_20210801) c/ckb_identity.h +build/omni_lock.o: c/omni_lock.c c/omni_lock_supply.h c/omni_lock_acp.h build/secp256k1_data_info.h $(SECP256K1_SRC) c/ckb_identity.h $(CC) -c $(OMNI_LOCK_CFLAGS) -o $@ $< build/omni_lock: build/omni_lock.o build/cobuild.o @@ -97,7 +97,7 @@ cobuild_mol: clean: clean2 rm -rf build/secp256k1_data_info.h build/dump_secp256k1_data rm -f build/secp256k1_data - cd deps/secp256k1-20210801 && [ -f "Makefile" ] && make clean + cd deps/secp256k1 && [ -f "Makefile" ] && make clean clean2: rm -rf build/*.debug diff --git a/Makefile.clang b/Makefile.clang index 5d8ce4c..3662c67 100644 --- a/Makefile.clang +++ b/Makefile.clang @@ -7,11 +7,11 @@ CFLAGS := \ -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-unused-function -Wno-bitwise-instead-of-logical -g LDFLAGS := -nostdlib -static --gc-sections -SECP256K1_SRC_20210801 := deps/secp256k1-20210801/src/ecmult_static_pre_context.h +SECP256K1_SRC := deps/secp256k1/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 -OMNI_LOCK_CFLAGS := $(subst secp256k1,secp256k1-20210801,$(OMNI_LOCK_CFLAGS)) +OMNI_LOCK_CFLAGS :=$(subst ckb-c-std-lib,ckb-c-stdlib,$(CFLAGS)) -I deps/sparse-merkle-tree/c +OMNI_LOCK_CFLAGS := $(subst secp256k1,secp256k1,$(OMNI_LOCK_CFLAGS)) # enable log OMNI_LOCK_CFLAGS += -DCKB_C_STDLIB_PRINTF -DCKB_C_STDLIB_PRINTF_BUFFER_SIZE=1024 @@ -39,13 +39,13 @@ build/always_success: c/always_success.c build/secp256k1_data_info.h: build/dump_secp256k1_data $< -build/dump_secp256k1_data: c/dump_secp256k1_data.c $(SECP256K1_SRC_20210801) +build/dump_secp256k1_data: c/dump_secp256k1_data.c $(SECP256K1_SRC) mkdir -p build - $(CC) -I deps/secp256k1-20210801/src -I deps/secp256k1-20210801 -o $@ $< + $(CC) -I deps/secp256k1/src -I deps/secp256k1 -o $@ $< -$(SECP256K1_SRC_20210801): - cd deps/secp256k1-20210801 && \ +$(SECP256K1_SRC): + cd deps/secp256k1 && \ ./autogen.sh && \ CC=$(CC) LD=$(LD) ./configure --with-asm=no --enable-ecmult-static-precomputation --with-ecmult-window=6 --enable-module-recovery && \ make src/ecmult_static_pre_context.h src/ecmult_static_context.h @@ -81,7 +81,7 @@ omni_lock_mol: build/cobuild.o: c/cobuild.c c/cobuild.h $(CC) -c $(OMNI_LOCK_CFLAGS) -o $@ $< -build/omni_lock.o: c/omni_lock.c c/omni_lock_supply.h c/omni_lock_acp.h build/secp256k1_data_info.h $(SECP256K1_SRC_20210801) c/ckb_identity.h +build/omni_lock.o: c/omni_lock.c c/omni_lock_supply.h c/omni_lock_acp.h build/secp256k1_data_info.h $(SECP256K1_SRC) c/ckb_identity.h $(CC) -c $(OMNI_LOCK_CFLAGS) -o $@ $< build/omni_lock: build/omni_lock.o build/cobuild.o @@ -99,7 +99,7 @@ cobuild_mol: clean: clean2 rm -rf build/secp256k1_data_info.h build/dump_secp256k1_data rm -f build/secp256k1_data - cd deps/secp256k1-20210801 && [ -f "Makefile" ] && make clean + cd deps/secp256k1 && [ -f "Makefile" ] && make clean clean2: rm -rf build/*.debug diff --git a/deps/ckb-c-stdlib-20210801 b/deps/ckb-c-stdlib similarity index 100% rename from deps/ckb-c-stdlib-20210801 rename to deps/ckb-c-stdlib diff --git a/deps/secp256k1-20210801 b/deps/secp256k1 similarity index 100% rename from deps/secp256k1-20210801 rename to deps/secp256k1 diff --git a/tests/omni_lock/CMakeLists.txt b/tests/omni_lock/CMakeLists.txt index 12b1630..03d6206 100644 --- a/tests/omni_lock/CMakeLists.txt +++ b/tests/omni_lock/CMakeLists.txt @@ -18,17 +18,17 @@ add_definitions(-DCKB_USE_SIM) add_definitions(-DSECP256K1_BUILD) include_directories(../../tests/omni_lock) -include_directories(../../deps/ckb-c-stdlib-20210801) +include_directories(../../deps/ckb-c-stdlib) include_directories(../../deps/sparse-merkle-tree/c) # include_directories(deps/ckb-c-stdlib/libc) # on simulator, we don't use own "libc" -include_directories(../../deps/secp256k1-20210801/src) -include_directories(../../deps/secp256k1-20210801) -include_directories(../../deps/ckb-c-stdlib-20210801/molecule) +include_directories(../../deps/secp256k1/src) +include_directories(../../deps/secp256k1) +include_directories(../../deps/ckb-c-stdlib/molecule) include_directories(../../c) include_directories(../../build) add_executable(omni_lock_simulator ../../tests/omni_lock/omni_lock_sim.c) target_compile_definitions(omni_lock_simulator PUBLIC -D_FILE_OFFSET_BITS=64 -DCKB_DECLARATION_ONLY) -target_include_directories(omni_lock_simulator PUBLIC deps/ckb-c-stdlib-20210801/libc) +target_include_directories(omni_lock_simulator PUBLIC deps/ckb-c-stdlib/libc) target_link_libraries(omni_lock_simulator dl) diff --git a/tests/omni_lock/exec_fuzzer/Makefile b/tests/omni_lock/exec_fuzzer/Makefile index cba0089..756291c 100644 --- a/tests/omni_lock/exec_fuzzer/Makefile +++ b/tests/omni_lock/exec_fuzzer/Makefile @@ -16,16 +16,16 @@ LLVM_COV=llvm-cov CORPUS_DIR=corpus -FUZZER_FLAGS=-g -O1 -fsanitize=fuzzer,address,undefined -fsanitize-recover=address -I ../../../c -I ../../../deps/ckb-c-stdlib-20210801 +FUZZER_FLAGS=-g -O1 -fsanitize=fuzzer,address,undefined -fsanitize-recover=address -I ../../../c -I ../../../deps/ckb-c-stdlib COVERAGE_DIR=coverage -COVERAGE_FLAGS=-fprofile-instr-generate -fcoverage-mapping -I ../../../c -I ../../../deps/ckb-c-stdlib-20210801 +COVERAGE_FLAGS=-fprofile-instr-generate -fcoverage-mapping -I ../../../c -I ../../../deps/ckb-c-stdlib ifeq ($(OS),MacOS) COVERAGE_FLAGS+=-Wl,-U,_LLVMFuzzerCustomMutator -Wl,-U,_LLVMFuzzerInitialize endif -EXTERNAL_HEADERS=../../../deps/ckb-c-stdlib-20210801/ckb_exec.h +EXTERNAL_HEADERS=../../../deps/ckb-c-stdlib/ckb_exec.h all: fuzzer coverage From 9b8c666aacabe42c5e09dddbb0b59fefb3979204 Mon Sep 17 00:00:00 2001 From: joii Date: Mon, 26 Feb 2024 16:30:35 +0800 Subject: [PATCH 3/5] Remove clang --- .github/workflows/clang.yml | 17 ------ Dockerfile | 30 --------- Makefile.clang | 118 ------------------------------------ 3 files changed, 165 deletions(-) delete mode 100644 .github/workflows/clang.yml delete mode 100644 Dockerfile delete mode 100644 Makefile.clang diff --git a/.github/workflows/clang.yml b/.github/workflows/clang.yml deleted file mode 100644 index 99fdb94..0000000 --- a/.github/workflows/clang.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: Clang - -on: [push, pull_request] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v1 - - name: Update submodules - run: git submodule update --init - - name: Build contract - run: make -f Makefile.clang all-via-docker - - name: Run omni_lock tests - run: cd tests/omni_lock_rust && cargo test diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 1bb0e39..0000000 --- a/Dockerfile +++ /dev/null @@ -1,30 +0,0 @@ -FROM debian:bullseye-slim AS intermediate - -# Install dependencies -RUN apt-get -qq update; \ - apt-get install -qqy --no-install-recommends \ - gnupg2 wget ca-certificates apt-transport-https \ - autoconf automake cmake dpkg-dev file make patch libc6-dev libtool - -# Install LLVM -RUN echo "deb https://apt.llvm.org/bullseye llvm-toolchain-bullseye-16 main" \ - > /etc/apt/sources.list.d/llvm.list && \ - wget -qO /etc/apt/trusted.gpg.d/llvm.asc \ - https://apt.llvm.org/llvm-snapshot.gpg.key && \ - apt-get -qq update && \ - apt-get install -qqy -t llvm-toolchain-bullseye-16 clang-16 clang-tidy-16 clang-format-16 lld-16 libc++-16-dev libc++abi-16-dev && \ - for f in /usr/lib/llvm-*/bin/*; do ln -sf "$f" /usr/bin; done && \ - ln -sf clang /usr/bin/cc && \ - ln -sf clang /usr/bin/c89 && \ - ln -sf clang /usr/bin/c99 && \ - ln -sf clang++ /usr/bin/c++ && \ - ln -sf clang++ /usr/bin/g++ && \ - rm -rf /var/lib/apt/lists/* - -FROM intermediate as test - -COPY tests /tests - -RUN /tests/run.sh 16 - -FROM intermediate as final diff --git a/Makefile.clang b/Makefile.clang deleted file mode 100644 index 3662c67..0000000 --- a/Makefile.clang +++ /dev/null @@ -1,118 +0,0 @@ -CC := clang-16 -LD := ld.lld-16 -OBJCOPY := llvm-objcopy-16 -CFLAGS := \ - --target=riscv64 -march=rv64imc_zba_zbb_zbc_zbs \ - -fPIC -O2 -fno-builtin-printf -fno-builtin-memcmp -fno-builtin-memset -nostdinc -nostdlib -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-unused-function -Wno-bitwise-instead-of-logical -g -LDFLAGS := -nostdlib -static --gc-sections -SECP256K1_SRC := deps/secp256k1/src/ecmult_static_pre_context.h - - -OMNI_LOCK_CFLAGS :=$(subst ckb-c-std-lib,ckb-c-stdlib,$(CFLAGS)) -I deps/sparse-merkle-tree/c -OMNI_LOCK_CFLAGS := $(subst secp256k1,secp256k1,$(OMNI_LOCK_CFLAGS)) -# enable log -OMNI_LOCK_CFLAGS += -DCKB_C_STDLIB_PRINTF -DCKB_C_STDLIB_PRINTF_BUFFER_SIZE=1024 - - -PROTOCOL_HEADER := c/blockchain.h -PROTOCOL_SCHEMA := c/blockchain.mol -PROTOCOL_VERSION := d75e4c56ffa40e17fd2fe477da3f98c5578edcd1 -PROTOCOL_URL := https://raw.githubusercontent.com/nervosnetwork/ckb/${PROTOCOL_VERSION}/util/types/schemas/blockchain.mol -MOLC := moleculec -MOLC_VERSION := 0.7.0 - -BUILDER_DOCKER := xujiandong/ckb-riscv-llvm-toolchain@sha256:6409ab0d3e335c74088b54f4f73252f4b3367ae364d5c7ca7acee82135f5af4d - -all: build/omni_lock build/always_success - -all-via-docker: ${PROTOCOL_HEADER} - docker run --rm -v `pwd`:/code ${BUILDER_DOCKER} bash -c "cd /code && make -f Makefile.clang all" - - -build/always_success: c/always_success.c - $(CC) $(OMNI_LOCK_CFLAGS) -nostdlib -static -Wl,--gc-sections -o $@ $< - $(OBJCOPY) --only-keep-debug $@ $@.debug - $(OBJCOPY) --strip-debug --strip-all $@ - -build/secp256k1_data_info.h: build/dump_secp256k1_data - $< - -build/dump_secp256k1_data: c/dump_secp256k1_data.c $(SECP256K1_SRC) - mkdir -p build - $(CC) -I deps/secp256k1/src -I deps/secp256k1 -o $@ $< - - -$(SECP256K1_SRC): - cd deps/secp256k1 && \ - ./autogen.sh && \ - CC=$(CC) LD=$(LD) ./configure --with-asm=no --enable-ecmult-static-precomputation --with-ecmult-window=6 --enable-module-recovery && \ - make src/ecmult_static_pre_context.h src/ecmult_static_context.h - -${PROTOCOL_SCHEMA}: - curl -L -o $@ ${PROTOCOL_URL} - -ALL_C_SOURCE := $(wildcard c/omni_lock.c c/omni_lock_acp.h c/omni_lock_time_lock.h \ - tests/omni_lock/omni_lock_sim.c tests/omni_lock/ckb_syscall_omni_lock_sim.h tests/omni_lock/omni_lock_supply.h\ - c/blake2b_decl_only.h c/cobuild.h c/cobuild.c) - -fmt: - docker run --rm -v `pwd`:/code ${BUILDER_DOCKER} bash -c "cd code && clang-format -i -style=Google $(ALL_C_SOURCE)" - git diff --exit-code $(ALL_C_SOURCE) - -mol: - make omni_lock_mol - make cobuild_mol - -c/xudt_rce_mol.h: c/xudt_rce.mol - ${MOLC} --language c --schema-file $< > $@ - -c/xudt_rce_mol2.h: c/xudt_rce.mol - moleculec --language - --schema-file c/xudt_rce.mol --format json > build/blockchain_mol2.json - moleculec-c2 --input build/blockchain_mol2.json | clang-format -style=Google > c/xudt_rce_mol2.h - -omni_lock_mol: - ${MOLC} --language rust --schema-file c/omni_lock.mol | rustfmt > tests/omni_lock_rust/src/omni_lock.rs - ${MOLC} --language c --schema-file c/omni_lock.mol > c/omni_lock_mol.h - ${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/cobuild.o: c/cobuild.c c/cobuild.h - $(CC) -c $(OMNI_LOCK_CFLAGS) -o $@ $< - -build/omni_lock.o: c/omni_lock.c c/omni_lock_supply.h c/omni_lock_acp.h build/secp256k1_data_info.h $(SECP256K1_SRC) c/ckb_identity.h - $(CC) -c $(OMNI_LOCK_CFLAGS) -o $@ $< - -build/omni_lock: build/omni_lock.o build/cobuild.o - $(LD) $(LDFLAGS) -o $@ $^ - cp $@ $@.debug - $(OBJCOPY) --strip-debug --strip-all $@ - ls -l $@ - -cobuild_mol: - ${MOLC} --language rust --schema-file c/basic.mol | rustfmt > tests/omni_lock_rust/src/schemas/basic.rs - ${MOLC} --language rust --schema-file c/top_level.mol | rustfmt > tests/omni_lock_rust/src/schemas/top_level.rs - ${MOLC} --language - --schema-file c/basic.mol --format json > build/cobuild_basic_mol2.json - moleculec-c2 --input build/cobuild_basic_mol2.json | clang-format -style=Google > c/cobuild_basic_mol2.h - -clean: clean2 - rm -rf build/secp256k1_data_info.h build/dump_secp256k1_data - rm -f build/secp256k1_data - cd deps/secp256k1 && [ -f "Makefile" ] && make clean - -clean2: - rm -rf build/*.debug - rm -f build/omni_lock - rm -f build/*.o - rm -f build/always_success - -install-tools: - if [ ! -x "$$(command -v "${MOLC}")" ] \ - || [ "$$(${MOLC} --version | awk '{ print $$2 }' | tr -d ' ')" != "${MOLC_VERSION}" ]; then \ - cargo install --force --version "${MOLC_VERSION}" "${MOLC}"; \ - fi - -dist: clean all - -.PHONY: all all-via-docker dist clean package-clean package publish From bb5e9deb4282f91830d0995670e1e8f5a458343a Mon Sep 17 00:00:00 2001 From: joii Date: Mon, 26 Feb 2024 16:44:46 +0800 Subject: [PATCH 4/5] Delete redundant code in Makefile --- Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index f0a2f98..498c82d 100644 --- a/Makefile +++ b/Makefile @@ -2,13 +2,12 @@ TARGET := riscv64-unknown-linux-gnu CC := $(TARGET)-gcc 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 +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-stdlib -I deps/ckb-c-stdlib/libc -I deps/ckb-c-stdlib/molecule -I c -I build -Wall -Werror -Wno-nonnull -Wno-nonnull-compare -Wno-unused-function -g LDFLAGS := -nostdlib -nostartfiles -fno-builtin -Wl,-static -Wl,--gc-sections SECP256K1_SRC := deps/secp256k1/src/ecmult_static_pre_context.h -OMNI_LOCK_CFLAGS :=$(subst ckb-c-std-lib,ckb-c-stdlib,$(CFLAGS)) -I deps/sparse-merkle-tree/c -OMNI_LOCK_CFLAGS := $(subst secp256k1,secp256k1,$(OMNI_LOCK_CFLAGS)) +OMNI_LOCK_CFLAGS :=$(CFLAGS) -I deps/sparse-merkle-tree/c # enable log OMNI_LOCK_CFLAGS += -DCKB_C_STDLIB_PRINTF -DCKB_C_STDLIB_PRINTF_BUFFER_SIZE=1024 From 55d83537258369eff4df904b9f627a307ba6032f Mon Sep 17 00:00:00 2001 From: joii Date: Mon, 26 Feb 2024 16:52:27 +0800 Subject: [PATCH 5/5] Use compiled __builtin_ctzl --- c/omni_lock.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/c/omni_lock.c b/c/omni_lock.c index 38bb32c..c3d6156 100644 --- a/c/omni_lock.c +++ b/c/omni_lock.c @@ -1,5 +1,3 @@ -// in secp256k1_ctz64_var: we don't have __builtin_ctzl in gcc for RISC-V -#define __builtin_ctzl secp256k1_ctz64_var_debruijn // clang-format off #include // it's used by blockchain-api2.h, the behavior when panic