diff --git a/c/polyjuice.h b/c/polyjuice.h index cd387b1d..506bb1c8 100644 --- a/c/polyjuice.h +++ b/c/polyjuice.h @@ -276,7 +276,7 @@ int load_account_code(gw_context_t* gw_ctx, uint32_t account_id, return 0; } - debug_print_int("[load_account_code] account_id:", account_id); + debug_print_int("[load_account_code] account_id", account_id); uint8_t key[32]; uint8_t data_hash[32]; polyjuice_build_contract_code_key(account_id, key); @@ -299,22 +299,25 @@ int load_account_code(gw_context_t* gw_ctx, uint32_t account_id, return 0; } - uint64_t old_code_size = *code_size; + debug_print_int("[load_account_code] code_size before loading", *code_size); ret = gw_ctx->sys_load_data(gw_ctx, data_hash, code_size, offset, code); + debug_print_int("[load_account_code] code_size after loading", *code_size); if (ret != 0) { ckb_debug("[load_account_code] sys_load_data failed"); return ret; } - if (*code_size > old_code_size) { - debug_print_int("[load_account_code] code can't be larger than", MAX_DATA_SIZE); - return -1; + if (*code_size > MAX_DATA_SIZE) { + debug_print_int("[load_account_code] code_size can't be larger than", + MAX_DATA_SIZE); + return GW_FATAL_BUFFER_OVERFLOW; } + return 0; } -//////////////////////////////////////////////////////////////////////////// -//// Callbacks -//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//// Callbacks - EVMC Host Interfaces +//////////////////////////////////////////////////////////////////////////////// struct evmc_tx_context get_tx_context(struct evmc_host_context* context) { struct evmc_tx_context ctx{0}; /* gas price = 1 */ @@ -412,14 +415,16 @@ size_t get_code_size(struct evmc_host_context* context, ckb_debug("get contract account id failed"); return 0; } + uint8_t code[MAX_DATA_SIZE]; uint64_t code_size = MAX_DATA_SIZE; ret = load_account_code(context->gw_ctx, account_id, &code_size, 0, code); if (ret != 0) { - ckb_debug("load_account_code failed"); + debug_print_int("[get_code_size] load_account_code failed", ret); context->error_code = ret; return 0; } + ckb_debug("END get_code_size"); return code_size; } @@ -441,7 +446,7 @@ evmc_bytes32 get_code_hash(struct evmc_host_context* context, uint64_t code_size = MAX_DATA_SIZE; ret = load_account_code(context->gw_ctx, account_id, &code_size, 0, code); if (ret != 0) { - ckb_debug("load_account_code failed"); + debug_print_int("[get_code_hash] load_account_code failed", ret); context->error_code = ret; return hash; } @@ -454,28 +459,48 @@ evmc_bytes32 get_code_hash(struct evmc_host_context* context, return hash; } +/** + * @brief Copy code callback function. + * + * This callback function is used by an EVM to request a copy of the code of the + * given account to the memory buffer provided by the EVM. The Client MUST copy + * the requested code, starting with the given offset, to the provided memory + * buffer up to the size of the buffer or the size of the code, whichever is + * smaller. + * + * @param context The pointer to the Host execution context. + * @param address The address of the account. + * @param code_offset The offset of the code to copy. + * @param buffer_data The pointer to the memory buffer allocated by the EVM to + * store a copy of the requested code. + * @param buffer_size The size of the memory buffer. + * @return size_t The number of bytes copied to the buffer by the Client. + */ size_t copy_code(struct evmc_host_context* context, const evmc_address* address, size_t code_offset, uint8_t* buffer_data, size_t buffer_size) { ckb_debug("BEGIN copy_code"); - int ret; + debug_print_int("[copy_code] code_offset", code_offset); + debug_print_int("[copy_code] buffer_size", buffer_size); + uint32_t account_id = 0; - ret = address_to_account_id(context->gw_ctx, address->bytes, &account_id); + int ret = address_to_account_id(context->gw_ctx, address->bytes, &account_id); if (ret != 0) { ckb_debug("get contract account id failed"); context->error_code = ret; return 0; } - uint64_t code_size = (uint32_t)buffer_size; + uint64_t code_size = buffer_size; ret = load_account_code(context->gw_ctx, account_id, &code_size, - (uint32_t)code_offset, buffer_data); + code_offset, buffer_data); if (ret != 0) { - ckb_debug("load account code failed"); + debug_print_int("[copy_code] load_account_code failed", ret); context->error_code = ret; return 0; } + ckb_debug("END copy_code"); - return 0; + return code_size >= buffer_size ? buffer_size : code_size; } evmc_uint256be get_balance(struct evmc_host_context* context, @@ -1008,7 +1033,6 @@ int handle_message(gw_context_t* ctx, uint8_t* code_data = NULL; size_t code_size = 0; uint8_t code_data_buffer[MAX_DATA_SIZE]; - uint64_t code_size_u32 = MAX_DATA_SIZE; if (is_create(msg.kind)) { /* use input as code */ code_data = (uint8_t*)msg.input_data; @@ -1016,18 +1040,21 @@ int handle_message(gw_context_t* ctx, msg.input_data = NULL; msg.input_size = 0; } else if (to_address_exists) { + uint64_t code_size_tmp = MAX_DATA_SIZE; /* call kind: CALL/CALLCODE/DELEGATECALL */ - ret = load_account_code(ctx, to_id, &code_size_u32, 0, code_data_buffer); + ret = load_account_code(ctx, to_id, &code_size_tmp, 0, code_data_buffer); if (ret != 0) { + debug_print_int("[handle_message] load_account_code failed", ret); return ret; } - if (code_size_u32 == 0) { - debug_print_int("[handle_message] empty contract code for account (EoA account)", to_id); + if (code_size_tmp == 0) { + debug_print_int("[handle_message] account with empty code (EoA account)", + to_id); code_data = NULL; } else { code_data = code_data_buffer; } - code_size = (size_t)code_size_u32; + code_size = (size_t)code_size_tmp; } else { // Call non-exists address } @@ -1223,7 +1250,8 @@ int run_polyjuice() { return clean_evmc_result_and_return(&res, ret); } - ret = context.sys_set_program_return_data(&context, (uint8_t *)res.output_data, + ret = context.sys_set_program_return_data(&context, + (uint8_t *)res.output_data, res.output_size); if (ret != 0) { ckb_debug("set return data failed"); diff --git a/devtools/ci/integration-test.sh b/devtools/ci/integration-test.sh index 36658f88..34b18bde 100644 --- a/devtools/ci/integration-test.sh +++ b/devtools/ci/integration-test.sh @@ -12,10 +12,12 @@ if [ -d "$GODWOKEN_DIR" ] then echo "godwoken project already exists" else - git clone -b develop https://github.com/nervosnetwork/godwoken.git $GODWOKEN_DIR + git clone --depth=1 https://github.com/nervosnetwork/godwoken.git $GODWOKEN_DIR fi cd $GODWOKEN_DIR -git checkout 7527776abf53ab069015b66e2569148341425bd8 # https://github.com/nervosnetwork/godwoken/commits/7527776a +# https://github.com/nervosnetwork/godwoken/releases/tag/v0.10.4 +git fetch origin v0.10.4 +git checkout FETCH_HEAD git submodule update --init --recursive --depth=1 cd $PROJECT_ROOT @@ -25,10 +27,10 @@ make all-via-docker # fetch godwoken-scripts from godwoken-prebuilds image, # including meta-contract and sudt-contract GW_SCRIPTS_DIR=$PROJECT_ROOT/build -docker pull nervos/godwoken-prebuilds:latest mkdir -p $GW_SCRIPTS_DIR && echo "Create dir" -docker run --rm -v $GW_SCRIPTS_DIR:/build-dir \ - nervos/godwoken-prebuilds:latest \ +IMAGE=nervos/godwoken-prebuilds:v0.10.3 +docker pull $IMAGE +docker run --rm -v $GW_SCRIPTS_DIR:/build-dir $IMAGE \ cp -r /scripts/godwoken-scripts /build-dir \ && echo "Copy godwoken-scripts" diff --git a/polyjuice-tests/Cargo.lock b/polyjuice-tests/Cargo.lock index d721e6fc..369acac9 100644 --- a/polyjuice-tests/Cargo.lock +++ b/polyjuice-tests/Cargo.lock @@ -24,119 +24,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c5d78ce20460b82d3fa150275ed9d55e21064fc7951177baacf86a145c4a4b1f" [[package]] -name = "async-channel" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2114d64672151c0c5eaa5e131ec84a74f06e1e559830dabba01ca30605d66319" -dependencies = [ - "concurrent-queue", - "event-listener", - "futures-core", -] - -[[package]] -name = "async-executor" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "871f9bb5e0a22eeb7e8cf16641feb87c9dc67032ccf8ff49e772eb9941d3a965" -dependencies = [ - "async-task", - "concurrent-queue", - "fastrand", - "futures-lite", - "once_cell", - "slab", -] - -[[package]] -name = "async-fs" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b3ca4f8ff117c37c278a2f7415ce9be55560b846b5bc4412aaa5d29c1c3dae2" -dependencies = [ - "async-lock", - "blocking", - "futures-lite", -] - -[[package]] -name = "async-io" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a811e6a479f2439f0c04038796b5cfb3d2ad56c230e0f2d3f7b04d68cfee607b" -dependencies = [ - "concurrent-queue", - "futures-lite", - "libc", - "log", - "once_cell", - "parking", - "polling", - "slab", - "socket2", - "waker-fn", - "winapi", -] - -[[package]] -name = "async-lock" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6a8ea61bf9947a1007c5cada31e647dbc77b103c679858150003ba697ea798b" -dependencies = [ - "event-listener", -] - -[[package]] -name = "async-net" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5373304df79b9b4395068fb080369ec7178608827306ce4d081cba51cac551df" -dependencies = [ - "async-io", - "blocking", - "futures-lite", -] - -[[package]] -name = "async-process" -version = "1.3.0" +name = "atty" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83137067e3a2a6a06d67168e49e68a0957d215410473a740cea95a2425c0b7c6" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "async-io", - "blocking", - "cfg-if 1.0.0", - "event-listener", - "futures-lite", + "hermit-abi", "libc", - "once_cell", - "signal-hook", "winapi", ] [[package]] -name = "async-task" -version = "4.0.3" +name = "autocfg" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91831deabf0d6d7ec49552e489aed63b7456a7a3c46cff62adad428110b0af0" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] -name = "atomic-waker" -version = "1.0.0" +name = "base64" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" - -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" [[package]] name = "bindgen" @@ -211,18 +119,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" [[package]] -name = "blocking" -version = "1.1.0" +name = "bumpalo" +version = "3.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "046e47d4b2d391b1f6f8b407b1deb8dee56c1852ccd868becf2710f601b5f427" -dependencies = [ - "async-channel", - "async-task", - "atomic-waker", - "fastrand", - "futures-lite", - "once_cell", -] +checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899" [[package]] name = "byteorder" @@ -239,12 +139,6 @@ dependencies = [ "serde", ] -[[package]] -name = "cache-padded" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba" - [[package]] name = "cc" version = "1.0.72" @@ -474,19 +368,26 @@ dependencies = [ ] [[package]] -name = "concurrent-queue" -version = "1.2.2" +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "core-foundation" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30ed07550be01594c6026cff2a1d7fe9c8f683caa798e12b68694ac9e88286a3" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" dependencies = [ - "cache-padded", + "core-foundation-sys", + "libc", ] [[package]] -name = "convert_case" -version = "0.4.0" +name = "core-foundation-sys" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "crossbeam-channel" @@ -542,6 +443,15 @@ dependencies = [ "generic-array", ] +[[package]] +name = "encoding_rs" +version = "0.8.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" +dependencies = [ + "cfg-if 1.0.0", +] + [[package]] name = "env_logger" version = "0.8.4" @@ -555,12 +465,6 @@ dependencies = [ "termcolor", ] -[[package]] -name = "event-listener" -version = "2.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7531096570974c3a9dcf9e4b8e1cede1ec26cf5046219fb3b9d897503b9be59" - [[package]] name = "faster-hex" version = "0.4.1" @@ -574,39 +478,82 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51e2ce894d53b295cf97b05685aa077950ff3e8541af83217fc720a6437169f8" [[package]] -name = "fastrand" -version = "1.5.0" +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +dependencies = [ + "matches", + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b394ed3d285a429378d3b384b9eb1285267e7df4b166df24b7a6939a04dc392e" +checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" dependencies = [ - "instant", + "futures-core", ] [[package]] name = "futures-core" -version = "0.3.17" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d1c26957f23603395cd326b0ffe64124b818f4449552f960d815cfba83a53d" +checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" [[package]] name = "futures-io" -version = "0.3.17" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" + +[[package]] +name = "futures-sink" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "522de2a0fe3e380f1bc577ba0474108faf3f6b18321dbf60b3b9c39a75073377" +checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868" [[package]] -name = "futures-lite" -version = "1.12.0" +name = "futures-task" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48" +checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a" + +[[package]] +name = "futures-util" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" dependencies = [ - "fastrand", "futures-core", "futures-io", + "futures-task", "memchr", - "parking", "pin-project-lite", - "waker-fn", + "pin-utils", + "slab", ] [[package]] @@ -679,9 +626,10 @@ dependencies = [ name = "gw-ckb-hardfork" version = "0.1.0" dependencies = [ + "arc-swap", "ckb-types", "lazy_static", - "smol", + "tokio", ] [[package]] @@ -701,6 +649,7 @@ version = "0.1.0" dependencies = [ "ckb-fixed-hash", "gw-jsonrpc-types", + "reqwest", "serde", ] @@ -711,21 +660,39 @@ dependencies = [ "ckb-rocksdb", "gw-config", "libc", + "log", "serde", "tempfile", "thiserror", ] +[[package]] +name = "gw-dynamic-config" +version = "0.1.0" +dependencies = [ + "anyhow", + "arc-swap", + "ckb-fixed-hash", + "gw-config", + "gw-jsonrpc-types", + "gw-tx-filter", + "reqwest", + "serde", + "toml", +] + [[package]] name = "gw-generator" version = "0.2.0" dependencies = [ "anyhow", + "arc-swap", "blake2b-rs 0.2.0", "ckb-vm", "gw-ckb-hardfork", "gw-common", "gw-config", + "gw-dynamic-config", "gw-store", "gw-traits", "gw-tx-filter", @@ -736,8 +703,9 @@ dependencies = [ "rlp", "secp256k1", "sha3", - "smol", "thiserror", + "tokio", + "tracing", ] [[package]] @@ -792,6 +760,8 @@ dependencies = [ "gw-config", "gw-traits", "gw-types", + "hex", + "log", "thiserror", ] @@ -807,6 +777,31 @@ dependencies = [ "sparse-merkle-tree", ] +[[package]] +name = "h2" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37a82c6d637fc9515a4694bbf1cb2457b79d81ce52b3108bdeea58b07dd34a57" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" + [[package]] name = "heapsize" version = "0.4.2" @@ -831,6 +826,40 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "http" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31f4c6746584866f0feabcc69893c5b51beef3831656a968ed7ae254cdc4fd03" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ff4f84919677303da5f147645dbea6b1881f368d03ac84e1dc09031ebd7b2c6" +dependencies = [ + "bytes", + "http", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9100414882e15fb7feccb4897e5f0ff0ff1ca7d1a86a23208ada4d7a18e6c6c4" + +[[package]] +name = "httpdate" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" + [[package]] name = "humantime" version = "2.1.0" @@ -838,14 +867,69 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] -name = "instant" -version = "0.1.12" +name = "hyper" +version = "0.14.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +checksum = "b26ae0a80afebe130861d90abf98e3814a4f28a4c6ffeb5ab8ebb2be311e0ef2" dependencies = [ - "cfg-if 1.0.0", + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + +[[package]] +name = "idna" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f647032dfaa1f8b6dc29bd3edb7bbef4861b8b8007ebb118d6db284fd59f6ee" +dependencies = [ + "autocfg", + "hashbrown", ] +[[package]] +name = "ipnet" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35e70ee094dc02fd9c13fdad4940090f22dbd6ac7c9e7094a46cf0232a50bc7c" + [[package]] name = "itoa" version = "1.0.1" @@ -861,6 +945,15 @@ dependencies = [ "libc", ] +[[package]] +name = "js-sys" +version = "0.3.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a38fc24e30fd564ce974c02bf1d337caddff65be6cc4735a1f7eab22a7440f04" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "keccak" version = "0.1.0" @@ -881,9 +974,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.112" +version = "0.2.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" +checksum = "ec647867e2bf0772e28c8bcde4f0d19a9216916e890543b5a03ed8ef27b8f259" [[package]] name = "libloading" @@ -914,6 +1007,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "matches" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" + [[package]] name = "memchr" version = "2.4.1" @@ -929,12 +1028,41 @@ dependencies = [ "cfg-if 0.1.10", ] +[[package]] +name = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + [[package]] name = "minimal-lexical" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" +[[package]] +name = "mio" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52da4364ffb0e4fe33a9841a98a3f3014fb964045ce4f7a45a398243c8d6b0c9" +dependencies = [ + "libc", + "log", + "miow", + "ntapi", + "wasi 0.11.0+wasi-snapshot-preview1", + "winapi", +] + +[[package]] +name = "miow" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" +dependencies = [ + "winapi", +] + [[package]] name = "molecule" version = "0.7.2" @@ -946,6 +1074,24 @@ dependencies = [ "faster-hex 0.6.1", ] +[[package]] +name = "native-tls" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "nom" version = "7.1.0" @@ -957,6 +1103,25 @@ dependencies = [ "version_check", ] +[[package]] +name = "ntapi" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f" +dependencies = [ + "winapi", +] + +[[package]] +name = "num_cpus" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +dependencies = [ + "hermit-abi", + "libc", +] + [[package]] name = "numext-constructor" version = "0.1.6" @@ -1016,10 +1181,37 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] -name = "parking" -version = "2.0.0" +name = "openssl" +version = "0.10.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7ae222234c30df141154f159066c5093ff73b63204dcda7121eb082fc56a95" +dependencies = [ + "bitflags", + "cfg-if 1.0.0", + "foreign-types", + "libc", + "once_cell", + "openssl-sys", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" +checksum = "7e46109c383602735fa0a2e48dd2b7c892b048e1bf69e5c3b1d804b7d9c203cb" +dependencies = [ + "autocfg", + "cc", + "libc", + "pkg-config", + "vcpkg", +] [[package]] name = "peeking_take_while" @@ -1027,6 +1219,12 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" + [[package]] name = "pin-project-lite" version = "0.2.7" @@ -1034,23 +1232,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" [[package]] -name = "plain" -version = "0.2.3" +name = "pin-utils" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] -name = "polling" -version = "2.2.0" +name = "pkg-config" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "685404d509889fade3e86fe3a5803bca2ec09b0c0778d5ada6ec8bf7a8de5259" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "log", - "wepoll-ffi", - "winapi", -] +checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" + +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" [[package]] name = "polyjuice-tests" @@ -1211,6 +1408,42 @@ dependencies = [ "winapi", ] +[[package]] +name = "reqwest" +version = "0.11.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46a1f7aa4f35e5e8b4160449f51afc758f0ce6454315a9fa7d0d113e958c41eb" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-tls", + "ipnet", + "js-sys", + "lazy_static", + "log", + "mime", + "native-tls", + "percent-encoding", + "pin-project-lite", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-native-tls", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + [[package]] name = "rlp" version = "0.5.1" @@ -1248,6 +1481,16 @@ version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" +[[package]] +name = "schannel" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" +dependencies = [ + "lazy_static", + "winapi", +] + [[package]] name = "scroll" version = "0.10.2" @@ -1286,6 +1529,29 @@ dependencies = [ "cc", ] +[[package]] +name = "security-framework" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "semver" version = "1.0.4" @@ -1323,6 +1589,18 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + [[package]] name = "sha3" version = "0.9.1" @@ -1341,54 +1619,17 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" -[[package]] -name = "signal-hook" -version = "0.3.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c35dfd12afb7828318348b8c408383cf5071a086c1d4ab1c0f9840ec92dbb922" -dependencies = [ - "libc", - "signal-hook-registry", -] - -[[package]] -name = "signal-hook-registry" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" -dependencies = [ - "libc", -] - [[package]] name = "slab" version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" -[[package]] -name = "smol" -version = "1.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85cf3b5351f3e783c1d79ab5fc604eeed8b8ae9abd36b166e8b87a089efd85e4" -dependencies = [ - "async-channel", - "async-executor", - "async-fs", - "async-io", - "async-lock", - "async-net", - "async-process", - "blocking", - "futures-lite", - "once_cell", -] - [[package]] name = "socket2" -version = "0.4.2" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dc90fe6c7be1a323296982db1836d1ea9e47b6839496dde9a541bc496df3516" +checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" dependencies = [ "libc", "winapi", @@ -1466,18 +1707,159 @@ dependencies = [ "crunchy", ] +[[package]] +name = "tinyvec" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c1c1d5a42b6245520c249549ec267180beaffcc0615401ac8e31853d4b6d8d2" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + +[[package]] +name = "tokio" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee" +dependencies = [ + "bytes", + "libc", + "memchr", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "winapi", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0edfdeb067411dba2044da6d1cb2df793dd35add7888d73c16e3381ded401764" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", + "tracing", +] + +[[package]] +name = "toml" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" +dependencies = [ + "serde", +] + +[[package]] +name = "tower-service" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" + +[[package]] +name = "tracing" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a1bdf54a7c28a2bbf701e1d2233f6c77f473486b94bee4f9678da5a148dca7f" +dependencies = [ + "cfg-if 1.0.0", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e65ce065b4b5c53e73bb28912318cb8c9e9ad3921f1d669eb0e68b4c8143a2b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90442985ee2f57c9e1b548ee72ae842f4a9a20e3f417cc38dbc5dc684d9bb4ee" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "try-lock" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" + [[package]] name = "typenum" version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec" +[[package]] +name = "unicode-bidi" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a01404663e3db436ed2746d9fefef640d868edae3cceb81c3b8d5732fda678f" + +[[package]] +name = "unicode-normalization" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" +dependencies = [ + "tinyvec", +] + [[package]] name = "unicode-xid" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +[[package]] +name = "url" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +dependencies = [ + "form_urlencoded", + "idna", + "matches", + "percent-encoding", +] + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "version_check" version = "0.9.3" @@ -1485,10 +1867,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" [[package]] -name = "waker-fn" -version = "1.1.0" +name = "want" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", +] [[package]] name = "wasi" @@ -1503,12 +1889,85 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] -name = "wepoll-ffi" -version = "0.1.2" +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d743fdedc5c64377b5fc2bc036b01c7fd642205a0d96356034ae3404d49eb7fb" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25f1af7423d8588a3d840681122e72e6a24ddbcb3f0ec385cac0d12d24256c06" dependencies = [ - "cc", + "cfg-if 1.0.0", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b21c0df030f5a177f3cba22e9bc4322695ec43e7257d865302900290bcdedca" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2eb6ec270a31b1d3c7e266b999739109abce8b6c87e4b31fcfcd788b65267395" +dependencies = [ + "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f4203d69e40a52ee523b2529a773d5ffc1dc0071801c87b3d270b471b80ed01" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa8a30d46208db204854cadbb5d4baf5fcf8071ba5bf48190c3e59937962ebc" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d958d035c4438e28c70e4321a2911302f10135ce78a9c7834c0cab4123d06a2" + +[[package]] +name = "web-sys" +version = "0.3.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c060b319f29dd25724f09a2ba1418f142f539b2be99fbf4d2d5a8f7330afb8eb" +dependencies = [ + "js-sys", + "wasm-bindgen", ] [[package]] @@ -1541,3 +2000,12 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "winreg" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +dependencies = [ + "winapi", +] diff --git a/polyjuice-tests/src/helper.rs b/polyjuice-tests/src/helper.rs index d1e659d5..964daa9e 100644 --- a/polyjuice-tests/src/helper.rs +++ b/polyjuice-tests/src/helper.rs @@ -447,12 +447,7 @@ pub fn setup() -> (Store, DummyState, Generator, u32) { rollup_script_hash: ROLLUP_SCRIPT_HASH.clone().into(), rollup_config, }; - let generator = Generator::new( - backend_manage, - account_lock_manage, - rollup_context, - Default::default(), - ); + let generator = Generator::new(backend_manage, account_lock_manage, rollup_context); let tx = store.begin_transaction(); let tip_block_number: Uint64 = 8.pack(); @@ -510,6 +505,7 @@ pub fn deploy( &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); state.apply_run_result(&run_result).expect("update state"); @@ -579,6 +575,7 @@ pub fn simple_storage_get( &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); // 491894, 571661 -> 586360 < 587K diff --git a/polyjuice-tests/src/test_cases/address.rs b/polyjuice-tests/src/test_cases/address.rs new file mode 100644 index 00000000..f61a64fb --- /dev/null +++ b/polyjuice-tests/src/test_cases/address.rs @@ -0,0 +1,118 @@ +use crate::helper::{self, deploy, new_account_script, new_block_info, PolyjuiceArgsBuilder}; +use gw_common::state::State; +use gw_generator::traits::StateExt; +use gw_store::traits::chain_store::ChainStore; +use gw_types::{ + packed::RawL2Transaction, + prelude::{Builder, Entity, Pack}, +}; +use std::convert::TryInto; + +const CONTRACT_CODE: &str = include_str!("./evm-contracts/AddressType.bin"); + +#[test] +fn test_get_contract_code() { + let (store, mut state, generator, _creator_account_id) = helper::setup(); + let block_producer_script = helper::build_eth_l2_script([0x99u8; 20]); + let block_producer_id = state + .create_account_from_script(block_producer_script) + .unwrap(); + + let from_eth_address = [1u8; 20]; + let from_script = helper::build_eth_l2_script(from_eth_address.clone()); + let from_script_hash = from_script.hash(); + let from_short_script_hash = &from_script_hash[0..20]; + let from_id = state.create_account_from_script(from_script).unwrap(); + state + .mint_sudt(helper::CKB_SUDT_ACCOUNT_ID, from_short_script_hash, 400000) + .unwrap(); + + // Deploy contract + let mut block_number = 1; + let _run_result = deploy( + &generator, + &store, + &mut state, + _creator_account_id, + from_id, + CONTRACT_CODE, + 122000, + 0, + block_producer_id, + block_number, + ); + let contract_script = new_account_script(&mut state, _creator_account_id, from_id, false); + let contract_id = state + .get_account_id_by_script_hash(&contract_script.hash().into()) + .unwrap() + .expect("get contract account ID by account_script"); + + // test createMemoryArray function + block_number += 1; + let block_info = new_block_info(block_producer_id, block_number, block_number); + let input = hex::decode("c59083f5").expect("createMemoryArray function"); + let args = PolyjuiceArgsBuilder::default() + .gas_limit(10000) + .gas_price(1) + .value(0) + .input(&input) + .build(); + let raw_l2tx = RawL2Transaction::new_builder() + .from_id(from_id.pack()) + .to_id(contract_id.pack()) + .args(gw_types::bytes::Bytes::from(args).pack()) + .build(); + let db = store.begin_transaction(); + let tip_block_hash = db.get_tip_block_hash().unwrap(); + let run_result = generator + .execute_transaction( + &gw_store::chain_view::ChainView::new(&db, tip_block_hash), + &state, + &block_info, + &raw_l2tx, + gw_generator::constants::L2TX_MAX_CYCLES, + None, + ) + .expect("call createMemoryArray function"); + let mut expect_result = [0u8; 32]; + for i in 0..32 { + expect_result[i] = i as u8; + } + println!("MemoryArray: {:?}", run_result.return_data); + assert_eq!(run_result.return_data[64..], expect_result); + + // Try to get the contract code + block_number += 1; + let block_info = new_block_info(block_producer_id, block_number, block_number); + let input = hex::decode("ea879634").expect("getCode function"); + let args = PolyjuiceArgsBuilder::default() + .gas_limit(10000) + .gas_price(1) + .value(0) + .input(&input) + .build(); + let raw_l2tx = RawL2Transaction::new_builder() + .from_id(from_id.pack()) + .to_id(contract_id.pack()) + .args(gw_types::bytes::Bytes::from(args).pack()) + .build(); + let db = store.begin_transaction(); + let tip_block_hash = db.get_tip_block_hash().unwrap(); + let run_result = generator + .execute_transaction( + &gw_store::chain_view::ChainView::new(&db, tip_block_hash), + &state, + &block_info, + &raw_l2tx, + gw_generator::constants::L2TX_MAX_CYCLES, + None, + ) + .expect("call getCode function"); + let expected_code = hex::decode(CONTRACT_CODE).expect("code hex to Vec"); + let code_len = usize::from_be_bytes(run_result.return_data[56..64].try_into().unwrap()); + assert_eq!(expected_code.len() - 32, code_len); + assert_eq!( + run_result.return_data[64..64 + code_len], + expected_code[32..] + ); +} diff --git a/polyjuice-tests/src/test_cases/call_multiple_times.rs b/polyjuice-tests/src/test_cases/call_multiple_times.rs index 7b2939f8..98b8164a 100644 --- a/polyjuice-tests/src/test_cases/call_multiple_times.rs +++ b/polyjuice-tests/src/test_cases/call_multiple_times.rs @@ -149,6 +149,7 @@ fn test_call_multiple_times() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); state.apply_run_result(&run_result).expect("update state"); diff --git a/polyjuice-tests/src/test_cases/call_selfdestruct.rs b/polyjuice-tests/src/test_cases/call_selfdestruct.rs index ae8bdf77..52f297da 100644 --- a/polyjuice-tests/src/test_cases/call_selfdestruct.rs +++ b/polyjuice-tests/src/test_cases/call_selfdestruct.rs @@ -142,6 +142,7 @@ fn test_selfdestruct() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); state.apply_run_result(&run_result).expect("update state"); @@ -194,6 +195,7 @@ fn test_selfdestruct() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ); println!("result {:?}", result); assert!(result.is_err()); @@ -226,6 +228,7 @@ fn test_selfdestruct() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ); println!("result {:?}", result); assert!(result.is_err()); diff --git a/polyjuice-tests/src/test_cases/contract_call_contract.rs b/polyjuice-tests/src/test_cases/contract_call_contract.rs index 13e2f116..596d6d23 100644 --- a/polyjuice-tests/src/test_cases/contract_call_contract.rs +++ b/polyjuice-tests/src/test_cases/contract_call_contract.rs @@ -125,6 +125,7 @@ fn test_contract_call_contract() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); state.apply_run_result(&run_result).expect("update state"); @@ -219,6 +220,7 @@ fn test_contract_call_non_exists_contract() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); // [CallNonExistsContract.rawCall(addr)] used cycles: 862060 < 870K diff --git a/polyjuice-tests/src/test_cases/contract_create_contract.rs b/polyjuice-tests/src/test_cases/contract_create_contract.rs index 7d65603e..37cfc8ec 100644 --- a/polyjuice-tests/src/test_cases/contract_create_contract.rs +++ b/polyjuice-tests/src/test_cases/contract_create_contract.rs @@ -91,6 +91,7 @@ fn test_contract_create_contract() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); state.apply_run_result(&run_result).expect("update state"); diff --git a/polyjuice-tests/src/test_cases/create2.rs b/polyjuice-tests/src/test_cases/create2.rs index fde00fd6..110524ef 100644 --- a/polyjuice-tests/src/test_cases/create2.rs +++ b/polyjuice-tests/src/test_cases/create2.rs @@ -99,6 +99,7 @@ fn test_create2() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); // [Create2Impl.deploy(...)] used cycles: 1197555 < 1230K diff --git a/polyjuice-tests/src/test_cases/delegatecall.rs b/polyjuice-tests/src/test_cases/delegatecall.rs index 585fd710..022083af 100644 --- a/polyjuice-tests/src/test_cases/delegatecall.rs +++ b/polyjuice-tests/src/test_cases/delegatecall.rs @@ -130,6 +130,7 @@ fn test_delegatecall() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); // [DelegateCall] used cycles: 1457344 < 1460K diff --git a/polyjuice-tests/src/test_cases/ecrecover.rs b/polyjuice-tests/src/test_cases/ecrecover.rs index 45e09905..f27604f9 100644 --- a/polyjuice-tests/src/test_cases/ecrecover.rs +++ b/polyjuice-tests/src/test_cases/ecrecover.rs @@ -92,6 +92,7 @@ fn test_ecrecover() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); // [recover] used cycles: 2604412 < 2660K diff --git a/polyjuice-tests/src/test_cases/erc20.rs b/polyjuice-tests/src/test_cases/erc20.rs index eaf194b2..8e020fec 100644 --- a/polyjuice-tests/src/test_cases/erc20.rs +++ b/polyjuice-tests/src/test_cases/erc20.rs @@ -167,6 +167,7 @@ fn test_erc20() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); // [ERC20 contract method_x] used cycles: 942107 < 960K diff --git a/polyjuice-tests/src/test_cases/eth_to_godwoken_addr.rs b/polyjuice-tests/src/test_cases/eth_to_godwoken_addr.rs index 322a8d1f..44b546af 100644 --- a/polyjuice-tests/src/test_cases/eth_to_godwoken_addr.rs +++ b/polyjuice-tests/src/test_cases/eth_to_godwoken_addr.rs @@ -90,6 +90,7 @@ fn test_eth_to_godwoken_addr() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); // [EthToGodwokenAddr.convert(addr)] used cycles: 573228 < 580K diff --git a/polyjuice-tests/src/test_cases/evm-contracts/AddressType.bin b/polyjuice-tests/src/test_cases/evm-contracts/AddressType.bin new file mode 100644 index 00000000..c2d339f1 --- /dev/null +++ b/polyjuice-tests/src/test_cases/evm-contracts/AddressType.bin @@ -0,0 +1 @@ +608060405234801561001057600080fd5b50610342806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063c59083f51461003b578063ea87963414610059575b600080fd5b610043610077565b604051610050919061020b565b60405180910390f35b610061610138565b60405161006e919061020b565b60405180910390f35b60606000602067ffffffffffffffff8111156100965761009561022d565b5b6040519080825280601f01601f1916602001820160405280156100c85781602001600182028036833780820191505090505b50905060005b8151811015610130578060f81b8282815181106100ee576100ed61025c565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508080610128906102c4565b9150506100ce565b508091505090565b60603073ffffffffffffffffffffffffffffffffffffffff16803b806020016040519081016040528181526000908060200190933c905090565b600081519050919050565b600082825260208201905092915050565b60005b838110156101ac578082015181840152602081019050610191565b838111156101bb576000848401525b50505050565b6000601f19601f8301169050919050565b60006101dd82610172565b6101e7818561017d565b93506101f781856020860161018e565b610200816101c1565b840191505092915050565b6000602082019050818103600083015261022581846101d2565b905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000819050919050565b60006102cf826102ba565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82036103015761030061028b565b5b60018201905091905056fea2646970667358221220a563499c8a5e0561f2a8e64e34d546b3adc17ca95cf0982a9785202b41a73e7864736f6c634300080d0033 \ No newline at end of file diff --git a/polyjuice-tests/src/test_cases/evm-contracts/AddressType.sol b/polyjuice-tests/src/test_cases/evm-contracts/AddressType.sol new file mode 100644 index 00000000..7130fd11 --- /dev/null +++ b/polyjuice-tests/src/test_cases/evm-contracts/AddressType.sol @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: SEE LICENSE IN LICENSE +pragma solidity ^0.8.13; + +contract AddressType { + constructor() {} + + function getCode() public view returns (bytes memory) { + return address(this).code; + } + + function createMemoryArray() public pure returns (bytes memory) { + // Create a dynamic byte array: + bytes memory b = new bytes(32); + for (uint i = 0; i < b.length; i++) + b[i] = bytes1(uint8(i)); + return b; + } +} diff --git a/polyjuice-tests/src/test_cases/fallback_function.rs b/polyjuice-tests/src/test_cases/fallback_function.rs index 3e397f16..5ffea69e 100644 --- a/polyjuice-tests/src/test_cases/fallback_function.rs +++ b/polyjuice-tests/src/test_cases/fallback_function.rs @@ -54,6 +54,7 @@ fn test_fallback_function() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); // [Deploy FallbackFunction] used cycles: 587271 < 590K @@ -97,6 +98,7 @@ fn test_fallback_function() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); // [Call fallback()] used cycles: 514059 < 520K diff --git a/polyjuice-tests/src/test_cases/get_block_info.rs b/polyjuice-tests/src/test_cases/get_block_info.rs index a908130a..2759dcd0 100644 --- a/polyjuice-tests/src/test_cases/get_block_info.rs +++ b/polyjuice-tests/src/test_cases/get_block_info.rs @@ -77,6 +77,7 @@ fn test_get_block_info() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); state.apply_run_result(&run_result).expect("update state"); @@ -147,6 +148,7 @@ fn test_get_block_info() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); assert_eq!( diff --git a/polyjuice-tests/src/test_cases/get_chain_id.rs b/polyjuice-tests/src/test_cases/get_chain_id.rs index c1a7147a..fdcc5252 100644 --- a/polyjuice-tests/src/test_cases/get_chain_id.rs +++ b/polyjuice-tests/src/test_cases/get_chain_id.rs @@ -58,6 +58,7 @@ fn test_get_chain_id() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); state.apply_run_result(&run_result).expect("update state"); @@ -101,6 +102,7 @@ fn test_get_chain_id() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); state.apply_run_result(&run_result).expect("update state"); diff --git a/polyjuice-tests/src/test_cases/heap_memory.rs b/polyjuice-tests/src/test_cases/heap_memory.rs index d021ffa6..be12162c 100644 --- a/polyjuice-tests/src/test_cases/heap_memory.rs +++ b/polyjuice-tests/src/test_cases/heap_memory.rs @@ -77,6 +77,7 @@ fn test_heap_momory() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("success to malloc memory"); // [newMemory less than 512K] used cycles: 752,115 -> 883611 (increase 17.48%) < 890K @@ -115,6 +116,7 @@ fn test_heap_momory() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect_err("OOM"); println!("{:?}", err); diff --git a/polyjuice-tests/src/test_cases/invalid_sudt_erc20_proxy.rs b/polyjuice-tests/src/test_cases/invalid_sudt_erc20_proxy.rs index d403f036..23690a19 100644 --- a/polyjuice-tests/src/test_cases/invalid_sudt_erc20_proxy.rs +++ b/polyjuice-tests/src/test_cases/invalid_sudt_erc20_proxy.rs @@ -166,6 +166,7 @@ fn test_invalid_sudt_erc20_proxy() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ); if *success { diff --git a/polyjuice-tests/src/test_cases/mod.rs b/polyjuice-tests/src/test_cases/mod.rs index 0a31e578..5d69cb4d 100644 --- a/polyjuice-tests/src/test_cases/mod.rs +++ b/polyjuice-tests/src/test_cases/mod.rs @@ -1,3 +1,4 @@ +pub(crate) mod address; pub(crate) mod call_multiple_times; pub(crate) mod call_selfdestruct; pub(crate) mod contract_call_contract; diff --git a/polyjuice-tests/src/test_cases/parse_log_event.rs b/polyjuice-tests/src/test_cases/parse_log_event.rs index 6679d5a4..5250b41d 100644 --- a/polyjuice-tests/src/test_cases/parse_log_event.rs +++ b/polyjuice-tests/src/test_cases/parse_log_event.rs @@ -178,6 +178,7 @@ fn test_parse_log_event() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); state.apply_run_result(&run_result).expect("update state"); diff --git a/polyjuice-tests/src/test_cases/recover_account.rs b/polyjuice-tests/src/test_cases/recover_account.rs index 32c2bac7..81b4bba8 100644 --- a/polyjuice-tests/src/test_cases/recover_account.rs +++ b/polyjuice-tests/src/test_cases/recover_account.rs @@ -99,6 +99,7 @@ fn test_recover_account() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); // [RecoverAccount.recover(message, signature, code_hash)] used cycles: 648630 < 670K @@ -153,6 +154,7 @@ fn test_recover_account() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); state.apply_run_result(&run_result).expect("update state"); @@ -192,6 +194,7 @@ fn test_recover_account() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect_err("construct"); assert_eq!( diff --git a/polyjuice-tests/src/test_cases/recursion_contract.rs b/polyjuice-tests/src/test_cases/recursion_contract.rs index bc2e01f7..be0800bb 100644 --- a/polyjuice-tests/src/test_cases/recursion_contract.rs +++ b/polyjuice-tests/src/test_cases/recursion_contract.rs @@ -76,6 +76,7 @@ fn test_recursion_contract_call() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("recursive call depth to 32"); state.apply_run_result(&run_result).expect("update state"); @@ -145,6 +146,7 @@ fn test_recursion_contract_call() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect_err("EVMC_REVERT = 2"); assert_eq!(err, TransactionError::InvalidExitCode(2)); @@ -177,6 +179,7 @@ fn test_recursion_contract_call() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect_err("EVMC_OUT_OF_GAS = 3"); assert_eq!(err, TransactionError::InvalidExitCode(3)); diff --git a/polyjuice-tests/src/test_cases/selfdestruct.rs b/polyjuice-tests/src/test_cases/selfdestruct.rs index 921d14f1..1727e2c6 100644 --- a/polyjuice-tests/src/test_cases/selfdestruct.rs +++ b/polyjuice-tests/src/test_cases/selfdestruct.rs @@ -68,6 +68,7 @@ fn test_selfdestruct() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); // [Deploy SelfDestruct] used cycles: 570570 < 580K @@ -119,6 +120,7 @@ fn test_selfdestruct() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); // [call SelfDestruct.done()] used cycles: 589657 < 600K @@ -161,6 +163,7 @@ fn test_selfdestruct() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ); println!("result {:?}", result); assert!(result.is_err()); diff --git a/polyjuice-tests/src/test_cases/simple_storage.rs b/polyjuice-tests/src/test_cases/simple_storage.rs index 241c63f1..776f6de3 100644 --- a/polyjuice-tests/src/test_cases/simple_storage.rs +++ b/polyjuice-tests/src/test_cases/simple_storage.rs @@ -58,6 +58,7 @@ fn test_simple_storage() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); state.apply_run_result(&run_result).expect("update state"); @@ -110,6 +111,7 @@ fn test_simple_storage() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); state.apply_run_result(&run_result).expect("update state"); @@ -141,6 +143,7 @@ fn test_simple_storage() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); state.apply_run_result(&run_result).expect("update state"); diff --git a/polyjuice-tests/src/test_cases/simple_transfer.rs b/polyjuice-tests/src/test_cases/simple_transfer.rs index 714e558b..2fc2bdf1 100644 --- a/polyjuice-tests/src/test_cases/simple_transfer.rs +++ b/polyjuice-tests/src/test_cases/simple_transfer.rs @@ -160,6 +160,7 @@ fn test_simple_transfer() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); // [SimpleTransfer to EoA] used cycles: 725217 < 736K @@ -208,6 +209,7 @@ fn test_simple_transfer() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); // [SimpleTransfer to zero address] used cycles: 699554 < 710K @@ -262,6 +264,7 @@ fn test_simple_transfer() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); // [SimpleTransfer.transferToSimpleStorage1] used cycles: 1203332 < 1210K @@ -328,6 +331,7 @@ fn test_simple_transfer() { &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect("construct"); state.apply_run_result(&run_result).expect("update state"); diff --git a/polyjuice-tests/src/test_cases/sudt_erc20_proxy.rs b/polyjuice-tests/src/test_cases/sudt_erc20_proxy.rs index c46c3d71..2609cc19 100644 --- a/polyjuice-tests/src/test_cases/sudt_erc20_proxy.rs +++ b/polyjuice-tests/src/test_cases/sudt_erc20_proxy.rs @@ -287,6 +287,7 @@ fn test_sudt_erc20_proxy_inner( &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, )?; println!( "[execute_transaction] {} {}ms", @@ -332,6 +333,7 @@ fn test_sudt_erc20_proxy_inner( &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect_err("err"); // by: `revert(0, 0)` @@ -368,6 +370,7 @@ fn test_sudt_erc20_proxy_inner( &block_info, &raw_tx, L2TX_MAX_CYCLES, + None, ) .expect_err("err"); // by: `revert(0, 0)`