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 1 commit
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
9 changes: 5 additions & 4 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
38 changes: 26 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,35 @@ 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.
*/
enum evmc_storage_status
{
EVMC_STORAGE_UNCHANGED = 0, /**< The storage item value unchanged. */
EVMC_STORAGE_MODIFIED = 1, /**< The storage item value modified. */
EVMC_STORAGE_ADDED = 2, /**< The storage item added. */
EVMC_STORAGE_DELETED = 3, /**< The storage item deleted. */
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.

Does this needs to expose special cases about 0?

Adding explanation above may be good. We have the following cases, please map them to codes:

  • zero -> zero (UNCHANGED, because value is always the same)
  • zero -> non-zero (ADDED)
  • non-zero -> zero (DELETED)
  • non-zero -> non-zero (same value: UNCHANGED)
  • non-zero -> non-zero (different value: MODIFIED)

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think the special case for zero -> zero is needed, this can be reported together with X -> X. It will not be needed in EIP-1087 either.

I will add more documentation. Thanks for suggestion.

Copy link
Member

@axic axic Aug 9, 2018

Choose a reason for hiding this comment

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

I guess the caller can deduce that by value == 0 && unchanged.

};


/**
* 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.
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.

Should have @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