-
Notifications
You must be signed in to change notification settings - Fork 1k
EIP2935 - Use system call instead of direct storage modification #8243
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
Merged
siladu
merged 11 commits into
besu-eth:main
from
Gabriel-Trintinalia:eip29-25-as-system-call
Feb 5, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
871c22d
Implement EIP2935 as system call
Gabriel-Trintinalia ef918bd
Implement EIP2935 as system call
Gabriel-Trintinalia 45721bd
Rename class
Gabriel-Trintinalia 0a4be70
Rename class
Gabriel-Trintinalia 2647f03
Fix order and trace
Gabriel-Trintinalia 9f27fb0
Fix constructor order
Gabriel-Trintinalia 0e9ade3
Remove redundant method and move commit to same level
Gabriel-Trintinalia f3b72f3
Rename variable
Gabriel-Trintinalia 6bc3fa8
Merge branch 'main' into eip29-25-as-system-call
Gabriel-Trintinalia 33cd579
minor changes
Gabriel-Trintinalia 93baef0
Merge branch 'main' into eip29-25-as-system-call
Gabriel-Trintinalia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,91 +15,47 @@ | |
| package org.hyperledger.besu.ethereum.mainnet.blockhash; | ||
|
|
||
| import org.hyperledger.besu.datatypes.Address; | ||
| import org.hyperledger.besu.datatypes.Hash; | ||
| import org.hyperledger.besu.ethereum.core.MutableWorldState; | ||
| import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader; | ||
| import org.hyperledger.besu.evm.account.MutableAccount; | ||
| import org.hyperledger.besu.evm.worldstate.WorldUpdater; | ||
| import org.hyperledger.besu.ethereum.mainnet.systemcall.BlockProcessingContext; | ||
| import org.hyperledger.besu.ethereum.mainnet.systemcall.SystemCallProcessor; | ||
|
|
||
| import com.google.common.annotations.VisibleForTesting; | ||
| import org.apache.tuweni.units.bigints.UInt256; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.apache.tuweni.bytes.Bytes; | ||
|
|
||
| /** | ||
| * Processes and stores historical block hashes in accordance with EIP-2935. This class is | ||
| * responsible for managing the storage of block hashes to support EIP-2935, which introduces | ||
| * historical block hash access in smart contracts. | ||
| */ | ||
| public class PragueBlockHashProcessor extends CancunBlockHashProcessor { | ||
| private static final Logger LOG = LoggerFactory.getLogger(PragueBlockHashProcessor.class); | ||
|
|
||
| public static final Address HISTORY_STORAGE_ADDRESS = | ||
| private static final Address HISTORY_STORAGE_ADDRESS = | ||
| Address.fromHexString("0x0000f90827f1c53a10cb7a02335b175320002935"); | ||
|
|
||
| /** The HISTORY_SERVE_WINDOW */ | ||
| private static final long HISTORY_SERVE_WINDOW = 8191; | ||
|
|
||
| protected final long historyServeWindow; | ||
| protected final Address historyStorageAddress; | ||
|
|
||
| /** Constructs a BlockHashProcessor. */ | ||
| public PragueBlockHashProcessor() { | ||
| this(HISTORY_STORAGE_ADDRESS, HISTORY_SERVE_WINDOW); | ||
| this(HISTORY_STORAGE_ADDRESS); | ||
| } | ||
|
|
||
| /** | ||
| * Constructs a BlockHashProcessor with a specified history save window. This constructor is | ||
| * primarily used for testing. | ||
| * | ||
| * @param historyStorageAddress the address of the contract storing the history | ||
| * @param historyServeWindow The number of blocks for which history should be saved. | ||
| */ | ||
| @VisibleForTesting | ||
| public PragueBlockHashProcessor( | ||
| final Address historyStorageAddress, final long historyServeWindow) { | ||
| public PragueBlockHashProcessor(final Address historyStorageAddress) { | ||
| this.historyStorageAddress = historyStorageAddress; | ||
| this.historyServeWindow = historyServeWindow; | ||
| } | ||
|
|
||
| @Override | ||
| public void processBlockHashes( | ||
| final MutableWorldState mutableWorldState, final ProcessableBlockHeader currentBlockHeader) { | ||
| super.processBlockHashes(mutableWorldState, currentBlockHeader); | ||
|
|
||
| WorldUpdater worldUpdater = mutableWorldState.updater(); | ||
| final MutableAccount historyStorageAccount = worldUpdater.getAccount(historyStorageAddress); | ||
|
|
||
| if (historyStorageAccount != null | ||
| && historyStorageAccount.getNonce() > 0 | ||
| && currentBlockHeader.getNumber() > 0) { | ||
| storeParentHash(historyStorageAccount, currentBlockHeader); | ||
| } | ||
| worldUpdater.commit(); | ||
| } | ||
|
|
||
| /** | ||
| * Stores the hash of the parent block in the world state. | ||
| * | ||
| * @param account The account associated with the historical block hash storage. | ||
| * @param header The current block header being processed. | ||
| */ | ||
| private void storeParentHash(final MutableAccount account, final ProcessableBlockHeader header) { | ||
| storeHash(account, header.getNumber() - 1, header.getParentHash()); | ||
| } | ||
|
|
||
| /** | ||
| * Stores the hash in the world state. | ||
| * | ||
| * @param account The account associated with the historical block hash storage. | ||
| * @param number The slot to store. | ||
| * @param hash The hash to be stored. | ||
| */ | ||
| private void storeHash(final MutableAccount account, final long number, final Hash hash) { | ||
| UInt256 slot = UInt256.valueOf(number % historyServeWindow); | ||
| UInt256 value = UInt256.fromBytes(hash); | ||
| LOG.trace( | ||
| "Writing to {} {}=%{}", account.getAddress(), slot.toDecimalString(), value.toHexString()); | ||
| account.setStorageValue(slot, value); | ||
| public Void process(final BlockProcessingContext context) { | ||
| super.process(context); | ||
| SystemCallProcessor processor = | ||
| new SystemCallProcessor(context.getProtocolSpec().getTransactionProcessor()); | ||
|
|
||
| Bytes inputData = context.getBlockHeader().getParentHash(); | ||
| processor.process(historyStorageAddress, context, inputData); | ||
| return null; | ||
|
Comment on lines
+52
to
+59
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the important change of this PR. The rest is refactoring. |
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you think this could change in the future? Having the
BlockHashProcessorhave a handle on the window size makes it more extendable in another fork if the window changes