From 83f135b5c5173fb8fa3e1d7dc3e92280fa60a8ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 30 Aug 2018 10:22:49 +0200 Subject: [PATCH] go: Add Host exported functions type checks --- bindings/go/evmc/host.c | 80 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 2 deletions(-) diff --git a/bindings/go/evmc/host.c b/bindings/go/evmc/host.c index 53e3bfb..0f91f6d 100644 --- a/bindings/go/evmc/host.c +++ b/bindings/go/evmc/host.c @@ -7,6 +7,19 @@ #include + +void evmc_go_free_result_output(const struct evmc_result* result) +{ + free((void*)result->output_data); +} + + +/* Go does not support exporting functions with parameters with const modifiers, + * so we have to cast function pointers to the function types defined in EVMC. + * This disables any type checking of exported Go functions. To mitigate this + * problem the go_exported_functions_type_checks() function simulates usage + * of Go exported functions with expected types to check them during compilation. + */ const struct evmc_context_fn_table evmc_go_fn_table = { (evmc_account_exists_fn)accountExists, (evmc_get_storage_fn)getStorage, @@ -22,7 +35,70 @@ const struct evmc_context_fn_table evmc_go_fn_table = { (evmc_emit_log_fn)emitLog, }; -void evmc_go_free_result_output(const struct evmc_result* result) + +#pragma GCC diagnostic error "-Wconversion" +static inline void go_exported_functions_type_checks() { - free((void*)result->output_data); + struct evmc_context* context = NULL; + struct evmc_address* address = NULL; + struct evmc_uint256be* uint256be = NULL; + uint8_t* data = NULL; + size_t size = 0; + int64_t number = 0; + struct evmc_message* message = NULL; + struct evmc_result* result = NULL; + struct evmc_tx_context* tx_context = NULL; + + enum evmc_storage_status storage_status; + (void)storage_status; + int status; + (void)status; + + evmc_account_exists_fn account_exists_fn = NULL; + status = account_exists_fn(context, address); + status = accountExists(context, address); + + evmc_get_storage_fn get_storage_fn = NULL; + get_storage_fn(uint256be, context, address, uint256be); + getStorage(uint256be, context, address, uint256be); + + evmc_set_storage_fn set_storage_fn = NULL; + storage_status = set_storage_fn(context, address, uint256be, uint256be); + storage_status = setStorage(context, address, uint256be, uint256be); + + evmc_get_balance_fn get_balance_fn = NULL; + get_balance_fn(uint256be, context, address); + getBalance(uint256be, context, address); + + evmc_get_code_size_fn get_code_size_fn = NULL; + size = get_code_size_fn(context, address); + size = getCodeSize(context, address); + + evmc_get_code_hash_fn get_code_hash_fn = NULL; + get_code_hash_fn(uint256be, context, address); + getCodeHash(uint256be, context, address); + + evmc_copy_code_fn copy_code_fn = NULL; + size = copy_code_fn(context, address, size, data, size); + size = copyCode(context, address, size, data, size); + + evmc_selfdestruct_fn selfdestruct_fn = NULL; + selfdestruct_fn(context, address, address); + selfdestruct(context, address, address); + + evmc_call_fn call_fn = NULL; + call_fn(result, context, message); + call(result, context, message); + + evmc_get_tx_context_fn get_tx_context_fn = NULL; + get_tx_context_fn(tx_context, context); + getTxContext(tx_context, context); + + evmc_get_block_hash_fn get_block_hash_fn = NULL; + get_block_hash_fn(uint256be, context, number); + getBlockHash(uint256be, context, number); + + evmc_emit_log_fn emit_log_fn = NULL; + emit_log_fn(context, address, data, size, uint256be, size); + emitLog(context, address, data, size, uint256be, size); }