EVM-C: Reduce query_fn to account_exists_fn

This commit is contained in:
Paweł Bylica 2017-08-08 10:26:52 +02:00
parent 2d2adcb868
commit 182d7f3876
2 changed files with 16 additions and 68 deletions

View File

@ -24,19 +24,12 @@ static void print_address(const struct evm_uint160be* address)
printf("%x", address->bytes[i] & 0xff); printf("%x", address->bytes[i] & 0xff);
} }
static void query(union evm_variant* result, static int account_exists(struct evm_env* env,
struct evm_env* env, const struct evm_uint160be* address) {
enum evm_query_key key, printf("EVM-C: EXISTS @");
const struct evm_uint160be* address) { print_address(address);
printf("EVM-C: QUERY %d\n", key); printf("\n");
switch (key) { return 0;
case EVM_ACCOUNT_EXISTS:
result->int64 = 0;
break;
default:
result->int64 = 0;
}
} }
static void get_storage(struct evm_uint256be* result, static void get_storage(struct evm_uint256be* result,
@ -119,7 +112,7 @@ static void evm_log(struct evm_env* env, const struct evm_uint160be* address,
} }
static const struct evm_host example_host = { static const struct evm_host example_host = {
query, account_exists,
get_storage, get_storage,
set_storage, set_storage,
get_balance, get_balance,

View File

@ -190,61 +190,16 @@ struct evm_result {
} reserved; } reserved;
}; };
/// The query callback key. /// Check account existence callback function
enum evm_query_key {
EVM_ACCOUNT_EXISTS = 14, ///< Check if an account exists.
};
/// Variant type to represent possible types of values used in EVM.
/// ///
/// Type-safety is lost around the code that uses this type. We should have /// This callback function is used by the EVM to check if
/// complete set of unit tests covering all possible cases. /// there exists an account at given address.
/// The size of the type is 64 bytes and should fit in single cache line. /// @param env Pointer to execution environment managed by the host
union evm_variant { /// application.
/// A host-endian 64-bit integer.
int64_t int64;
/// A big-endian 256-bit integer or hash.
struct evm_uint256be uint256be;
/// A memory reference.
struct {
/// Pointer to the data.
uint8_t const* data;
/// Size of the referenced memory/data.
size_t data_size;
};
};
/// Query callback function.
///
/// This callback function is used by the EVM to query the host application
/// about additional information about accounts in the state required to
/// execute EVM code.
/// @param[out] result The result of the query.
/// @param env Pointer to execution environment managed by the host
/// application.
/// @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 address The address of the account the query is about.
/// /// @return 1 if exists, 0 otherwise.
/// ## Types of queries typedef int (*evm_account_exists_fn)(struct evm_env* env,
/// const struct evm_uint160be* address);
/// - ::EVM_ACCOUNT_EXISTS
/// @result evm_variant::int64 1 if exists, 0 if not.
///
///
/// @todo
/// - Consider swapping key and address arguments,
/// e.g. `query(result, env, addr, EVM_SLOAD, k)`.
/// - Consider renaming key argument to something else. Key is confusing
/// especially for SSTORE and SLOAD. Maybe "kind"?
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. /// Get storage callback function.
/// ///
@ -352,7 +307,7 @@ typedef void (*evm_call_fn)(
/// ///
/// @todo Merge evm_host with evm_env? /// @todo Merge evm_host with evm_env?
struct evm_host { struct evm_host {
evm_query_state_fn query; evm_account_exists_fn account_exists;
evm_get_storage_fn get_storage; evm_get_storage_fn get_storage;
evm_set_storage_fn set_storage; evm_set_storage_fn set_storage;
evm_get_balance_fn get_balance; evm_get_balance_fn get_balance;