Skip to content

Extend gas optimization for eth_createAccessList#8261

Merged
yperbasis merged 2 commits intoerigontech:develfrom
qkniep:devel
Oct 1, 2023
Merged

Extend gas optimization for eth_createAccessList#8261
yperbasis merged 2 commits intoerigontech:develfrom
qkniep:devel

Conversation

@qkniep
Copy link
Contributor

@qkniep qkniep commented Sep 21, 2023

This builds upon #3453 and #3524, which previously implemented gas optimizations for the access lists generated by Erigon's implementation of the eth_createAccessList RPC call.

Erigon currently optimizes inclusion of the recipient address based on how many storage keys are accessed, but does not perform the same optimization for sender address and precompiled contract addresses. These changes make the same optimization available for all of these cases.

Additionally, this handles the cases of block producer address and created smart contract addresses. If these cases were omitted on purpose since they heavily rely on state, it may still make sense to offer them to users but disable them by default.

Copy link
Member

@yperbasis yperbasis left a comment

Choose a reason for hiding this comment

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

I agree that it makes sense to extend the gas optimization to the sender and, since Shanghai, to the block producer. For precompiles it's a moot point because they don't have any storage. Created contracts, however, are not pre-warmed-up and so it's cheaper to warm them up explicitly with an access list. EIP-2929 & EIP-3651 list all pre-warmed-up accounts.

@qkniep
Copy link
Contributor Author

qkniep commented Sep 24, 2023

It makes sense that this change would not have an effect for the precompiles then.
Regarding created contracts, maybe I am misunderstanding this part of EIP-2929:

When a CREATE or CREATE2 opcode is called, immediately (ie. before checks are done to determine whether or not the address is unclaimed) add the address being created to accessed_addresses, but gas costs of CREATE and CREATE2 are unchanged.

I interpreted this as CREATE/CREATE2 opcodes leading to a "free" warm-up of the created contract's address. So, as long as there were no other accesses (e.g. EXTCODESIZE) before contract creation it would make sense to treat them the same as being pre-warmed-up.

@yperbasis
Copy link
Member

It makes sense that this change would not have an effect for the precompiles then. Regarding created contracts, maybe I am misunderstanding this part of EIP-2929:

When a CREATE or CREATE2 opcode is called, immediately (ie. before checks are done to determine whether or not the address is unclaimed) add the address being created to accessed_addresses, but gas costs of CREATE and CREATE2 are unchanged.

I interpreted this as CREATE/CREATE2 opcodes leading to a "free" warm-up of the created contract's address. So, as long as there were no other accesses (e.g. EXTCODESIZE) before contract creation it would make sense to treat them the same as being pre-warmed-up.

Yes, you're right.


// Retrieve the precompiles since they don't need to be added to the access list
precompiles := vm.ActivePrecompiles(chainConfig.Rules(blockNumber, header.Time))
excl := make(map[libcommon.Address]struct{})
Copy link
Member

Choose a reason for hiding this comment

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

From & to should also be added to excl

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a specific reason this should be handled both during tracing and after tracing? As I understand it, the resulting access list would be the same.
The way it is handled now excl also has very clear semantics of "this address should under no circumstances appear in the access list", which would make it easy to use with user-provided addresses as well. Whereas using excl for to and from would require differentiating between addAddress and addSlot again.

Copy link
Member

Choose a reason for hiding this comment

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

I was worrying about preserving backwards compatibility in the non-optimized case, but perhaps it's not that important. Now I'm thinking about making optimizeGas the default unless set to false explicitly.

@yperbasis yperbasis merged commit 3775f4a into erigontech:devel Oct 1, 2023
yperbasis added a commit that referenced this pull request Oct 1, 2023
Enable gas optimizations of PRs #3453 & #8261 unless the `optimizeGas`
argument is explicitly set to `false`.
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.

2 participants