Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update according to reviews #38

Merged
merged 5 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions .github/workflows/clang.yml

This file was deleted.

12 changes: 5 additions & 7 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
30 changes: 0 additions & 30 deletions Dockerfile

This file was deleted.

25 changes: 12 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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_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 :=$(CFLAGS) -I deps/sparse-merkle-tree/c
# enable log
OMNI_LOCK_CFLAGS += -DCKB_C_STDLIB_PRINTF -DCKB_C_STDLIB_PRINTF_BUFFER_SIZE=1024

Expand All @@ -35,16 +34,16 @@ build/always_success: c/always_success.c
$(OBJCOPY) --only-keep-debug $@ [email protected]
$(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)
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
Expand Down Expand Up @@ -80,7 +79,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) c/ckb_identity.h
$(CC) -c $(OMNI_LOCK_CFLAGS) -o $@ $<

build/omni_lock: build/omni_lock.o build/cobuild.o
Expand All @@ -95,9 +94,9 @@ 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
cd deps/secp256k1-20210801 && [ -f "Makefile" ] && make clean
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
Expand Down
118 changes: 0 additions & 118 deletions Makefile.clang

This file was deleted.

4 changes: 2 additions & 2 deletions c/dump_secp256k1_data_20210801.c → c/dump_secp256k1_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ 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;
}
fwrite(secp256k1_ecmult_static_pre_context, pre_size, 1, fp_data);
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;
}
Expand Down
6 changes: 2 additions & 4 deletions c/omni_lock.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
// it's used by blockchain-api2.h, the behavior when panic
Expand All @@ -20,9 +18,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"
Expand Down
2 changes: 1 addition & 1 deletion c/secp256k1_helper_20210801.h → c/secp256k1_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test-vectors/tx_btc_P2PKH_compressed.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
},
"type": null
},
"data": "0x{{ data ../build/secp256k1_data_20210801 }}",
"data": "0x{{ data ../build/secp256k1_data }}",
"header": null
},
{
Expand Down
2 changes: 1 addition & 1 deletion test-vectors/tx_btc_P2PKH_uncompressed.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
},
"type": null
},
"data": "0x{{ data ../build/secp256k1_data_20210801 }}",
"data": "0x{{ data ../build/secp256k1_data }}",
"header": null
},
{
Expand Down
2 changes: 1 addition & 1 deletion test-vectors/tx_btc_Segwit_Bech32.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
},
"type": null
},
"data": "0x{{ data ../build/secp256k1_data_20210801 }}",
"data": "0x{{ data ../build/secp256k1_data }}",
"header": null
},
{
Expand Down
2 changes: 1 addition & 1 deletion test-vectors/tx_btc_Segwit_P2SH.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
},
"type": null
},
"data": "0x{{ data ../build/secp256k1_data_20210801 }}",
"data": "0x{{ data ../build/secp256k1_data }}",
"header": null
},
{
Expand Down
2 changes: 1 addition & 1 deletion test-vectors/tx_cobuild_btc_compressed.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
},
"type": null
},
"data": "0x{{ data ../build/secp256k1_data_20210801 }}",
"data": "0x{{ data ../build/secp256k1_data }}",
"header": null
},
{
Expand Down
2 changes: 1 addition & 1 deletion test-vectors/tx_eth.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
},
"type": null
},
"data": "0x{{ data ../build/secp256k1_data_20210801 }}",
"data": "0x{{ data ../build/secp256k1_data }}",
"header": null
},
{
Expand Down
2 changes: 1 addition & 1 deletion test-vectors/tx_eth_displaying.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
},
"type": null
},
"data": "0x{{ data ../build/secp256k1_data_20210801 }}",
"data": "0x{{ data ../build/secp256k1_data }}",
"header": null
},
{
Expand Down
10 changes: 5 additions & 5 deletions tests/omni_lock/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion tests/omni_lock/ckb_syscall_omni_lock_sim.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading