Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Commit

Permalink
Merge pull request #154 from nervosnetwork/TESTNET_V0_FORK1
Browse files Browse the repository at this point in the history
fix(testnet_v0): add `TESTNET_V0_FORK1`
  • Loading branch information
Flouse authored May 19, 2022
2 parents c927fb6 + 848cbdc commit a5dec04
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 17 deletions.
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/**/*.*

Expand Down
5 changes: 4 additions & 1 deletion c/polyjuice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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,
Expand Down
36 changes: 34 additions & 2 deletions c/polyjuice_globals.h
Original file line number Diff line number Diff line change
@@ -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
14 changes: 2 additions & 12 deletions devtools/ci/integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,15 @@ 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

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
Expand Down
6 changes: 5 additions & 1 deletion polyjuice-tests/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a5dec04

Please sign in to comment.