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

Support EIP-2929: Gas cost increases for state access opcodes #571

Merged
merged 6 commits into from
Apr 13, 2021

Conversation

yperbasis
Copy link
Member

@yperbasis yperbasis commented Feb 15, 2021

ethereum/evmone#289 & erigontech/silkworm#161 provide an example of EIP-2929 implementation.

@yperbasis yperbasis requested review from chfast and axic February 15, 2021 12:16
@yperbasis yperbasis force-pushed the eip-2929 branch 2 times, most recently from 9424768 to 7a1b2f3 Compare February 19, 2021 16:21
@yperbasis yperbasis added the changelog Deserves a CHANGELOG entry label Feb 25, 2021
include/evmc/evmc.h Outdated Show resolved Hide resolved
@@ -156,6 +156,15 @@ class MockedHost : public Host
return accounts.count(addr) != 0;
}

/// Access an account (EIP-2929).
evmc_access_status access_account(const address&) noexcept override { return EVMC_COLD_ACCESS; }
Copy link
Member

Choose a reason for hiding this comment

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

For later: we should implement some basic map of access to also return "warm" status. This will help with code coverage in evmone.

@chfast chfast force-pushed the eip-2929 branch 3 times, most recently from 74daa4b to 5304359 Compare March 29, 2021 16:16
@chfast chfast requested a review from gumb0 March 29, 2021 16:48
EXPECT_EQ(b[OP_CALLCODE].gas_cost, 100);
EXPECT_EQ(b[OP_DELEGATECALL].gas_cost, 100);
EXPECT_EQ(b[OP_STATICCALL].gas_cost, 100);
EXPECT_EQ(b[OP_SLOAD].gas_cost, 100);
}
Copy link
Member

Choose a reason for hiding this comment

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

Would also add selfdestruct/sstore to this list. They are special cases.

Copy link
Member Author

Choose a reason for hiding this comment

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

SELFDESTRUCT doesn't charge WARM_STORAGE_READ_COST (EIP-2929).

SSTORE had complicated pricing logic even prior to EIP-2929; I decided not to change the previous decision to assign 0 gas cost to it in evmc.

Copy link
Member

Choose a reason for hiding this comment

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

Fine to add these though for clarity (i.e. to document what you have just written).

include/evmc/evmc.h Outdated Show resolved Hide resolved
include/evmc/evmc.h Outdated Show resolved Hide resolved
include/evmc/evmc.h Outdated Show resolved Hide resolved
include/evmc/evmc.h Outdated Show resolved Hide resolved
/** Access account callback function (EIP-2929). */
evmc_access_account_fn access_account;

/** Access storage callback function (EIP-2929). */
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need to state EIP-2929 in every place? I am fine with it for now, but perhaps in the long term we don't need it?

* @param address The address of the account.
* @return 0 if cold access, 1 if warm access.
*/
int accessAccount(byte[] address);
Copy link
Member

@axic axic Mar 29, 2021

Choose a reason for hiding this comment

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

Could use boolean if it is a bool. accountExists does that.

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 used enum for clarity. It's not immediately obvious whether true means cold access or warm access.

Copy link
Member

Choose a reason for hiding this comment

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

In C yes, but in Java it seems to be only a number :)

Copy link
Member

Choose a reason for hiding this comment

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

We can leave a todo here to change this to enum or bool.

bindings/java/c/host.c Outdated Show resolved Hide resolved
bindings/java/c/host.c Outdated Show resolved Hide resolved
@@ -126,6 +126,8 @@ mod tests {

let host = ::evmc_sys::evmc_host_interface {
account_exists: None,
access_account: None,
Copy link
Member

@axic axic Mar 29, 2021

Choose a reason for hiding this comment

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

It just occurred to me account_exists should be after the accessing ones if we consider some lexical ordering?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, the ordering here is not lexical, but loosely logical. In

account_exists
access_account
access_storage
get_storage
...

access_account & access_storage are together between account and storage operations.

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 vote for lexical ordering.

Copy link
Member

Choose a reason for hiding this comment

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

I'm also not sure what is the point of bringing up "lexical" ordering. For logical ordering, they more belong to the transaction context, not state access (although name indicates otherwise). For me you can put them last after emit_log.

Copy link
Member

Choose a reason for hiding this comment

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

The other entries seemed to be lexically ordered, in most cases. I don't really care, it was just a remark.

Copy link
Member

Choose a reason for hiding this comment

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

I didn't notice that others are not ordered, then I don't care.

Copy link
Member

Choose a reason for hiding this comment

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

Still putting them last for historical and weak ABI stability seems a good option. I can do that in the final rebase.

@chfast chfast force-pushed the eip-2929 branch 7 times, most recently from addb263 to d4f426a Compare April 12, 2021 16:14
yperbasis and others added 6 commits April 13, 2021 13:37
Create new instruction metrics/costs table for Berlin EVM revision.
Use warm access costs from EIP-2929 "Gas cost increases for state access
opcodes": https://eips.ethereum.org/EIPS/eip-2929.
Add methods access_account() and access_storage() to
evmc_host_interface. These are to support EIP-2929 "Gas cost increases
for state access opcodes" https://eips.ethereum.org/EIPS/eip-2929.
This also defines EVMC_ACCESS_{WARM,COLD} constants for access status
representation.

Adjustments to Go/Java/Rust bindings are to be done in consecutive
commits.

Co-authored-by: Paweł Bylica <chfast@gmail.com>
Implement Java bindings for access_account() and access_storage()
Host methods.
Implement Go bindings for access_account() and access_storage()
Host methods.
Implement Rust bindings for access_account() and access_storage()
Host methods.
@chfast chfast merged commit 8124d85 into ethereum:master Apr 13, 2021
@chfast chfast deleted the eip-2929 branch April 13, 2021 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog Deserves a CHANGELOG entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants