Support for EXTCODEHASH
MODIFY
examples/capi.c
examples/capi.c
@@ -16,13 +16,6 @@ struct evmc_uint256be balance(struct evmc_context* context, const struct evmc_ad
return ret;
}
-struct evmc_address address(struct evmc_context* context)
-{
- (void)context;
- struct evmc_address ret = {.bytes = {1, 2, 3, 4}};
- return ret;
-}
-
static void print_address(const struct evmc_address* address)
{
int i = 0;
@@ -84,6 +77,17 @@ static size_t get_code_size(struct evmc_context* context, const struct evmc_addr
return 0;
}
+static void get_code_hash(struct evmc_uint256be* result,
+ struct evmc_context* context,
+ const struct evmc_address* address)
+{
+ (void)result;
+ (void)context;
+ printf("EVM-C: CODEHASH @");
+ print_address(address);
+ printf("\n");
+}
+
static size_t copy_code(struct evmc_context* context,
const struct evmc_address* address,
size_t code_offset,
@@ -155,8 +159,8 @@ static void evm_log(struct evmc_context* context,
}
static const struct evmc_context_fn_table ctx_fn_table = {
- account_exists, get_storage, set_storage, get_balance, get_code_size, copy_code,
- selfdestruct, call, get_tx_context, get_block_hash, evm_log,
+ account_exists, get_storage, set_storage, get_balance, get_code_size, get_code_hash,
+ copy_code, selfdestruct, call, get_tx_context, get_block_hash, evm_log,
};
/// Example how the API is supposed to be used.

MODIFY
include/evmc/evmc.h
include/evmc/evmc.h
@@ -40,7 +40,7 @@ extern "C" {
enum
{
/** The EVMC ABI version number of the interface declared in this file. */
- EVMC_ABI_VERSION = 3
+ EVMC_ABI_VERSION = 4
};
/**
@@ -491,6 +491,18 @@ typedef void (*evmc_get_balance_fn)(struct evmc_uint256be* result,
typedef size_t (*evmc_get_code_size_fn)(struct evmc_context* context,
const struct evmc_address* address);
+/**
+ * Get code size callback function.
+ *
+ * This callback function is used by an EVM to get the keccak256 hash of the code stored
+ * in the account at the given address. For accounts not having a code, this
+ * function returns keccak256 hash of empty data. For accounts not existing in the state,
+ * this function returns 0.
+ */
+typedef void (*evmc_get_code_hash_fn)(struct evmc_uint256be* result,
+ struct evmc_context* context,
+ const struct evmc_address* address);
+
/**
* Copy code callback function.
*
@@ -591,6 +603,9 @@ struct evmc_context_fn_table
/** Get code size callback function. */
evmc_get_code_size_fn get_code_size;
+ /** Get code hash callback function. */
+ evmc_get_code_hash_fn get_code_hash;
+
/** Copy code callback function. */
evmc_copy_code_fn copy_code;

MODIFY
lib/instructions/instruction_metrics.c
lib/instructions/instruction_metrics.c
@@ -85,7 +85,7 @@ static struct evmc_instruction_metrics constantinople_metrics[256] = {
/* EXTCODECOPY = 0x3c */ {700, 4, 0},
/* RETURNDATASIZE = 0x3d */ {BASE, 0, 1},
/* RETURNDATACOPY = 0x3e */ {VERYLOW, 3, 0},
- /* = 0x3f */ {UNDEFINED, 0, 0},
+ /* EXTCODEHASH = 0x3f */ {400, 1, 1},
/* BLOCKHASH = 0x40 */ {20, 1, 1},
/* COINBASE = 0x41 */ {BASE, 0, 1},
/* TIMESTAMP = 0x42 */ {BASE, 0, 1},

Support for EXTCODEHASH