diff --git a/Makefile b/Makefile index e0b977c6..27f13e0e 100644 --- a/Makefile +++ b/Makefile @@ -52,7 +52,7 @@ BUILDER_DOCKER := nervos/ckb-riscv-gnu-toolchain@sha256:7b168b4b109a0f741078a71b all: build/test_contracts build/test_rlp build/generator build/validator build/generator_log build/validator_log build/test_ripemd160 build/blockchain.h build/godwoken.h -all-via-docker: generate-protocol +all-via-docker: generate-protocol fetch-gw-scripts mkdir -p build docker run --rm -v `pwd`:/code -w /code ${BUILDER_DOCKER} make make patch-generator && make patch-generator_log @@ -223,6 +223,16 @@ contract/sudt-erc20-proxy: # then echo "ERC20BIN_SHASUM matches" ; \ # else echo "ERC20BIN_SHASUM does not match" ; exit 1 ; fi +# fetch godwoken-scripts from godwoken-prebuilds image, +# including meta-contract and sudt-contract +PREBUILDS := ghcr.io/nervosnetwork/godwoken-prebuilds:v0.10.7-alphanet +fetch-gw-scripts: + mkdir -p build + docker run --rm -v `pwd`/build:/build-dir \ + $(PREBUILDS) \ + cp -r /scripts/godwoken-scripts /build-dir \ + && echo "Copy godwoken-scripts" + fmt: clang-format -i -style=Google c/**/*.* diff --git a/c/polyjuice.h b/c/polyjuice.h index 34a0ac79..f7d57c35 100644 --- a/c/polyjuice.h +++ b/c/polyjuice.h @@ -767,10 +767,12 @@ int load_globals(gw_context_t* ctx, uint32_t to_id, evmc_call_kind call_kind) { return FATAL_POLYJUICE; } + /** read rollup_script_hash and g_sudt_id from creator account */ memcpy(g_rollup_script_hash, creator_raw_args_seg.ptr, 32); memcpy(&g_sudt_id, creator_raw_args_seg.ptr + 32, sizeof(uint32_t)); debug_print_data("rollup_script_hash", g_rollup_script_hash, 32); debug_print_int("sudt id", g_sudt_id); + return 0; } @@ -1104,7 +1106,8 @@ int handle_message(gw_context_t* ctx, * 2. CALLCODE/DELEGATECALL should skip `handle_transfer`, otherwise * `value transfer` of CALLCODE/DELEGATECALL will be executed twice */ - if (!is_special_call(msg.kind)) { + if (!is_special_call(msg.kind) || + (is_testnet_v0() && ctx->block_info.number < TESTNET_V0_FORK1_BLOCK)) { bool to_address_is_eoa = !to_address_exists || (to_address_exists && code_size == 0); ret = handle_transfer(ctx, &msg, (uint8_t *)g_tx_origin.bytes, diff --git a/c/polyjuice_globals.h b/c/polyjuice_globals.h index 6d9302cf..9c21e969 100644 --- a/c/polyjuice_globals.h +++ b/c/polyjuice_globals.h @@ -1,19 +1,51 @@ #ifndef POLYJUICE_GLOBALS_H #define POLYJUICE_GLOBALS_H -#define POLYJUICE_VERSION "v0.8.12" +#define POLYJUICE_VERSION "v0.8.13" #define POLYJUICE_SHORT_ADDR_LEN 20 /* 32 + 4 + 20 */ #define SCRIPT_ARGS_LEN 56 static uint8_t g_rollup_script_hash[32] = {0}; static uint32_t g_sudt_id = UINT32_MAX; -/* Receipt.contractAddress - The contract address created, if the transaction was a contract creation, otherwise null */ + +/** + * Receipt.contractAddress is the created contract, + * if the transaction was a contract creation, otherwise null + */ static uint32_t g_created_id = UINT32_MAX; static uint8_t g_created_address[20] = {0}; + +/** + * creator_account, known as root account + * @see https://github.com/nervosnetwork/godwoken/blob/develop/docs/life_of_a_polyjuice_transaction.md#root-account--deployment + */ static uint32_t g_creator_account_id = UINT32_MAX; + static evmc_address g_tx_origin = {0}; + static uint8_t g_script_code_hash[32] = {0}; static uint8_t g_script_hash_type = 0xff; +/** + * @brief Hardforks + * + * TESTNET_V0_FORK1 + * fix: CALLCODE and DELEGATECALL should skip transfer + * https://github.com/nervosnetwork/godwoken-polyjuice/commit/c927fb6ce6d5c3632e09bc5de2d1485736c56fe0 + */ +#define TESTNET_V0_FORK1_BLOCK 380000 +bool is_testnet_v0() { + // Godwoken testnet_v0 Rollup script hash: + // 0x4cc2e6526204ae6a2e8fcf12f7ad472f41a1606d5b9624beebd215d780809f6a + static const uint8_t testnet_v0_rollup_script_hash[32] = { + 0x4c, 0xc2, 0xe6, 0x52, 0x62, 0x04, 0xae, 0x6a, + 0x2e, 0x8f, 0xcf, 0x12, 0xf7, 0xad, 0x47, 0x2f, + 0x41, 0xa1, 0x60, 0x6d, 0x5b, 0x96, 0x24, 0xbe, + 0xeb, 0xd2, 0x15, 0xd7, 0x80, 0x80, 0x9f, 0x6a + }; + + return 0 == memcmp(g_rollup_script_hash, testnet_v0_rollup_script_hash, 32); +} + #endif // POLYJUICE_GLOBALS_H diff --git a/devtools/ci/integration-test.sh b/devtools/ci/integration-test.sh index 5fd9c34f..e4104d42 100644 --- a/devtools/ci/integration-test.sh +++ b/devtools/ci/integration-test.sh @@ -15,8 +15,8 @@ else git clone --depth=1 https://github.com/nervosnetwork/godwoken.git $GODWOKEN_DIR fi cd $GODWOKEN_DIR -# https://github.com/nervosnetwork/godwoken/releases/tag/v0.10.4 -git fetch origin v0.10.4 +# https://github.com/nervosnetwork/godwoken/tree/0.10 +git fetch origin 0.10 git checkout FETCH_HEAD git submodule update --init --recursive --depth=1 @@ -24,16 +24,6 @@ cd $PROJECT_ROOT git submodule update --init --recursive --depth=1 make all-via-docker -# fetch godwoken-scripts from godwoken-prebuilds image, -# including meta-contract and sudt-contract -GW_SCRIPTS_DIR=$PROJECT_ROOT/build -mkdir -p $GW_SCRIPTS_DIR && echo "Create dir" -IMAGE=nervos/godwoken-prebuilds:v0.10.4 -docker pull $IMAGE -docker run --rm -v $GW_SCRIPTS_DIR:/build-dir $IMAGE \ - cp -r /scripts/godwoken-scripts /build-dir \ - && echo "Copy godwoken-scripts" - cd $TESTS_DIR export RUST_BACKTRACE=full cargo test -- --nocapture diff --git a/polyjuice-tests/src/helper.rs b/polyjuice-tests/src/helper.rs index 964daa9e..238853bc 100644 --- a/polyjuice-tests/src/helper.rs +++ b/polyjuice-tests/src/helper.rs @@ -42,7 +42,7 @@ pub const SUDT_VALIDATOR_SCRIPT_TYPE_HASH: [u8; 32] = [0xa2u8; 32]; pub const SECP_DATA: &[u8] = include_bytes!("../../build/secp256k1_data"); // polyjuice pub const BIN_DIR: &str = "../build"; -pub const GENERATOR_NAME: &str = "generator.aot"; +pub const GENERATOR_NAME: &str = "generator_log"; pub const VALIDATOR_NAME: &str = "validator"; pub const ROLLUP_SCRIPT_HASH: [u8; 32] = [0xa9u8; 32]; @@ -606,6 +606,10 @@ pub fn build_eth_l2_script(args: [u8; 20]) -> Script { } pub fn check_cycles(l2_tx_label: &str, used_cycles: u64, warning_cycles: u64) { + if GENERATOR_NAME.contains("_log") { + return; // disable cycles check + } + println!("[check_cycles] used_cycles: {}", used_cycles); assert!( used_cycles < warning_cycles,