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

refactor: Hop use SSLOAD2 #618

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

refactor: Hop use SSLOAD2 #618

wants to merge 1 commit into from

Conversation

H3xept
Copy link
Contributor

@H3xept H3xept commented Mar 20, 2024

⚠️ DO NOT MERGE THIS IS JUST A SHOWCASE ⚠️

Long story short:

  • SLOAD is one of the most expensive opcodes, 2100 gas per evm word
  • A possible way to improve gas usage is start using smart-contract code as storage since EXTCODECOPY is cheaper for reads bigger than 1 word (https://www.evm.codes/#3c?fork=cancun - the caveat is that data will be write-once )

Reads:
https://zefram.xyz/posts/how-i-almost-cheesed-the-evm/
https://github.com/0xsequence/sstore2

Ideas:
(a) We could have facets read their configuration from contract code - this will only be efficient for big configs (not sure if we have such configs). The effect here could also be achieved by "flattening" the config into immutable variables.
(b) Create a "fork" of the diamond standard where the diamond storage is replaced by a contract-code-storage. This could lead to us reading the jump location for diamond dispatch + facet configurations in one go using EXTCODECOPY and avoiding the cost of multiple SLOADs.

⚠️ The code of this PR is just meant as a showcase on how SSLOAD2(Map) is used (I couldnt use the simple SSLOAD version without modifying a lot of logic, which was beyond the scope of this). The actual gas used by this change is higher than what the original hop facet uses.

wip

forge install: create3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant