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

Commit

Permalink
fix(eth_addr_reg): init g_eth_addr_reg_id = ctx.transaction_context.t…
Browse files Browse the repository at this point in the history
…o_id
  • Loading branch information
Flouse committed Mar 1, 2022
1 parent 88b5701 commit 8741eec
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ all-via-docker-in-debug-mode: generate-protocol
docker run --rm -v `pwd`:/code -w /code ${BUILDER_DOCKER} make all-in-debug-mode
# Be aware that a given prerequisite will only be built once per invocation of make, at most.
all-in-debug-mode: LDFLAGS := -g # only use -O0 to decrease compile time while coding and debugging (O0 compile time: 1m58s)
all-in-debug-mode: CFLAGS += -DCKB_C_STDLIB_PRINTF
all-in-debug-mode: CFLAGS += -DPOLYJUICE_DEBUG_LOG
all-in-debug-mode: all

clean-via-docker:
Expand Down
5 changes: 4 additions & 1 deletion c/eth_addr_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int handle_fee(gw_context_t *ctx, uint64_t fee) {
}

int main() {
#ifdef CKB_C_STDLIB_PRINTF
#ifdef POLYJUICE_DEBUG_LOG
// init buffer for debug_print
char buffer[DEBUG_BUFFER_SIZE];
g_debug_buffer = buffer;
Expand All @@ -55,6 +55,9 @@ int main() {
return ret;
};

/* g_eth_addr_reg_id is used in the mapping key constructions */
g_eth_addr_reg_id = ctx.transaction_context.to_id;

/* verify and parse args */
mol_seg_t args_seg;
args_seg.ptr = ctx.transaction_context.args;
Expand Down
2 changes: 1 addition & 1 deletion c/tests/test_contracts.c
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ int init_mock_state() {
#endif

int main() {
#ifdef CKB_C_STDLIB_PRINTF
#ifdef POLYJUICE_DEBUG_LOG
// init buffer for debug_print
char buffer[DEBUG_BUFFER_SIZE];
g_debug_buffer = buffer;
Expand Down
2 changes: 1 addition & 1 deletion c/tests/test_rlp.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void test(const char *sender_hex, uint32_t nonce, const char *expected_rlp, cons
}

int main() {
#ifdef CKB_C_STDLIB_PRINTF
#ifdef POLYJUICE_DEBUG_LOG
// init buffer for debug_print
char buffer[DEBUG_BUFFER_SIZE];
g_debug_buffer = buffer;
Expand Down
6 changes: 3 additions & 3 deletions polyjuice-tests/fuzz/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ all: generate-protocol build/polyjuice_generator_fuzzer
build/polyjuice_generator_fuzzer: generate-protocol $(GENERATOR_DEPS)
$(CXX) $(CFLAGS) $(LDFLAGS) $(SANITIZER_FLAGS) $(LIMIT_ERROR) -fsanitize=fuzzer -Ibuild -o $@ polyjuice_generator_fuzzer.cc $(ALL_OBJS)
build/polyjuice_generator_fuzzer_log: generate-protocol $(GENERATOR_DEPS)
$(CXX) $(CFLAGS) $(LDFLAGS) $(SANITIZER_FLAGS) $(LIMIT_ERROR) -fsanitize=fuzzer -Ibuild -o $@ polyjuice_generator_fuzzer.cc $(ALL_OBJS) -DCKB_C_STDLIB_PRINTF
$(CXX) $(CFLAGS) $(LDFLAGS) $(SANITIZER_FLAGS) $(LIMIT_ERROR) -fsanitize=fuzzer -Ibuild -o $@ polyjuice_generator_fuzzer.cc $(ALL_OBJS) -DPOLYJUICE_DEBUG_LOG

###
# TODO:
Expand Down Expand Up @@ -98,7 +98,7 @@ build/generator: ../../c/generator.c $(GENERATOR_DEPS)
cd $(SECP_DIR) && (git apply -R workaround-fix-g++-linking.patch || true) && cd - # revert patch
build/generator_log: ../../c/generator.c $(GENERATOR_DEPS)
cd $(SECP_DIR) && (git apply workaround-fix-g++-linking.patch || true) && cd - # apply patch
$(CXX) $(CFLAGS) $(LDFLAGS) $(SANITIZER_FLAGS) -Ibuild -o $@ ../../c/generator.c $(ALL_OBJS) -DCKB_C_STDLIB_PRINTF
$(CXX) $(CFLAGS) $(LDFLAGS) $(SANITIZER_FLAGS) -Ibuild -o $@ ../../c/generator.c $(ALL_OBJS) -DPOLYJUICE_DEBUG_LOG
$(OBJCOPY) --only-keep-debug $@ $@.debug
$(OBJCOPY) --strip-debug --strip-all $@
cd $(SECP_DIR) && (git apply -R workaround-fix-g++-linking.patch || true) && cd - # revert patch
Expand All @@ -110,7 +110,7 @@ build/validator: ../../c/validator.c $(VALIDATOR_DEPS)
cd $(SECP_DIR) && (git apply -R workaround-fix-g++-linking.patch || true) && cd - # revert patch
build/validator_log: ../../c/validator.c $(VALIDATOR_DEPS)
cd $(SECP_DIR) && (git apply workaround-fix-g++-linking.patch || true) && cd - # apply patch
$(CXX) $(SANITIZER_FLAGS) $(CFLAGS) $(LDFLAGS) -Ibuild -o $@ ../../c/validator.c $(ALL_OBJS) -DCKB_C_STDLIB_PRINTF
$(CXX) $(SANITIZER_FLAGS) $(CFLAGS) $(LDFLAGS) -Ibuild -o $@ ../../c/validator.c $(ALL_OBJS) -DPOLYJUICE_DEBUG_LOG
$(OBJCOPY) --only-keep-debug $@ $@.debug
$(OBJCOPY) --strip-debug --strip-all $@
cd $(SECP_DIR) && (git apply -R workaround-fix-g++-linking.patch || true) && cd - # revert patch
Expand Down
2 changes: 1 addition & 1 deletion polyjuice-tests/fuzz/ckb_syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void dbg_print_hex(const uint8_t* ptr, size_t size) {
printf("\n");
}

#ifndef CKB_C_STDLIB_PRINTF
#ifndef POLYJUICE_DEBUG_LOG
#undef dbg_print
#undef dbg_print_h256
#undef dbg_print_hex
Expand Down
2 changes: 1 addition & 1 deletion polyjuice-tests/fuzz/mock_godwoken.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extern "C" int ckb_debug(const char* str) {
return 0;
}

#ifndef CKB_C_STDLIB_PRINTF
#ifndef POLYJUICE_DEBUG_LOG
#undef ckb_debug
#define ckb_debug(s) do {} while (0)
#endif
Expand Down
22 changes: 19 additions & 3 deletions polyjuice-tests/src/test_cases/eth_addr_reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use gw_generator::{error::TransactionError, traits::StateExt};
use gw_store::{chain_view::ChainView, traits::chain_store::ChainStore};
use gw_types::{packed::RawL2Transaction, prelude::*};

const SS_INIT_CODE: &str = include_str!("./evm-contracts/SimpleStorage.bin");

#[derive(Debug, Default)]
pub struct EthToGwArgsBuilder {
pub(crate) method: u32,
Expand Down Expand Up @@ -78,14 +80,14 @@ fn test_update_eth_addr_reg_by_contract() {
.mint_sudt(
CKB_SUDT_ACCOUNT_ID,
&eth_eoa_account_script_hash[..20],
2000,
52000,
)
.unwrap();
assert_eq!(
state
.get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &eth_eoa_account_script_hash[..20])
.unwrap(),
2000u128
52000u128
);

// update_eth_address_registry by `ETH Address Registry` layer2 contract
Expand All @@ -107,7 +109,7 @@ fn test_update_eth_addr_reg_by_contract() {
state
.get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &eth_eoa_account_script_hash[..20])
.unwrap(),
1000u128
51000u128
);

// try to register the same account again
Expand Down Expand Up @@ -176,6 +178,20 @@ fn test_update_eth_addr_reg_by_contract() {
assert_eq!(run_result.return_data, eth_eoa_address);

// New Polyjuice conatract account will be registered in `create_new_account` of polyjuice.h

// Deploy SimpleStorage using the eth_eoa_acount as from_id
let _run_result = helper::deploy(
&generator,
&store,
&mut state,
helper::CREATOR_ACCOUNT_ID,
eth_eoa_account_id,
SS_INIT_CODE,
50000,
0,
block_producer_id,
4,
);
}

#[test]
Expand Down

0 comments on commit 8741eec

Please sign in to comment.