mirror of https://github.com/status-im/evmc.git
Merge pull request #120 from ethereum/evm-v5
EVM-C: Split get_storage from query callback
This commit is contained in:
commit
ac066efd5c
|
@ -27,8 +27,7 @@ static void print_address(const struct evm_uint160be* address)
|
|||
static void query(union evm_variant* result,
|
||||
struct evm_env* env,
|
||||
enum evm_query_key key,
|
||||
const struct evm_uint160be* address,
|
||||
const struct evm_uint256be* storage_key) {
|
||||
const struct evm_uint160be* address) {
|
||||
printf("EVM-C: QUERY %d\n", key);
|
||||
switch (key) {
|
||||
case EVM_CODE_BY_ADDRESS:
|
||||
|
@ -49,6 +48,16 @@ static void query(union evm_variant* result,
|
|||
}
|
||||
}
|
||||
|
||||
static void get_storage(struct evm_uint256be* result,
|
||||
struct evm_env* env,
|
||||
const struct evm_uint160be* address,
|
||||
const struct evm_uint256be* key)
|
||||
{
|
||||
printf("EVM-C: SLOAD @");
|
||||
print_address(address);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static void set_storage(struct evm_env* env,
|
||||
const struct evm_uint160be* address,
|
||||
const struct evm_uint256be* key,
|
||||
|
@ -105,7 +114,10 @@ int main(int argc, char *argv[]) {
|
|||
if (factory.abi_version != EVM_ABI_VERSION)
|
||||
return 1; // Incompatible ABI version.
|
||||
|
||||
struct evm_instance* jit = factory.create(query, set_storage, selfdestruct,
|
||||
struct evm_instance* jit = factory.create(query,
|
||||
get_storage,
|
||||
set_storage,
|
||||
selfdestruct,
|
||||
call,
|
||||
get_tx_context, get_block_hash,
|
||||
evm_log);
|
||||
|
|
|
@ -8,6 +8,7 @@ struct examplevm
|
|||
{
|
||||
struct evm_instance instance;
|
||||
evm_query_state_fn query_fn;
|
||||
evm_get_storage_fn get_storage_fn;
|
||||
evm_set_storage_fn set_storage_fn;
|
||||
evm_selfdestruct_fn selfdestruct_fn;
|
||||
evm_call_fn call_fn;
|
||||
|
@ -100,11 +101,11 @@ static struct evm_result execute(struct evm_instance* instance,
|
|||
}
|
||||
else if (code_size == strlen(counter) &&
|
||||
strncmp((const char*)code, counter, code_size)) {
|
||||
union evm_variant value;
|
||||
struct evm_uint256be value;
|
||||
const struct evm_uint256be index = {{0,}};
|
||||
vm->query_fn(&value, env, EVM_SLOAD, &msg->address, &index);
|
||||
value.uint256be.bytes[31] += 1;
|
||||
vm->set_storage_fn(env, &msg->address, &index, &value.uint256be);
|
||||
vm->get_storage_fn(&value, env, &msg->address, &index);
|
||||
value.bytes[31] += 1;
|
||||
vm->set_storage_fn(env, &msg->address, &index, &value);
|
||||
ret.code = EVM_SUCCESS;
|
||||
return ret;
|
||||
}
|
||||
|
@ -117,6 +118,7 @@ static struct evm_result execute(struct evm_instance* instance,
|
|||
}
|
||||
|
||||
static struct evm_instance* evm_create(evm_query_state_fn query_fn,
|
||||
evm_get_storage_fn get_storage_fn,
|
||||
evm_set_storage_fn set_storage_fn,
|
||||
evm_selfdestruct_fn selfdestruct_fn,
|
||||
evm_call_fn call_fn,
|
||||
|
@ -130,6 +132,7 @@ static struct evm_instance* evm_create(evm_query_state_fn query_fn,
|
|||
interface->execute = execute;
|
||||
interface->set_option = evm_set_option;
|
||||
vm->query_fn = query_fn;
|
||||
vm->get_storage_fn = get_storage_fn;
|
||||
vm->set_storage_fn = set_storage_fn;
|
||||
vm->selfdestruct_fn = selfdestruct_fn;
|
||||
vm->call_fn = call_fn;
|
||||
|
|
|
@ -187,7 +187,6 @@ struct evm_result {
|
|||
|
||||
/// The query callback key.
|
||||
enum evm_query_key {
|
||||
EVM_SLOAD = 0, ///< Storage value of a given key for SLOAD.
|
||||
EVM_CODE_BY_ADDRESS = 10, ///< Code by an address for EXTCODECOPY.
|
||||
EVM_CODE_SIZE = 11, ///< Code size by an address for EXTCODESIZE.
|
||||
EVM_BALANCE = 12, ///< Balance of a given address for BALANCE.
|
||||
|
@ -228,15 +227,9 @@ union evm_variant {
|
|||
/// @param key The kind of the query. See evm_query_key
|
||||
/// and details below.
|
||||
/// @param address The address of the account the query is about.
|
||||
/// @param storage_key Optional argument to provide storage key. Used
|
||||
/// only in ::EVM_SLOAD queries.
|
||||
///
|
||||
/// ## Types of queries
|
||||
///
|
||||
/// - ::EVM_SLOAD
|
||||
/// @param storage_key The index of the storage entry.
|
||||
/// @result evm_variant::uint256be The current value of the storage entry.
|
||||
///
|
||||
/// - ::EVM_CODE_BY_ADDRESS
|
||||
/// @result evm_variant::data The appropriate code for the given address or NULL if not found.
|
||||
///
|
||||
|
@ -258,13 +251,26 @@ union evm_variant {
|
|||
typedef void (*evm_query_state_fn)(union evm_variant* result,
|
||||
struct evm_env* env,
|
||||
enum evm_query_key key,
|
||||
const struct evm_uint160be* address);
|
||||
|
||||
/// Get storage callback function.
|
||||
///
|
||||
/// This callback function is used by an EVM to query the given contract
|
||||
/// storage entry.
|
||||
/// @param[out] result The returned storage value.
|
||||
/// @param env Pointer to execution environment managed by the host
|
||||
/// application.
|
||||
/// @param address The address of the contract.
|
||||
/// @param key The index of the storage entry.
|
||||
typedef void (*evm_get_storage_fn)(struct evm_uint256be* result,
|
||||
struct evm_env* env,
|
||||
const struct evm_uint160be* address,
|
||||
const struct evm_uint256be* storage_key);
|
||||
const struct evm_uint256be* key);
|
||||
|
||||
/// Set storage callback function.
|
||||
///
|
||||
/// This callback function is used by an EVM to update the given contract
|
||||
/// storage entry
|
||||
/// storage entry.
|
||||
/// @param env Pointer to execution environment managed by the host
|
||||
/// application.
|
||||
/// @param address The address of the contract.
|
||||
|
@ -332,6 +338,7 @@ struct evm_instance; ///< Forward declaration.
|
|||
/// @param get_block_hash_fn Pointer to get block hash function. Nonnull.
|
||||
/// @return Pointer to the created EVM instance.
|
||||
typedef struct evm_instance* (*evm_create_fn)(evm_query_state_fn query_fn,
|
||||
evm_get_storage_fn get_storage_fn,
|
||||
evm_set_storage_fn set_storage_fn,
|
||||
evm_selfdestruct_fn selfdestruct_fn,
|
||||
evm_call_fn call_fn,
|
||||
|
|
Loading…
Reference in New Issue