diff --git a/script/Cargo.toml b/script/Cargo.toml index c595451420..7a32b42357 100644 --- a/script/Cargo.toml +++ b/script/Cargo.toml @@ -32,8 +32,8 @@ tokio = { version = "1.35.0", features = ["rt-multi-thread"] } [dev-dependencies] proptest = "1.0" -ckb-db = { path = "../db", version = "= 0.114.0-pre" } -ckb-store = { path = "../store", version = "= 0.114.0-pre" } +ckb-db = { path = "../db", version = "= 0.114.0-pre", features = ["portable"] } +ckb-store = { path = "../store", version = "= 0.114.0-pre", features = ["portable"] } ckb-test-chain-utils = { path = "../util/test-chain-utils", version = "= 0.114.0-pre" } tiny-keccak = { version = "2.0", features = ["sha3"] } ckb-crypto = { path = "../util/crypto", version = "= 0.114.0-pre" } diff --git a/script/testdata/Makefile b/script/testdata/Makefile index 70567978d3..59eebd1032 100644 --- a/script/testdata/Makefile +++ b/script/testdata/Makefile @@ -9,11 +9,15 @@ LIB_TARGET := riscv64-unknown-linux-gnu LIB_CC := $(LIB_TARGET)-gcc LIB_OBJCOPY := $(LIB_TARGET)-objcopy -# Tip: add `-DDEBUG` to enable the debug outputs COMMON_CFLAGS := -O3 \ -I deps/ckb-c-stdlib \ -I deps/ckb-c-stdlib/molecule \ - -Wall -Werror -g + -Wall -Werror +# enable log +COMMON_CFLAGS += -DCKB_C_STDLIB_PRINTF -DCKB_C_STDLIB_PRINTF_BUFFER_SIZE=1024 +# enable debug +# COMMON_CFLAGS += -g + BIN_CFLAGS := $(COMMON_CFLAGS) LIB_CFLAGS := -shared -fPIC -nostdlib -nostartfiles -fvisibility=hidden $(COMMON_CFLAGS) @@ -21,8 +25,6 @@ COMMON_LDFLAGS := -Wl,-static -fdata-sections -ffunction-sections -Wl,--gc-secti BIN_LDFLAGS := $(COMMON_LDFLAGS) LIB_LDFLAGS := $(COMMON_LDFLAGS) -OBJCOPY_FLAGS := --strip-debug --strip-all - # nervos/ckb-riscv-gnu-toolchain:bionic-20210804 BIN_BUILDER_DOCKER := nervos/ckb-riscv-gnu-toolchain@sha256:cfeb97864cf2039a0900bfa83c3f112a780b2281bded395604b8a8a693c95e08 # nervos/ckb-riscv-gnu-toolchain:gnu-bionic-20210727 @@ -50,32 +52,8 @@ ALL_BINS := jalr_zero \ load_is_even_into_global \ load_is_even_with_snapshot \ load_arithmetic \ - debugger \ - get_memory_limit \ - set_content \ - spawn_big_content_length \ - spawn_big_memory_size \ - spawn_callee_exec_callee \ - spawn_callee_exec_caller \ - spawn_callee_get_memory_limit \ - spawn_callee_out_of_cycles \ - spawn_callee_set_content \ - spawn_callee_strcat \ - spawn_caller_exec \ - spawn_caller_get_memory_limit \ - spawn_caller_out_of_cycles \ - spawn_caller_out_of_cycles_wrap \ - spawn_caller_set_content \ - spawn_caller_strcat_wrap \ - spawn_caller_strcat \ - spawn_caller_strcat_data_hash \ - spawn_recursive \ - spawn_current_memory \ - spawn_caller_current_cycles \ - spawn_callee_current_cycles \ - spawn_peak_memory_512k_to_32m \ - spawn_peak_memory_2m_to_32m \ - spawn_peak_memory_4m_to_32m + debugger + ALL_LIBS := is_even.lib \ add1.lib sub1.lib mul2.lib div2.lib @@ -99,24 +77,20 @@ clean: clean-bins clean-libs %: %.c $(BIN_CC) $(BIN_CFLAGS) $(BIN_LDFLAGS) -o $@ $< - $(BIN_OBJCOPY) $(OBJCOPY_FLAGS) $@ %.lib: %.c $(LIB_CC) $(LIB_CFLAGS) $(LIB_LDFLAGS) -o $@ $< - $(LIB_OBJCOPY) $(OBJCOPY_FLAGS) $@ %: %.S $(BIN_AS) -o $@.o $< $(BIN_LD) -o $@ $@.o @rm $@.o - $(BIN_OBJCOPY) $(OBJCOPY_FLAGS) $@ jalr_zero: jalr_zero.S cadd_hint_lock: cadd_hint_lock.S $(BIN_AS) -march=rv64imc -o $@.o $< $(BIN_LD) -o $@ $@.o @rm $@.o - $(BIN_OBJCOPY) $(OBJCOPY_FLAGS) $@ cpop_lock: cpop_lock.c mop_adc_lock: mop_adc_lock.S current_cycles: current_cycles.c @@ -140,29 +114,3 @@ sub1.lib: sub1.c mul2.lib: mul2.c div2.lib: div2.c load_arithmetic: load_arithmetic.c - -get_memory_limit: get_memory_limit.c -set_content: set_content.c -spawn_big_content_length: spawn_big_content_length.c -spawn_big_memory_size: spawn_big_memory_size.c -spawn_callee_current_cycles: spawn_callee_current_cycles.c -spawn_callee_exec_callee: spawn_callee_exec_callee.c -spawn_callee_exec_caller: spawn_callee_exec_caller.c -spawn_callee_get_memory_limit: spawn_callee_get_memory_limit.c -spawn_callee_out_of_cycles: spawn_callee_out_of_cycles.c -spawn_callee_set_content: spawn_callee_out_of_cycles.c -spawn_callee_strcat: spawn_callee_strcat.c -spawn_caller_current_cycles: spawn_caller_current_cycles.c -spawn_caller_exec: spawn_caller_exec.c -spawn_caller_get_memory_limit: spawn_caller_get_memory_limit.c -spawn_caller_out_of_cycles: spawn_caller_out_of_cycles.c -spawn_caller_out_of_cycles_wrap: spawn_caller_out_of_cycles_wrap.c -spawn_caller_set_content: spawn_caller_set_content.c -spawn_caller_strcat_wrap: spawn_caller_strcat_wrap.c -spawn_caller_strcat: spawn_caller_strcat.c -spawn_caller_strcat_data_hash: spawn_caller_strcat_data_hash.c -spawn_peak_memory_512k_to_32m: spawn_peak_memory_512k_to_32m.c -spawn_peak_memory_2m_to_32m: spawn_peak_memory_2m_to_32m.c -spawn_peak_memory_4m_to_32m: spawn_peak_memory_4m_to_32m.c -spawn_recursive: spawn_recursive.c -spawn_current_memory: spawn_current_memory.c diff --git a/script/testdata/README.md b/script/testdata/README.md index ce35495eb8..d4964cb16d 100644 --- a/script/testdata/README.md +++ b/script/testdata/README.md @@ -4,7 +4,7 @@ - Create a directory named `deps`. - - Clone https://github.com/nervosnetwork/ckb-c-stdlib into `deps`. + - Clone https://github.com/XuJiandong/ckb-c-stdlib.git with branch `syscall-spawn` into `deps`. - Build all scripts with `docker`. diff --git a/script/testdata/add1.lib b/script/testdata/add1.lib index 1c916b0a73..e6cd7e9c06 100755 Binary files a/script/testdata/add1.lib and b/script/testdata/add1.lib differ diff --git a/script/testdata/cadd_hint_lock b/script/testdata/cadd_hint_lock index 1f46b6b2ee..0a365e08a4 100755 Binary files a/script/testdata/cadd_hint_lock and b/script/testdata/cadd_hint_lock differ diff --git a/script/testdata/cpop_lock b/script/testdata/cpop_lock index cce506539f..ca9ac0deb7 100755 Binary files a/script/testdata/cpop_lock and b/script/testdata/cpop_lock differ diff --git a/script/testdata/current_cycles b/script/testdata/current_cycles index c524f6d090..8880779257 100755 Binary files a/script/testdata/current_cycles and b/script/testdata/current_cycles differ diff --git a/script/testdata/current_cycles_with_snapshot b/script/testdata/current_cycles_with_snapshot index 62e6752e66..e3c1e26055 100755 Binary files a/script/testdata/current_cycles_with_snapshot and b/script/testdata/current_cycles_with_snapshot differ diff --git a/script/testdata/debugger b/script/testdata/debugger index c0ef526adc..4563af5333 100755 Binary files a/script/testdata/debugger and b/script/testdata/debugger differ diff --git a/script/testdata/div2.lib b/script/testdata/div2.lib index 1775b76a35..d631c7773a 100755 Binary files a/script/testdata/div2.lib and b/script/testdata/div2.lib differ diff --git a/script/testdata/exec_callee b/script/testdata/exec_callee index 81c802765d..776580d800 100755 Binary files a/script/testdata/exec_callee and b/script/testdata/exec_callee differ diff --git a/script/testdata/exec_caller_big_offset_length b/script/testdata/exec_caller_big_offset_length index 1ea87c14ca..659dd922da 100755 Binary files a/script/testdata/exec_caller_big_offset_length and b/script/testdata/exec_caller_big_offset_length differ diff --git a/script/testdata/exec_caller_from_cell_data b/script/testdata/exec_caller_from_cell_data index 64fa89fc73..08f075eac5 100755 Binary files a/script/testdata/exec_caller_from_cell_data and b/script/testdata/exec_caller_from_cell_data differ diff --git a/script/testdata/exec_caller_from_witness b/script/testdata/exec_caller_from_witness index a22f978254..ac4ad0f26e 100755 Binary files a/script/testdata/exec_caller_from_witness and b/script/testdata/exec_caller_from_witness differ diff --git a/script/testdata/exec_configurable_callee b/script/testdata/exec_configurable_callee index c99bb78cad..69b97ca6d1 100755 Binary files a/script/testdata/exec_configurable_callee and b/script/testdata/exec_configurable_callee differ diff --git a/script/testdata/exec_configurable_caller b/script/testdata/exec_configurable_caller index 911eb8d274..80d9137fcd 100755 Binary files a/script/testdata/exec_configurable_caller and b/script/testdata/exec_configurable_caller differ diff --git a/script/testdata/get_memory_limit b/script/testdata/get_memory_limit deleted file mode 100755 index fbf37219f1..0000000000 Binary files a/script/testdata/get_memory_limit and /dev/null differ diff --git a/script/testdata/get_memory_limit.c b/script/testdata/get_memory_limit.c deleted file mode 100644 index a148ad4713..0000000000 --- a/script/testdata/get_memory_limit.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "ckb_syscalls.h" - -int main() { - if (ckb_get_memory_limit() == 8) { - return 0; - } - return 1; -} diff --git a/script/testdata/infinite_loop b/script/testdata/infinite_loop index 99cd4f7350..587db81534 100755 Binary files a/script/testdata/infinite_loop and b/script/testdata/infinite_loop differ diff --git a/script/testdata/is_even.lib b/script/testdata/is_even.lib index 07b308138a..9e45b77c71 100755 Binary files a/script/testdata/is_even.lib and b/script/testdata/is_even.lib differ diff --git a/script/testdata/jalr_zero b/script/testdata/jalr_zero index f77b85d85c..77a89a48d4 100755 Binary files a/script/testdata/jalr_zero and b/script/testdata/jalr_zero differ diff --git a/script/testdata/load_arithmetic b/script/testdata/load_arithmetic index 650df9295c..b1fcd181cf 100755 Binary files a/script/testdata/load_arithmetic and b/script/testdata/load_arithmetic differ diff --git a/script/testdata/load_code_to_stack_then_reuse b/script/testdata/load_code_to_stack_then_reuse index 494dcd1a4b..2b01578d4f 100755 Binary files a/script/testdata/load_code_to_stack_then_reuse and b/script/testdata/load_code_to_stack_then_reuse differ diff --git a/script/testdata/load_is_even_into_global b/script/testdata/load_is_even_into_global index 9fba1493f2..1c50a9b40f 100755 Binary files a/script/testdata/load_is_even_into_global and b/script/testdata/load_is_even_into_global differ diff --git a/script/testdata/load_is_even_with_snapshot b/script/testdata/load_is_even_with_snapshot index 16d2b05393..5543b99481 100755 Binary files a/script/testdata/load_is_even_with_snapshot and b/script/testdata/load_is_even_with_snapshot differ diff --git a/script/testdata/mop_adc_lock b/script/testdata/mop_adc_lock index d24fad349c..6593665e13 100755 Binary files a/script/testdata/mop_adc_lock and b/script/testdata/mop_adc_lock differ diff --git a/script/testdata/mul2.lib b/script/testdata/mul2.lib index 4ce9d55c69..889d6cf06d 100755 Binary files a/script/testdata/mul2.lib and b/script/testdata/mul2.lib differ diff --git a/script/testdata/set_content b/script/testdata/set_content deleted file mode 100755 index 63b8d7ef3e..0000000000 Binary files a/script/testdata/set_content and /dev/null differ diff --git a/script/testdata/set_content.c b/script/testdata/set_content.c deleted file mode 100644 index b6b80a211b..0000000000 --- a/script/testdata/set_content.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "ckb_syscalls.h" - -int main() { - uint64_t length = 5; - if (ckb_set_content((uint8_t *)"hello", &length) != 0) { - return 1; - } - if (length != 0) { - return 1; - } - return 0; -} diff --git a/script/testdata/spawn_big_content_length b/script/testdata/spawn_big_content_length deleted file mode 100755 index 0b63b00c4d..0000000000 Binary files a/script/testdata/spawn_big_content_length and /dev/null differ diff --git a/script/testdata/spawn_big_content_length.c b/script/testdata/spawn_big_content_length.c deleted file mode 100644 index 2620b5e15c..0000000000 --- a/script/testdata/spawn_big_content_length.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include - -#include "ckb_syscalls.h" - -int main() { - uint64_t spawn_content_length = 0xffffffff; - spawn_args_t spgs = { - .memory_limit = 8, - .exit_code = NULL, - .content = NULL, - .content_length = &spawn_content_length, - }; - int success = ckb_spawn(1, 3, 0, 0, NULL, &spgs); - if (success != 5) { - return 1; - } - return 0; -} diff --git a/script/testdata/spawn_big_memory_size b/script/testdata/spawn_big_memory_size deleted file mode 100755 index 7c0b7f8ebf..0000000000 Binary files a/script/testdata/spawn_big_memory_size and /dev/null differ diff --git a/script/testdata/spawn_big_memory_size.c b/script/testdata/spawn_big_memory_size.c deleted file mode 100644 index d1b9b0e33c..0000000000 --- a/script/testdata/spawn_big_memory_size.c +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include - -#include "ckb_syscalls.h" - -int main() { - spawn_args_t spgs = { - .memory_limit = 9, - .exit_code = NULL, - .content = NULL, - .content_length = NULL, - }; - int success = ckb_spawn(1, 3, 0, 0, NULL, &spgs); - if (success != 6) { - return 1; - } - return 0; -} diff --git a/script/testdata/spawn_callee_current_cycles b/script/testdata/spawn_callee_current_cycles deleted file mode 100755 index 1c2dd40aa0..0000000000 Binary files a/script/testdata/spawn_callee_current_cycles and /dev/null differ diff --git a/script/testdata/spawn_callee_current_cycles.c b/script/testdata/spawn_callee_current_cycles.c deleted file mode 100644 index c2005c9da4..0000000000 --- a/script/testdata/spawn_callee_current_cycles.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -#include - -#include "ckb_syscalls.h" - -int main(int argc, char *argv[]) { - int caller_cycles = atoi(argv[0]); - // Callee's current cycles must > caller's current cycles. - int callee_cycles = ckb_current_cycles(); - if (callee_cycles < caller_cycles + 100000) { - return 1; - } - return 0; -} diff --git a/script/testdata/spawn_callee_exec_callee b/script/testdata/spawn_callee_exec_callee deleted file mode 100755 index 1686432359..0000000000 Binary files a/script/testdata/spawn_callee_exec_callee and /dev/null differ diff --git a/script/testdata/spawn_callee_exec_callee.c b/script/testdata/spawn_callee_exec_callee.c deleted file mode 100644 index 76e8197013..0000000000 --- a/script/testdata/spawn_callee_exec_callee.c +++ /dev/null @@ -1 +0,0 @@ -int main() { return 0; } diff --git a/script/testdata/spawn_callee_exec_caller b/script/testdata/spawn_callee_exec_caller deleted file mode 100755 index 0a3f6b6016..0000000000 Binary files a/script/testdata/spawn_callee_exec_caller and /dev/null differ diff --git a/script/testdata/spawn_callee_exec_caller.c b/script/testdata/spawn_callee_exec_caller.c deleted file mode 100644 index 22723c1f0d..0000000000 --- a/script/testdata/spawn_callee_exec_caller.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "ckb_syscalls.h" - -int main() { - syscall(2043, 2, 3, 0, 0, 0, NULL); - return -1; -} diff --git a/script/testdata/spawn_callee_get_memory_limit b/script/testdata/spawn_callee_get_memory_limit deleted file mode 100755 index 94b6c711f7..0000000000 Binary files a/script/testdata/spawn_callee_get_memory_limit and /dev/null differ diff --git a/script/testdata/spawn_callee_get_memory_limit.c b/script/testdata/spawn_callee_get_memory_limit.c deleted file mode 100644 index 574544f877..0000000000 --- a/script/testdata/spawn_callee_get_memory_limit.c +++ /dev/null @@ -1,3 +0,0 @@ -#include "ckb_syscalls.h" - -int main() { return ckb_get_memory_limit(); } diff --git a/script/testdata/spawn_callee_out_of_cycles b/script/testdata/spawn_callee_out_of_cycles deleted file mode 100755 index c0819018bb..0000000000 Binary files a/script/testdata/spawn_callee_out_of_cycles and /dev/null differ diff --git a/script/testdata/spawn_callee_out_of_cycles.c b/script/testdata/spawn_callee_out_of_cycles.c deleted file mode 100644 index dbaa71d22a..0000000000 --- a/script/testdata/spawn_callee_out_of_cycles.c +++ /dev/null @@ -1,8 +0,0 @@ -int fib(int n) { - if (n < 2) { - return n; - } - return fib(n - 1) + fib(n - 2); -} - -int main() { return fib(100); } diff --git a/script/testdata/spawn_callee_set_content b/script/testdata/spawn_callee_set_content deleted file mode 100755 index b66210df7b..0000000000 Binary files a/script/testdata/spawn_callee_set_content and /dev/null differ diff --git a/script/testdata/spawn_callee_set_content.c b/script/testdata/spawn_callee_set_content.c deleted file mode 100644 index ed376ba5ce..0000000000 --- a/script/testdata/spawn_callee_set_content.c +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include - -#include "ckb_syscalls.h" - -int main(int argc, char *argv[]) { - uint64_t size = (uint64_t)atoi(argv[0]); - uint64_t real = (uint64_t)atoi(argv[1]); - uint8_t data[20] = {}; - int success = ckb_set_content(&data[0], &size); - if (success != 0) { - return 1; - } - if (size != real) { - return 1; - } - return 0; -} diff --git a/script/testdata/spawn_callee_strcat b/script/testdata/spawn_callee_strcat deleted file mode 100755 index ecc962b30c..0000000000 Binary files a/script/testdata/spawn_callee_strcat and /dev/null differ diff --git a/script/testdata/spawn_callee_strcat.c b/script/testdata/spawn_callee_strcat.c deleted file mode 100644 index f2f3f56e6c..0000000000 --- a/script/testdata/spawn_callee_strcat.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -#include "ckb_syscalls.h" - -int main(int argc, char *argv[]) { - char content[80]; - for (int i = 0; i < argc; i++) { - strcat(content, argv[i]); - } - uint64_t content_size = (uint64_t)strlen(content); - ckb_set_content((uint8_t *)&content[0], &content_size); - if (content_size != (uint64_t)strlen(content)) { - return 1; - } - return 0; -} diff --git a/script/testdata/spawn_caller_current_cycles b/script/testdata/spawn_caller_current_cycles deleted file mode 100755 index efa2fcec4d..0000000000 Binary files a/script/testdata/spawn_caller_current_cycles and /dev/null differ diff --git a/script/testdata/spawn_caller_current_cycles.c b/script/testdata/spawn_caller_current_cycles.c deleted file mode 100644 index f508cd3966..0000000000 --- a/script/testdata/spawn_caller_current_cycles.c +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include -#include - -#include "ckb_syscalls.h" - -int fib(int n) { - if (n < 2) { - return n; - } - return fib(n - 1) + fib(n - 2); -} - -int main() { - // Use invalid calculations to make the current cycles a larger value. - if (fib(20) != 6765) { - return 1; - } - - int cycles = ckb_current_cycles(); - char buffer[8]; - itoa(cycles, buffer, 10); - const char *argv[] = { &buffer[0] }; - int8_t spawn_exit_code = 255; - uint8_t spawn_content[80] = {}; - uint64_t spawn_content_length = 80; - spawn_args_t spgs = { - .memory_limit = 8, - .exit_code = &spawn_exit_code, - .content = &spawn_content[0], - .content_length = &spawn_content_length, - }; - int success = ckb_spawn(1, 3, 0, 1, argv, &spgs); - if (success != 0) { - return 1; - } - if (spawn_exit_code != 0) { - return 1; - } - return 0; -} diff --git a/script/testdata/spawn_caller_exec b/script/testdata/spawn_caller_exec deleted file mode 100755 index 429e98b60b..0000000000 Binary files a/script/testdata/spawn_caller_exec and /dev/null differ diff --git a/script/testdata/spawn_caller_exec.c b/script/testdata/spawn_caller_exec.c deleted file mode 100644 index 614342713f..0000000000 --- a/script/testdata/spawn_caller_exec.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include - -#include "ckb_syscalls.h" - -int main() { - spawn_args_t spgs = { - .memory_limit = 8, - .exit_code = NULL, - .content = NULL, - .content_length = NULL, - }; - return ckb_spawn(1, 3, 0, 0, NULL, &spgs); -} diff --git a/script/testdata/spawn_caller_get_memory_limit b/script/testdata/spawn_caller_get_memory_limit deleted file mode 100755 index 5b600a24e6..0000000000 Binary files a/script/testdata/spawn_caller_get_memory_limit and /dev/null differ diff --git a/script/testdata/spawn_caller_get_memory_limit.c b/script/testdata/spawn_caller_get_memory_limit.c deleted file mode 100644 index 6b6ea48662..0000000000 --- a/script/testdata/spawn_caller_get_memory_limit.c +++ /dev/null @@ -1,46 +0,0 @@ -#include -#include - -#include "ckb_syscalls.h" - -int main() { - int8_t spawn_exit_code; - uint8_t spawn_content[80] = {}; - uint64_t spawn_content_length = 80; - spawn_args_t spgs = { - .memory_limit = 0, - .exit_code = &spawn_exit_code, - .content = &spawn_content[0], - .content_length = &spawn_content_length, - }; - uint64_t success = 0; - - spgs.memory_limit = 3; - success = ckb_spawn(1, 3, 0, 0, NULL, &spgs); - if (success != 0) { - return 1; - } - if (spawn_exit_code != 3) { - return 1; - } - - spgs.memory_limit = 7; - success = ckb_spawn(1, 3, 0, 0, NULL, &spgs); - if (success != 0) { - return 1; - } - if (spawn_exit_code != 7) { - return 1; - } - - spgs.memory_limit = 8; - success = ckb_spawn(1, 3, 0, 0, NULL, &spgs); - if (success != 0) { - return 1; - } - if (spawn_exit_code != 8) { - return 1; - } - - return 0; -} diff --git a/script/testdata/spawn_caller_out_of_cycles b/script/testdata/spawn_caller_out_of_cycles deleted file mode 100755 index d4ac5f515c..0000000000 Binary files a/script/testdata/spawn_caller_out_of_cycles and /dev/null differ diff --git a/script/testdata/spawn_caller_out_of_cycles.c b/script/testdata/spawn_caller_out_of_cycles.c deleted file mode 100644 index 3818a84001..0000000000 --- a/script/testdata/spawn_caller_out_of_cycles.c +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include - -#include "ckb_syscalls.h" - -int main() { - spawn_args_t spgs = { - .memory_limit = 8, - .exit_code = NULL, - .content = NULL, - .content_length = NULL, - }; - uint64_t success = ckb_spawn(1, 3, 0, 0, NULL, &spgs); - if (success == 0) { - return 1; - } - return 0; -} diff --git a/script/testdata/spawn_caller_out_of_cycles_wrap b/script/testdata/spawn_caller_out_of_cycles_wrap deleted file mode 100755 index 1c3a8da922..0000000000 Binary files a/script/testdata/spawn_caller_out_of_cycles_wrap and /dev/null differ diff --git a/script/testdata/spawn_caller_out_of_cycles_wrap.c b/script/testdata/spawn_caller_out_of_cycles_wrap.c deleted file mode 100644 index bbb717e58c..0000000000 --- a/script/testdata/spawn_caller_out_of_cycles_wrap.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include - -#include "ckb_syscalls.h" - -int main() { - int8_t spawn_exit_code = 255; - spawn_args_t spgs = { - .memory_limit = 8, - .exit_code = &spawn_exit_code, - .content = NULL, - .content_length = NULL, - }; - uint64_t success = ckb_spawn(2, 3, 0, 0, NULL, &spgs); - if (success != 0) { - return 1; - } - return spawn_exit_code; -} diff --git a/script/testdata/spawn_caller_set_content b/script/testdata/spawn_caller_set_content deleted file mode 100755 index f610c38817..0000000000 Binary files a/script/testdata/spawn_caller_set_content and /dev/null differ diff --git a/script/testdata/spawn_caller_set_content.c b/script/testdata/spawn_caller_set_content.c deleted file mode 100644 index 026ef1bcfa..0000000000 --- a/script/testdata/spawn_caller_set_content.c +++ /dev/null @@ -1,95 +0,0 @@ -#include -#include - -#include "ckb_syscalls.h" - -int main_lt_content_length() { - int8_t spawn_exit_code = -1; - uint8_t spawn_content[10] = {}; - uint64_t spawn_content_length = 10; - spawn_args_t spgs = { - .memory_limit = 8, - .exit_code = &spawn_exit_code, - .content = &spawn_content[0], - .content_length = &spawn_content_length, - }; - const char *argv[] = {"8", "8"}; - uint64_t success = 0; - - success = ckb_spawn(1, 3, 0, 2, argv, &spgs); - if (success != 0) { - return 1; - } - if (spawn_exit_code != 0) { - return 1; - } - if (spawn_content_length != 8) { - return 1; - } - return 0; -} - -int main_eq_content_length() { - int8_t spawn_exit_code = -1; - uint8_t spawn_content[10] = {}; - uint64_t spawn_content_length = 10; - spawn_args_t spgs = { - .memory_limit = 8, - .exit_code = &spawn_exit_code, - .content = &spawn_content[0], - .content_length = &spawn_content_length, - }; - const char *argv[] = {"10", "10"}; - uint64_t success = 0; - - success = ckb_spawn(1, 3, 0, 2, argv, &spgs); - if (success != 0) { - return 1; - } - if (spawn_exit_code != 0) { - return 1; - } - if (spawn_content_length != 10) { - return 1; - } - return 0; -} - -int main_gt_content_length() { - int8_t spawn_exit_code = -1; - uint8_t spawn_content[10] = {}; - uint64_t spawn_content_length = 10; - spawn_args_t spgs = { - .memory_limit = 8, - .exit_code = &spawn_exit_code, - .content = &spawn_content[0], - .content_length = &spawn_content_length, - }; - const char *argv[] = {"12", "10"}; - uint64_t success = 0; - - success = ckb_spawn(1, 3, 0, 2, argv, &spgs); - if (success != 0) { - return 1; - } - if (spawn_exit_code != 0) { - return 1; - } - if (spawn_content_length != 10) { - return 1; - } - return 0; -} - -int main() { - if (main_lt_content_length() != 0) { - return 1; - } - if (main_eq_content_length() != 0) { - return 1; - } - if (main_gt_content_length() != 0) { - return 1; - } - return 0; -} diff --git a/script/testdata/spawn_caller_strcat b/script/testdata/spawn_caller_strcat deleted file mode 100755 index 1e1ed6edb3..0000000000 Binary files a/script/testdata/spawn_caller_strcat and /dev/null differ diff --git a/script/testdata/spawn_caller_strcat.c b/script/testdata/spawn_caller_strcat.c deleted file mode 100644 index 466547502d..0000000000 --- a/script/testdata/spawn_caller_strcat.c +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include - -#include "ckb_syscalls.h" - -int main() { - const char *argv[] = {"hello", "world"}; - int8_t spawn_exit_code = 255; - uint8_t spawn_content[80] = {}; - uint64_t spawn_content_length = 80; - spawn_args_t spgs = { - .memory_limit = 8, - .exit_code = &spawn_exit_code, - .content = &spawn_content[0], - .content_length = &spawn_content_length, - }; - int success = ckb_spawn(1, 3, 0, 2, argv, &spgs); - if (success != 0) { - return 1; - } - if (spawn_exit_code != 0) { - return 1; - } - if (strlen((char *)spawn_content) != 10) { - return 1; - } - if (strcmp((char *)spawn_content, "helloworld") != 0) { - return 1; - } - return 0; -} diff --git a/script/testdata/spawn_caller_strcat_data_hash b/script/testdata/spawn_caller_strcat_data_hash deleted file mode 100755 index 9d32803cd0..0000000000 Binary files a/script/testdata/spawn_caller_strcat_data_hash and /dev/null differ diff --git a/script/testdata/spawn_caller_strcat_data_hash.c b/script/testdata/spawn_caller_strcat_data_hash.c deleted file mode 100644 index f21987dffc..0000000000 --- a/script/testdata/spawn_caller_strcat_data_hash.c +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include -#include - -#include "ckb_exec.h" -#include "ckb_syscalls.h" - -int main() { - const char *argv[] = {"hello", "world"}; - - int8_t spawn_exit_code = -1; - uint8_t spawn_content[80] = {}; - uint64_t spawn_content_length = 80; - spawn_args_t spgs = { - .memory_limit = 8, - .exit_code = &spawn_exit_code, - .content = &spawn_content[0], - .content_length = &spawn_content_length, - }; - uint8_t hash[32] = {}; - uint32_t hash_len = 0; - _exec_hex2bin( - "1dc91c6a0d93ffba6d11bae8bc74d4cb89506e58203e7361434e77f24eb7b11f", hash, - 32, &hash_len); - int success = ckb_spawn_cell(hash, 0, 0, 0, 2, argv, &spgs); - if (success != 0) { - return 1; - } - if (spawn_exit_code != 0) { - return 1; - } - if (strlen((char *)spawn_content) != 10) { - return 1; - } - if (strcmp((char *)spawn_content, "helloworld") != 0) { - return 1; - } - return 0; -} diff --git a/script/testdata/spawn_caller_strcat_wrap b/script/testdata/spawn_caller_strcat_wrap deleted file mode 100755 index 1c3a8da922..0000000000 Binary files a/script/testdata/spawn_caller_strcat_wrap and /dev/null differ diff --git a/script/testdata/spawn_caller_strcat_wrap.c b/script/testdata/spawn_caller_strcat_wrap.c deleted file mode 100644 index bbb717e58c..0000000000 --- a/script/testdata/spawn_caller_strcat_wrap.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include - -#include "ckb_syscalls.h" - -int main() { - int8_t spawn_exit_code = 255; - spawn_args_t spgs = { - .memory_limit = 8, - .exit_code = &spawn_exit_code, - .content = NULL, - .content_length = NULL, - }; - uint64_t success = ckb_spawn(2, 3, 0, 0, NULL, &spgs); - if (success != 0) { - return 1; - } - return spawn_exit_code; -} diff --git a/script/testdata/spawn_current_memory b/script/testdata/spawn_current_memory deleted file mode 100755 index 417eaca599..0000000000 Binary files a/script/testdata/spawn_current_memory and /dev/null differ diff --git a/script/testdata/spawn_current_memory.c b/script/testdata/spawn_current_memory.c deleted file mode 100644 index b09c62cb0e..0000000000 --- a/script/testdata/spawn_current_memory.c +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include - -#include "ckb_syscalls.h" - -int main(int argc, char *argv[]) { - int peak_memory = ckb_current_memory(); - if (peak_memory != (argc + 1) * 8) { - return 1; - } - if (peak_memory < 56) { - int spawn_argc = argc + 1; - const char *spawn_argv[] = {"", "", "", "", "", "", "", ""}; - int8_t spawn_exit_code = 255; - spawn_args_t spgs = { - .memory_limit = 8, - .exit_code = &spawn_exit_code, - .content = NULL, - .content_length = NULL, - }; - uint64_t success = ckb_spawn(0, 3, 0, spawn_argc, spawn_argv, &spgs); - if (success != 0) { - return success; - } - } else { - return 0; - } -} diff --git a/script/testdata/spawn_peak_memory_2m_to_32m b/script/testdata/spawn_peak_memory_2m_to_32m deleted file mode 100755 index ebe14775db..0000000000 Binary files a/script/testdata/spawn_peak_memory_2m_to_32m and /dev/null differ diff --git a/script/testdata/spawn_peak_memory_2m_to_32m.c b/script/testdata/spawn_peak_memory_2m_to_32m.c deleted file mode 100644 index 11beb1e02a..0000000000 --- a/script/testdata/spawn_peak_memory_2m_to_32m.c +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include -#include - -#include "ckb_syscalls.h" - -int main(int argc, char *argv[]) { - int8_t spawn_exit_code = 255; - spawn_args_t spgs = { - .memory_limit = 4, - .exit_code = &spawn_exit_code, - .content = NULL, - .content_length = NULL, - }; - int8_t can_i_spawn = 0; - if (argc == 0) { - can_i_spawn = 1; - } - uint64_t depth = (uint64_t)atoi(argv[0]); - if (depth < 14) { - can_i_spawn = 1; - } - if (can_i_spawn) { - char buffer[20]; - itoa(depth + 1, buffer, 10); - const char *argv[] = {buffer}; - uint64_t success = ckb_spawn(0, 3, 0, 1, argv, &spgs); - if (success != 0) { - return success; - } - if (spawn_exit_code != 0) { - return 1; - } - } - return 0; -} diff --git a/script/testdata/spawn_peak_memory_4m_to_32m b/script/testdata/spawn_peak_memory_4m_to_32m deleted file mode 100755 index 28d8274b57..0000000000 Binary files a/script/testdata/spawn_peak_memory_4m_to_32m and /dev/null differ diff --git a/script/testdata/spawn_peak_memory_4m_to_32m.c b/script/testdata/spawn_peak_memory_4m_to_32m.c deleted file mode 100644 index bd91167ce0..0000000000 --- a/script/testdata/spawn_peak_memory_4m_to_32m.c +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include -#include - -#include "ckb_syscalls.h" - -int main(int argc, char *argv[]) { - int8_t spawn_exit_code = 255; - spawn_args_t spgs = { - .memory_limit = 8, - .exit_code = &spawn_exit_code, - .content = NULL, - .content_length = NULL, - }; - int8_t can_i_spawn = 0; - if (argc == 0) { - can_i_spawn = 1; - } - uint64_t depth = (uint64_t)atoi(argv[0]); - if (depth < 7) { - can_i_spawn = 1; - } - if (can_i_spawn) { - char buffer[20]; - itoa(depth + 1, buffer, 10); - const char *argv[] = {buffer}; - uint64_t success = ckb_spawn(0, 3, 0, 1, argv, &spgs); - if (success != 0) { - return success; - } - if (spawn_exit_code != 0) { - return 1; - } - } - return 0; -} diff --git a/script/testdata/spawn_peak_memory_512k_to_32m b/script/testdata/spawn_peak_memory_512k_to_32m deleted file mode 100755 index 118c5ab1d3..0000000000 Binary files a/script/testdata/spawn_peak_memory_512k_to_32m and /dev/null differ diff --git a/script/testdata/spawn_peak_memory_512k_to_32m.c b/script/testdata/spawn_peak_memory_512k_to_32m.c deleted file mode 100644 index 21680926ce..0000000000 --- a/script/testdata/spawn_peak_memory_512k_to_32m.c +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include -#include - -#include "ckb_syscalls.h" - -int main(int argc, char *argv[]) { - int8_t spawn_exit_code = 255; - spawn_args_t spgs = { - .memory_limit = 1, - .exit_code = &spawn_exit_code, - .content = NULL, - .content_length = NULL, - }; - int8_t can_i_spawn = 0; - if (argc == 0) { - can_i_spawn = 1; - } - uint64_t depth = (uint64_t)atoi(argv[0]); - if (depth < 56) { - can_i_spawn = 1; - } - if (can_i_spawn) { - char buffer[20]; - itoa(depth + 1, buffer, 10); - const char *argv[] = {buffer}; - uint64_t success = ckb_spawn(0, 3, 0, 1, argv, &spgs); - if (success != 0) { - return success; - } - if (spawn_exit_code != 0) { - return 1; - } - } - return 0; -} diff --git a/script/testdata/spawn_recursive b/script/testdata/spawn_recursive deleted file mode 100755 index ce415ca010..0000000000 Binary files a/script/testdata/spawn_recursive and /dev/null differ diff --git a/script/testdata/spawn_recursive.c b/script/testdata/spawn_recursive.c deleted file mode 100644 index 8b3510572a..0000000000 --- a/script/testdata/spawn_recursive.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include - -#include "ckb_syscalls.h" - -int main() { - int8_t spawn_exit_code = 255; - spawn_args_t spgs = { - .memory_limit = 8, - .exit_code = &spawn_exit_code, - .content = NULL, - .content_length = NULL, - }; - uint64_t success = ckb_spawn(0, 3, 0, 0, NULL, &spgs); - if (success != 0) { - return success; - } - return spawn_exit_code; -} diff --git a/script/testdata/spawn_times b/script/testdata/spawn_times deleted file mode 100755 index c7dcd39e58..0000000000 Binary files a/script/testdata/spawn_times and /dev/null differ diff --git a/script/testdata/spawn_times.md b/script/testdata/spawn_times.md deleted file mode 100644 index 351817947d..0000000000 --- a/script/testdata/spawn_times.md +++ /dev/null @@ -1,81 +0,0 @@ -This binary comes from: . Since I couldn't build a binary in C that would cause the same bug, I just added the binary to the project. - -```rs -#![no_std] -#![cfg_attr(not(test), no_main)] - -#[cfg(test)] -extern crate alloc; - -#[cfg(not(test))] -use ckb_std::default_alloc; -#[cfg(not(test))] -ckb_std::entry!(program_entry); -#[cfg(not(test))] -default_alloc!(); - -use core::result::Result; - -use alloc::{vec}; -use core::ffi::{CStr}; - -use ckb_std::{debug, syscalls}; -use ckb_std::ckb_constants::Source; -use ckb_std::env::argv; -use ckb_std::syscalls::{current_cycles, get_memory_limit, set_content, spawn}; - - -/// -/// test case : -/// invoke int ckb_spawn( uint64_t memory_limit, -/// size_t index, -/// size_t source, -/// size_t bounds, -/// int argc, char* argv[], -/// int8_t* exit_code, -/// uint8_t* content, -/// uint64_t* content_length); -/// -/// for { -/// spawn(xxx) -/// } -/// case1 : for { -/// spawn(xxx) -/// } -/// -/// result: -/// return ERROR : ExceededMaximumCycles -/// -pub fn program_entry() -> i8 { - // let argvs = argv(); - // debug!("argvs length:{:?}:{:?}",argvs.len(),argvs); - - if get_memory_limit() != 8 { - return 0; - } - let mut exit_code: i8 = 0; - let mut content: [u8; 10] = [1; 10]; - - let content_length: u64 = content.len() as u64; - let mut spawn_args = syscalls::SpawnArgs { - memory_limit: 8, - exit_code: &mut exit_code as *mut i8, - content: content.as_mut_ptr(), - content_length: &content_length as *const u64 as *mut u64, - }; - // let cstr1 = CStr::from_bytes_with_nul(b"arg0\0").unwrap(); - //argv is empty - let cstrs = vec![]; - - spawn_args.memory_limit = 1; - for i in 0..10000 { - debug!("current idx:{:?}",i); - let result = spawn(0, Source::CellDep, 0, cstrs.as_slice(), &spawn_args); - assert_eq!(exit_code, 0); - // debug!("result:{:?}",result); - let cycles = current_cycles(); - debug!("cycle:{:?}",cycles); - } - return 0; -} -``` diff --git a/script/testdata/sub1.lib b/script/testdata/sub1.lib index 9afeae0776..b1a89a227b 100755 Binary files a/script/testdata/sub1.lib and b/script/testdata/sub1.lib differ diff --git a/script/testdata/vm_version b/script/testdata/vm_version index bf39e3d56a..e105dad85c 100755 Binary files a/script/testdata/vm_version and b/script/testdata/vm_version differ diff --git a/script/testdata/vm_version_2 b/script/testdata/vm_version_2 index 13ea61a6ca..e3871ba942 100755 Binary files a/script/testdata/vm_version_2 and b/script/testdata/vm_version_2 differ diff --git a/script/testdata/vm_version_with_snapshot b/script/testdata/vm_version_with_snapshot index 9e16b52a45..7685e8d3ce 100755 Binary files a/script/testdata/vm_version_with_snapshot and b/script/testdata/vm_version_with_snapshot differ