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

Commit

Permalink
fix: fix sudt erc20 proxy delegate call bug
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWaWaR committed May 20, 2022
1 parent 34f8180 commit 8b33be3
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 5 deletions.
10 changes: 10 additions & 0 deletions c/contracts.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ typedef int (*precompiled_contract_gas_fn)(const uint8_t* input_src,
typedef int (*precompiled_contract_fn)(gw_context_t* ctx,
const uint8_t* code_data,
const size_t code_size,
const enum evmc_call_kind parent_kind,
bool is_static_call,
const uint8_t* input_src,
const size_t input_size,
Expand Down Expand Up @@ -72,6 +73,7 @@ int ecrecover_required_gas(const uint8_t* input, const size_t input_size,
int ecrecover(gw_context_t* ctx,
const uint8_t* code_data,
const size_t code_size,
const enum evmc_call_kind parent_kind,
bool is_static_call,
const uint8_t* input_src,
const size_t input_size, uint8_t** output, size_t* output_size) {
Expand Down Expand Up @@ -151,6 +153,7 @@ int sha256hash_required_gas(const uint8_t* input, const size_t input_size,
int sha256hash(gw_context_t* ctx,
const uint8_t* code_data,
const size_t code_size,
const enum evmc_call_kind parent_kind,
bool is_static_call,
const uint8_t* input_src,
const size_t input_size, uint8_t** output, size_t* output_size) {
Expand All @@ -176,6 +179,7 @@ int ripemd160hash_required_gas(const uint8_t* input, const size_t input_size,
int ripemd160hash(gw_context_t* ctx,
const uint8_t* code_data,
const size_t code_size,
const enum evmc_call_kind parent_kind,
bool is_static_call,
const uint8_t* input_src,
const size_t input_size, uint8_t** output,
Expand Down Expand Up @@ -204,6 +208,7 @@ int data_copy_required_gas(const uint8_t* input, const size_t input_size,
int data_copy(gw_context_t* ctx,
const uint8_t* code_data,
const size_t code_size,
const enum evmc_call_kind parent_kind,
bool is_static_call,
const uint8_t* input_src,
const size_t input_size, uint8_t** output, size_t* output_size) {
Expand Down Expand Up @@ -404,6 +409,7 @@ int big_mod_exp_required_gas(const uint8_t* input, const size_t input_size,
int big_mod_exp(gw_context_t* ctx,
const uint8_t* code_data,
const size_t code_size,
const enum evmc_call_kind parent_kind,
bool is_static_call,
const uint8_t* input_src,
const size_t input_size, uint8_t** output,
Expand Down Expand Up @@ -699,6 +705,7 @@ void f_generic(uint64_t h[8], uint64_t m[16], uint64_t c0, uint64_t c1,
int blake2f(gw_context_t* ctx,
const uint8_t* code_data,
const size_t code_size,
const enum evmc_call_kind parent_kind,
bool is_static_call,
const uint8_t* input_src,
const size_t input_size, uint8_t** output, size_t* output_size) {
Expand Down Expand Up @@ -777,6 +784,7 @@ int bn256_add_istanbul_gas(const uint8_t* input_src,
int bn256_add_istanbul(gw_context_t* ctx,
const uint8_t* code_data,
const size_t code_size,
const enum evmc_call_kind parent_kind,
bool is_static_call,
const uint8_t* input_src,
const size_t input_size,
Expand Down Expand Up @@ -825,6 +833,7 @@ int bn256_scalar_mul_istanbul_gas(const uint8_t* input_src,
int bn256_scalar_mul_istanbul(gw_context_t* ctx,
const uint8_t* code_data,
const size_t code_size,
const enum evmc_call_kind parent_kind,
bool is_static_call,
const uint8_t* input_src,
const size_t input_size,
Expand Down Expand Up @@ -866,6 +875,7 @@ int bn256_pairing_istanbul_gas(const uint8_t* input_src,
int bn256_pairing_istanbul(gw_context_t* ctx,
const uint8_t* code_data,
const size_t code_size,
const enum evmc_call_kind parent_kind,
bool is_static_call,
const uint8_t* input_src,
const size_t input_size,
Expand Down
2 changes: 2 additions & 0 deletions c/other_contracts.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ int recover_account_gas(const uint8_t* input_src,
int recover_account(gw_context_t* ctx,
const uint8_t* code_data,
const size_t code_size,
const enum evmc_call_kind parent_kind,
bool is_static_call,
const uint8_t* input_src,
const size_t input_size,
Expand Down Expand Up @@ -96,6 +97,7 @@ int eth_to_godwoken_addr_gas(const uint8_t* input_src,
int eth_to_godwoken_addr(gw_context_t* ctx,
const uint8_t* code_data,
const size_t code_size,
const enum evmc_call_kind parent_kind,
bool is_static_call,
const uint8_t* input_src,
const size_t input_size,
Expand Down
7 changes: 6 additions & 1 deletion c/polyjuice.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,13 @@ struct evmc_host_context {
gw_context_t* gw_ctx;
const uint8_t* code_data;
const size_t code_size;
// parent level call kind
enum evmc_call_kind kind;
uint32_t from_id;
uint32_t to_id;
// parent level sender
evmc_address sender;
// parent level destination
evmc_address destination;
int error_code;
};
Expand Down Expand Up @@ -599,6 +603,7 @@ struct evmc_result call(struct evmc_host_context* context,
res.gas_left = msg->gas - (int64_t)gas_cost;
ret = contract(gw_ctx,
context->code_data, context->code_size,
context->kind,
msg->flags == EVMC_STATIC,
msg->input_data, msg->input_size,
(uint8_t**)&res.output_data, &res.output_size);
Expand Down Expand Up @@ -910,7 +915,7 @@ int execute_in_evmone(gw_context_t* ctx,
int ret = 0;
evmc_address sender = msg->sender;
evmc_address destination = msg->destination;
struct evmc_host_context context {ctx, code_data, code_size, from_id, to_id, sender, destination, 0};
struct evmc_host_context context {ctx, code_data, code_size, msg->kind, from_id, to_id, sender, destination, 0};
struct evmc_vm* vm = evmc_create_evmone();
struct evmc_host_interface interface = {account_exists, get_storage, set_storage, get_balance,
get_code_size, get_code_hash, copy_code, selfdestruct,
Expand Down
6 changes: 6 additions & 0 deletions c/sudt_contracts.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ int balance_of_any_sudt_gas(const uint8_t* input_src,
int balance_of_any_sudt(gw_context_t* ctx,
const uint8_t* code_data,
const size_t code_size,
const enum evmc_call_kind parent_kind,
bool is_static_call,
const uint8_t* input_src,
const size_t input_size,
Expand Down Expand Up @@ -104,6 +105,7 @@ int transfer_to_any_sudt_gas(const uint8_t* input_src,
int transfer_to_any_sudt(gw_context_t* ctx,
const uint8_t* code_data,
const size_t code_size,
const enum evmc_call_kind parent_kind,
bool is_static_call,
const uint8_t* input_src,
const size_t input_size,
Expand Down Expand Up @@ -146,6 +148,10 @@ int transfer_to_any_sudt(gw_context_t* ctx,
ckb_debug("static call to transfer to any sudt is forbidden");
return ERROR_TRANSFER_TO_ANY_SUDT;
}
if (parent_kind == EVMC_CALLCODE || parent_kind == EVMC_DELEGATECALL) {
ckb_debug("delegatecall/callcode to transfer to any sudt is forbidden");
return ERROR_TRANSFER_TO_ANY_SUDT;
}
if (input_size != (32 + 32 + 32 + 32)) {
return ERROR_TRANSFER_TO_ANY_SUDT;
}
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 @@ -68,7 +68,7 @@ int test_contract(const uint8_t n,
ctx.sys_load_data = sys_load_data;
ctx.sys_load = sys_load;
ctx._internal_load_raw = _internal_load_raw;
ret = contract(&ctx, NULL, 0, true, input_src, input_size, &output, &output_size);
ret = contract(&ctx, NULL, 0, EVMC_CALL, true, input_src, input_size, &output, &output_size);
if (ret != 0) {
debug_print_int("run contract failed", ret);
goto test_contract_cleanup;
Expand Down
Loading

0 comments on commit 8b33be3

Please sign in to comment.