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

Extend storage status #661

Merged
merged 4 commits into from
Aug 12, 2022
Merged

Extend storage status #661

merged 4 commits into from
Aug 12, 2022

Conversation

chfast
Copy link
Member

@chfast chfast commented Aug 5, 2022

Expand the number of storage statuses to cover all possible EVM
behaviors. These provide enough information to VM to compute not only
gas costs but also refunds. Including legacy SSTORE costs before net
gas metering.

@chfast chfast force-pushed the extend_storage_status branch from 911af80 to 2767330 Compare August 5, 2022 10:12
@chfast chfast requested review from axic, gumb0, holiman and yperbasis August 5, 2022 10:29
@chfast chfast force-pushed the extend_storage_status branch from 2767330 to 03dc899 Compare August 5, 2022 10:42
@codecov
Copy link

codecov bot commented Aug 5, 2022

Codecov Report

Merging #661 (df7f718) into master (ebe37b9) will increase coverage by 0.04%.
The diff coverage is 96.00%.

❗ Current head df7f718 differs from pull request most recent head b91b723. Consider uploading reports for the commit b91b723 to get more accurate results

@@            Coverage Diff             @@
##           master     #661      +/-   ##
==========================================
+ Coverage   93.08%   93.12%   +0.04%     
==========================================
  Files          25       25              
  Lines        3674     3770      +96     
  Branches      379      391      +12     
==========================================
+ Hits         3420     3511      +91     
- Misses        144      148       +4     
- Partials      110      111       +1     

@chfast
Copy link
Member Author

chfast commented Aug 5, 2022

I have Client-side implementation of this using only 4 checks:

  • original != current (dirty)
  • original == new_value (restored)
  • current != 0
  • new_value != 0

https://github.com/ethereum/evmone/blob/state/test/state/host.cpp#L99-L162 (unstable link).

Then you can get the gas cost and refund per revision from a lookup table.

@chfast chfast force-pushed the extend_storage_status branch from 03dc899 to b0ee9fc Compare August 9, 2022 09:49
* This corresponds to the EIP-2200 rule 2 where:
* c == v.
*/
EVMC_STORAGE_MODIFIED_AGAIN = 0,
Copy link
Member

Choose a reason for hiding this comment

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

Why EVMC_STORAGE_MODIFIED_AGAIN rather than EVMC_STORAGE_UNCHANGED?

Copy link
Member Author

Choose a reason for hiding this comment

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

It felt more correct to me: in general we modify a value, just gas cost does not care. The "unchanged" strongly suggests that current == value what is not always the case for this group. But I can change it to EVMC_STORAGE_UNCHANGED if people think this is fine.

Copy link
Member

Choose a reason for hiding this comment

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

What is this rule 2 of EIP-2200 referenced in the doc? "If current value equals new value (this is a no-op), SLOAD_GAS is deducted."? Or something else?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, this is a mistake. This a group of this rule (2) and 3.2 without matching any subrules of 3.2. If you can parse my DSL, this can be e.g. X → Y → Z. Because these have the same cost, I decided to use single enum value for it.

If you think this is too confusing, I can assign separate values to these. But this suggests these have different behavior what is not the case.

Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer separate EVMC_STORAGE_UNCHANGED and EVMC_STORAGE_MODIFIED_AGAIN for extra clarity, even if they are priced the same.

Copy link
Member

Choose a reason for hiding this comment

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

Just throwing in another idea: EVMC_STORAGE_ASSIGNED_AGAIN

Copy link
Member Author

Choose a reason for hiding this comment

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

REASSIGNED?

Time for twitter pool.

Copy link
Member

Choose a reason for hiding this comment

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

REASSIGNED is fine with me.

Copy link
Member Author

Choose a reason for hiding this comment

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

Based on the comments from @gumb0 and my preferences, can we leave it as EVMC_STATUS_MODIFIED_AGAIN? Also documentation is updated.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to EVMC_STORAGE_ASSIGNED.

include/evmc/evmc.h Outdated Show resolved Hide resolved
@chfast chfast force-pushed the extend_storage_status branch from b0ee9fc to c9f1100 Compare August 10, 2022 15:11
* this status should be assigned to all remaining cases.
*
* This corresponds to the EIP-2200 rule 2 or rule 3.2 without sub-rules, where:
* c == v or (c != v, o != c, (o == 0 or (o != 0, c != 0, v != 0)), o != v)
Copy link
Member

Choose a reason for hiding this comment

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

This is hard to parse, and rule numbers like 3.2.1.1 are not useful because don't exist in EIP.

I perfectly understand notation like X -> Y -> 0, why do you need this new one?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is redundant. I try to explain what EIP rules it matches with the ordered list on condition to reach the particular rules in the spec tree in the EIP.

Any ideas how to improve this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you think it is better to remove it? I can have separate doxygen chapter (md document) that describes all matching details using big tables.

Copy link
Member

Choose a reason for hiding this comment

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

I would rather remove them. The document looks good.

@chfast chfast force-pushed the extend_storage_status branch 2 times, most recently from ab3a03b to a980e44 Compare August 11, 2022 16:30
@chfast chfast force-pushed the extend_storage_status branch 3 times, most recently from 9dc1a64 to 6d9c8e6 Compare August 12, 2022 07:23
@chfast chfast force-pushed the extend_storage_status branch from df7f718 to c7f5282 Compare August 12, 2022 11:56
chfast and others added 4 commits August 12, 2022 20:01
Expand the number of storage statuses to cover all possible EVM
behaviors. These provide enough information to VM to compute not only
gas costs but also refunds. Including legacy SSTORE costs before net
gas metering.
@chfast chfast force-pushed the extend_storage_status branch from c7f5282 to b91b723 Compare August 12, 2022 18:02
@chfast chfast merged commit 32fc145 into master Aug 12, 2022
@chfast chfast deleted the extend_storage_status branch August 12, 2022 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants