-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat: add pre-block EIP-4788 beacon root contract call #4457
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
cfb497d
feat: add EIP-4788 pre block call
Rjected 23f0e8f
remove unused dep
Rjected c9bae72
cargo fmt
Rjected 9214d88
make clippy happy
Rjected e2749f9
move pre block call to BlockExecutor impl
Rjected e89d595
use `Database` methods on State<DB> instead of underlying StateProvider
Rjected a827fc2
remove reth-interfaces usage in tests
Rjected 6e2c9d4
assert exact error on cancun block without beacon block root
Rjected 434103b
apply pre block contract call in payload builder
Rjected 2c0291d
disable block base fee check and set block gas limit
Rjected 66abd72
stop using optional base fee feature
Rjected 6936f3e
init env correctly
Rjected 30b6320
fix usages of State
Rjected 66b29ee
fix beacon root contract code
Rjected 3788bf7
set system address nonce to zero
Rjected f0af29b
re-set beacon roots address
Rjected 2f6970c
remove system address from output
Rjected a8d3c14
remove beneficiary account from result state
Rjected 8d05d0b
change apply_pre_block_call to apply_beacon_root_contract_call
Rjected 0865e7a
use cancun helper fn
Rjected 0034849
add note about EIP161 state clear
Rjected bafd150
rename pre block call method in payload builder
Rjected f854021
use Database + DatabaseCommit instead of returning State
Rjected 1b539c4
remove old contract address
Rjected 8858761
add test for no nonce increments on empty system account
Rjected 493482a
add docs for pre_block_beacon_root_contract_call
Rjected 37d2e1a
explicitly set every TxEnv field before beacon root contract call
Rjected 63d8d48
fix tests
Rjected 71d6a17
set blob fields in beacon root txenv
Rjected ae9c5cc
remove todo for client consensus
Rjected 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 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 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 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 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 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 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 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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
use crate::config::revm_spec; | ||
use reth_primitives::{ | ||
constants::{BEACON_ROOTS_ADDRESS, SYSTEM_ADDRESS}, | ||
recover_signer, Address, Bytes, Chain, ChainSpec, Head, Header, Transaction, TransactionKind, | ||
TransactionSignedEcRecovered, TxEip1559, TxEip2930, TxEip4844, TxLegacy, U256, | ||
TransactionSignedEcRecovered, TxEip1559, TxEip2930, TxEip4844, TxLegacy, H256, U256, | ||
}; | ||
use revm::primitives::{AnalysisKind, BlockEnv, CfgEnv, SpecId, TransactTo, TxEnv}; | ||
use revm::primitives::{AnalysisKind, BlockEnv, CfgEnv, Env, SpecId, TransactTo, TxEnv}; | ||
|
||
/// Convenience function to call both [fill_cfg_env] and [fill_block_env] | ||
pub fn fill_cfg_and_block_env( | ||
|
@@ -106,6 +107,51 @@ pub fn tx_env_with_recovered(transaction: &TransactionSignedEcRecovered) -> TxEn | |
tx_env | ||
} | ||
|
||
/// Fill transaction environment with the EIP-4788 system contract message data. | ||
/// | ||
/// This requirements for the beacon root contract call defined by | ||
/// [EIP-4788](https://eips.ethereum.org/EIPS/eip-4788) are: | ||
/// | ||
/// At the start of processing any execution block where `block.timestamp >= FORK_TIMESTAMP` (i.e. | ||
/// before processing any transactions), call `BEACON_ROOTS_ADDRESS` as `SYSTEM_ADDRESS` with the | ||
/// 32-byte input of `header.parent_beacon_block_root`, a gas limit of `30_000_000`, and `0` value. | ||
/// This will trigger the `set()` routine of the beacon roots contract. This is a system operation | ||
/// and therefore: | ||
/// * the call must execute to completion | ||
/// * the call does not count against the block’s gas limit | ||
/// * the call does not follow the EIP-1559 burn semantics - no value should be transferred as | ||
/// part of the call | ||
/// * if no code exists at `BEACON_ROOTS_ADDRESS`, the call must fail silently | ||
pub fn fill_tx_env_with_beacon_root_contract_call(env: &mut Env, parent_beacon_block_root: H256) { | ||
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 great |
||
env.tx = TxEnv { | ||
caller: SYSTEM_ADDRESS, | ||
transact_to: TransactTo::Call(BEACON_ROOTS_ADDRESS), | ||
// Explicitly set nonce to None so revm does not do any nonce checks | ||
nonce: None, | ||
gas_limit: 30_000_000, | ||
value: U256::ZERO, | ||
data: parent_beacon_block_root.to_fixed_bytes().to_vec().into(), | ||
// Setting the gas price to zero enforces that no value is transferred as part of the call, | ||
// and that the call will not count against the block's gas limit | ||
gas_price: U256::ZERO, | ||
// The chain ID check is not relevant here and is disabled if set to None | ||
chain_id: None, | ||
// Setting the gas priority fee to None ensures the effective gas price is derived from the | ||
// `gas_price` field, which we need to be zero | ||
gas_priority_fee: None, | ||
access_list: Vec::new(), | ||
// blob fields can be None for this tx | ||
blob_hashes: Vec::new(), | ||
max_fee_per_blob_gas: None, | ||
}; | ||
|
||
// ensure the block gas limit is >= the tx | ||
env.block.gas_limit = U256::from(env.tx.gas_limit); | ||
|
||
// disable the base fee check for this call by setting the base fee to zero | ||
env.block.basefee = U256::ZERO; | ||
} | ||
|
||
/// Fill transaction environment from [TransactionSignedEcRecovered]. | ||
pub fn fill_tx_env_with_recovered(tx_env: &mut TxEnv, transaction: &TransactionSignedEcRecovered) { | ||
fill_tx_env(tx_env, transaction.as_ref(), transaction.signer()) | ||
|
Oops, something went wrong.
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.
yeah I think we need to figure out what to do here, but no blocker for this pr