Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage status #52

Merged
merged 3 commits into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions examples/capi.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,18 @@ static void get_storage(struct evmc_uint256be* result,
printf("\n");
}

static void set_storage(struct evmc_context* context,
const struct evmc_address* address,
const struct evmc_uint256be* key,
const struct evmc_uint256be* value)
static enum evmc_storage_status set_storage(struct evmc_context* context,
const struct evmc_address* address,
const struct evmc_uint256be* key,
const struct evmc_uint256be* value)
{
(void)context;
(void)key;
(void)value;
printf("EVM-C: SSTORE @");
print_address(address);
printf("\n");
return EVMC_STORAGE_UNCHANGED;
}

static void get_balance(struct evmc_uint256be* result,
Expand Down Expand Up @@ -141,14 +142,12 @@ static void get_block_hash(struct evmc_uint256be* result,
}

/// EVM log callback.
///
/// @note The `evm_log` name is used to avoid conflict with `log()` C function.
static void evm_log(struct evmc_context* context,
const struct evmc_address* address,
const uint8_t* data,
size_t data_size,
const struct evmc_uint256be topics[],
size_t topics_count)
static void emit_log(struct evmc_context* context,
Copy link
Member

@axic axic Aug 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack this change. Needs an ABI bump.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ABI is bumped in this PR already, but that's not needed in this case, because this is a static function in a example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right I thought it was renaming the member, but that was renamed before.

const struct evmc_address* address,
const uint8_t* data,
size_t data_size,
const struct evmc_uint256be topics[],
size_t topics_count)
{
(void)context;
(void)address;
Expand All @@ -160,7 +159,7 @@ 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, get_code_hash,
copy_code, selfdestruct, call, get_tx_context, get_block_hash, evm_log,
copy_code, selfdestruct, call, get_tx_context, get_block_hash, emit_log,
};

/// Example how the API is supposed to be used.
Expand Down
60 changes: 48 additions & 12 deletions include/evmc/evmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extern "C" {
enum
{
/** The EVMC ABI version number of the interface declared in this file. */
EVMC_ABI_VERSION = 4
EVMC_ABI_VERSION = 5
};

/**
Expand Down Expand Up @@ -451,21 +451,57 @@ typedef void (*evmc_get_storage_fn)(struct evmc_uint256be* result,
const struct evmc_address* address,
const struct evmc_uint256be* key);


/**
* The effect of an attempt to modify a contract storage item.
*
* For the purpose of explaining the meaning of each element, the following
* notation is used:
* - 0 is zero value,
* - X != 0 (X is any value other than 0),
* - Y != X, Y != 0 (Y is any value other than X and 0),
* - the "->" means the change from one value to another.
*/
enum evmc_storage_status
{
/**
* The value of a storage item has been left unchanged: 0 -> 0 and X -> X.
*/
EVMC_STORAGE_UNCHANGED = 0,

/**
* The value of a storage item has been modified: X -> Y.
*/
EVMC_STORAGE_MODIFIED = 1,

/**
* A new storage item has been added: 0 -> X.
*/
EVMC_STORAGE_ADDED = 2,

/**
* A storage item has been deleted: X -> 0.
*/
EVMC_STORAGE_DELETED = 3,
};


/**
* Set storage callback function.
*
* This callback function is used by an EVM to update the given contract
* storage entry.
* @param context The pointer to the Host execution context.
* @see ::evmc_context.
* @param address The address of the contract.
* @param key The index of the storage entry.
* @param value The value to be stored.
* This callback function is used by an EVM to update the given contract
* storage entry.
* @param context The pointer to the Host execution context.
* @see ::evmc_context.
* @param address The address of the contract.
* @param key The index of the storage entry.
* @param value The value to be stored.
* @return The effect on the storage item, @see ::evmc_storage_status.
*/
typedef void (*evmc_set_storage_fn)(struct evmc_context* context,
const struct evmc_address* address,
const struct evmc_uint256be* key,
const struct evmc_uint256be* value);
typedef enum evmc_storage_status (*evmc_set_storage_fn)(struct evmc_context* context,
const struct evmc_address* address,
const struct evmc_uint256be* key,
const struct evmc_uint256be* value);

/**
* Get balance callback function.
Expand Down