Skip to content

Commit

Permalink
fix: execution (#82)
Browse files Browse the repository at this point in the history
* add additional test coverage for state root

* fix: l1 messages gas used + genesis state root + load gas oracle contract in cache

Signed-off-by: Gregory Edison <[email protected]>

* fix: fill_tx_env

Signed-off-by: Gregory Edison <[email protected]>

* fix: merge

Signed-off-by: Gregory Edison <[email protected]>

* fix: manifests

Signed-off-by: Gregory Edison <[email protected]>

* fix: apply spurious dragon and load gas oracle in pre-execution

Signed-off-by: Gregory Edison <[email protected]>

* fix: clippy

Signed-off-by: Gregory Edison <[email protected]>

* fix: chain config tests

Signed-off-by: Gregory Edison <[email protected]>

* fix: answer comments

Signed-off-by: Gregory Edison <[email protected]>

---------

Signed-off-by: Gregory Edison <[email protected]>
Co-authored-by: frisitano <[email protected]>
  • Loading branch information
greged93 and frisitano authored Dec 17, 2024
1 parent 133d9c0 commit b456d1f
Show file tree
Hide file tree
Showing 12 changed files with 155 additions and 149 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions crates/chainspec/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,6 @@ impl ChainSpec {

/// Get the initial base fee of the genesis block.
pub fn initial_base_fee(&self) -> Option<u64> {
// TODO(scroll): migrate to Chain::scroll() (introduced in https://github.com/alloy-rs/chains/pull/112) when alloy-chains is bumped to version 0.1.48
if self.chain == Chain::from_named(NamedChain::Scroll) ||
self.chain == Chain::from_named(NamedChain::ScrollSepolia)
{
return None
}

// If the base fee is set in the genesis block, we use that instead of the default.
let genesis_base_fee =
self.genesis.base_fee_per_gas.map(|fee| fee as u64).unwrap_or(INITIAL_BASE_FEE);
Expand Down
15 changes: 12 additions & 3 deletions crates/primitives/src/transaction/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ pub trait FillTxEnv {

impl FillTxEnv for TransactionSigned {
fn fill_tx_env(&self, tx_env: &mut TxEnv, sender: Address) {
#[cfg(all(feature = "optimism", not(feature = "scroll")))]
#[cfg(any(
all(feature = "optimism", not(feature = "scroll")),
all(feature = "scroll", not(feature = "optimism"))
))]
let envelope = alloy_eips::eip2718::Encodable2718::encoded_2718(self);

tx_env.caller = sender;
Expand Down Expand Up @@ -122,8 +125,8 @@ impl FillTxEnv for TransactionSigned {
tx_env.nonce = None;
tx_env.authorization_list = None;

// TODO (scroll): fill in the Scroll fields when revm fork is introduced in Reth.
// <https://github.com/scroll-tech/revm/blob/scroll-evm-executor/v49/crates/primitives/src/env.rs#L608-L611>
tx_env.scroll.is_l1_msg = true;
tx_env.scroll.rlp_bytes = None;
}
}

Expand All @@ -136,5 +139,11 @@ impl FillTxEnv for TransactionSigned {
enveloped_tx: Some(envelope.into()),
}
}

#[cfg(all(feature = "scroll", not(feature = "optimism")))]
if !self.is_l1_message() {
tx_env.scroll.is_l1_msg = false;
tx_env.scroll.rlp_bytes = Some(envelope.into());
}
}
}
5 changes: 3 additions & 2 deletions crates/scroll/chainspec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ reth-ethereum-forks.workspace = true
reth-primitives-traits.workspace = true
reth-network-peers.workspace = true

# scroll-reth
# scroll
reth-scroll-forks.workspace = true
reth-scroll-state-commitment.workspace = true

# ethereum
alloy-chains.workspace = true
Expand All @@ -38,8 +39,8 @@ derive_more.workspace = true
once_cell.workspace = true

[dev-dependencies]
reth-chainspec = { workspace = true, features = ["test-utils"] }
alloy-genesis.workspace = true
reth-chainspec = { workspace = true, features = ["test-utils"] }

[features]
default = ["std"]
Expand Down
190 changes: 76 additions & 114 deletions crates/scroll/chainspec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,22 @@ pub struct ScrollChainSpecBuilder {
impl ScrollChainSpecBuilder {
/// Construct a new builder from the scroll mainnet chain spec.
pub fn scroll_mainnet() -> Self {
let mut inner = ChainSpecBuilder::default()
.chain(SCROLL_MAINNET.chain)
.genesis(SCROLL_MAINNET.genesis.clone());
let forks = SCROLL_MAINNET.hardforks.clone();
inner = inner.with_forks(forks);
Self {
inner: ChainSpecBuilder::default()
.chain(SCROLL_MAINNET.chain)
.genesis(SCROLL_MAINNET.genesis.clone())
.with_forks(SCROLL_MAINNET.hardforks.clone()),
}
}

Self { inner }
/// Construct a new builder from the scroll sepolia chain spec.
pub fn scroll_sepolia() -> Self {
Self {
inner: ChainSpecBuilder::default()
.chain(SCROLL_SEPOLIA.chain)
.genesis(SCROLL_SEPOLIA.genesis.clone())
.with_forks(SCROLL_SEPOLIA.hardforks.clone()),
}
}
}

Expand Down Expand Up @@ -191,7 +200,7 @@ impl EthChainSpec for ScrollChainSpec {
}

fn genesis_hash(&self) -> B256 {
self.inner.genesis_hash()
*self.genesis_hash.get_or_init(|| self.genesis_header().hash_slow())
}

fn prune_delete_limit(&self) -> usize {
Expand All @@ -203,7 +212,7 @@ impl EthChainSpec for ScrollChainSpec {
}

fn genesis_header(&self) -> &Header {
self.inner.genesis_header()
self.inner.genesis_header.get_or_init(|| self.make_genesis_header())
}

fn genesis(&self) -> &Genesis {
Expand All @@ -219,6 +228,28 @@ impl EthChainSpec for ScrollChainSpec {
}
}

impl ScrollChainSpec {
fn make_genesis_header(&self) -> Header {
Header {
gas_limit: self.genesis.gas_limit,
difficulty: self.genesis.difficulty,
nonce: self.genesis.nonce.into(),
extra_data: self.genesis.extra_data.clone(),
state_root: reth_scroll_state_commitment::state_root_ref_unhashed(&self.genesis.alloc),
timestamp: self.genesis.timestamp,
mix_hash: self.genesis.mix_hash,
beneficiary: self.genesis.coinbase,
base_fee_per_gas: None,
withdrawals_root: None,
parent_beacon_block_root: None,
blob_gas_used: None,
excess_blob_gas: None,
requests_hash: None,
..Default::default()
}
}
}

impl Hardforks for ScrollChainSpec {
fn fork<H: reth_chainspec::Hardfork>(&self, fork: H) -> reth_chainspec::ForkCondition {
self.inner.fork(fork)
Expand Down Expand Up @@ -347,153 +378,84 @@ mod tests {
use reth_ethereum_forks::{EthereumHardfork, ForkHash};
use reth_scroll_forks::ScrollHardfork;

#[ignore = "waiting on https://github.com/scroll-tech/reth/pull/36"]
#[test]
fn scroll_mainnet_forkids() {
fn scroll_mainnet_genesis_hash() {
let scroll_mainnet =
ScrollChainSpecBuilder::scroll_mainnet().build(ScrollChainConfig::mainnet());
let _ =
scroll_mainnet.genesis_hash.set(SCROLL_MAINNET.genesis_hash.get().copied().unwrap());
assert_eq!(
b256!("bbc05efd412b7cd47a2ed0e5ddfcf87af251e414ea4c801d78b6784513180a80"),
scroll_mainnet.genesis_hash()
);
}

#[test]
fn scroll_sepolia_genesis_hash() {
let scroll_sepolia =
ScrollChainSpecBuilder::scroll_sepolia().build(ScrollChainConfig::sepolia());
assert_eq!(
b256!("aa62d1a8b2bffa9e5d2368b63aae0d98d54928bd713125e3fd9e5c896c68592c"),
scroll_sepolia.genesis_hash()
);
}

#[test]
fn scroll_mainnet_forkids() {
test_fork_ids(
&SCROLL_MAINNET,
&[
(
Head { number: 0, ..Default::default() },
ForkId { hash: ForkHash([0x67, 0xda, 0x02, 0x60]), next: 1704992401 },
ForkId { hash: ForkHash([0xea, 0x6b, 0x56, 0xca]), next: 5220340 },
),
(
Head { number: 0, timestamp: 1704992400, ..Default::default() },
ForkId { hash: ForkHash([0x67, 0xda, 0x02, 0x60]), next: 1704992401 },
Head { number: 5220340, ..Default::default() },
ForkId { hash: ForkHash([0xee, 0x46, 0xae, 0x2a]), next: 7096836 },
),
(
Head { number: 0, timestamp: 1704992401, ..Default::default() },
ForkId { hash: ForkHash([0x3c, 0x28, 0x3c, 0xb3]), next: 1710374401 },
Head { number: 7096836, ..Default::default() },
ForkId { hash: ForkHash([0x18, 0xd3, 0xc8, 0xd9]), next: 1724227200 },
),
(
Head { number: 0, timestamp: 1710374400, ..Default::default() },
ForkId { hash: ForkHash([0x3c, 0x28, 0x3c, 0xb3]), next: 1710374401 },
Head { number: 7096836, timestamp: 1724227200, ..Default::default() },
ForkId { hash: ForkHash([0xcc, 0xeb, 0x09, 0xb0]), next: 1725264000 },
),
(
Head { number: 0, timestamp: 1710374401, ..Default::default() },
ForkId { hash: ForkHash([0x51, 0xcc, 0x98, 0xb3]), next: 1720627201 },
),
(
Head { number: 0, timestamp: 1720627200, ..Default::default() },
ForkId { hash: ForkHash([0x51, 0xcc, 0x98, 0xb3]), next: 1720627201 },
),
(
Head { number: 0, timestamp: 1720627201, ..Default::default() },
ForkId { hash: ForkHash([0xe4, 0x01, 0x0e, 0xb9]), next: 1726070401 },
),
(
Head { number: 0, timestamp: 1726070401, ..Default::default() },
ForkId { hash: ForkHash([0xbc, 0x38, 0xf9, 0xca]), next: 0 },
Head { number: 7096836, timestamp: 1725264000, ..Default::default() },
ForkId { hash: ForkHash([0x21, 0xa2, 0x07, 0x54]), next: 0 },
),
],
);
}

#[ignore = "waiting on https://github.com/scroll-tech/reth/pull/36"]
#[test]
fn scroll_sepolia_forkids() {
test_fork_ids(
&SCROLL_SEPOLIA,
&[
(
Head { number: 0, ..Default::default() },
ForkId { hash: ForkHash([0x67, 0xa4, 0x03, 0x28]), next: 1699981200 },
),
(
Head { number: 0, timestamp: 1699981199, ..Default::default() },
ForkId { hash: ForkHash([0x67, 0xa4, 0x03, 0x28]), next: 1699981200 },
),
(
Head { number: 0, timestamp: 1699981200, ..Default::default() },
ForkId { hash: ForkHash([0xa4, 0x8d, 0x6a, 0x00]), next: 1708534800 },
),
(
Head { number: 0, timestamp: 1708534799, ..Default::default() },
ForkId { hash: ForkHash([0xa4, 0x8d, 0x6a, 0x00]), next: 1708534800 },
),
(
Head { number: 0, timestamp: 1708534800, ..Default::default() },
ForkId { hash: ForkHash([0xcc, 0x17, 0xc7, 0xeb]), next: 1716998400 },
ForkId { hash: ForkHash([0x25, 0xfa, 0xe4, 0x54]), next: 3747132 },
),
(
Head { number: 0, timestamp: 1716998399, ..Default::default() },
ForkId { hash: ForkHash([0xcc, 0x17, 0xc7, 0xeb]), next: 1716998400 },
Head { number: 3747132, ..Default::default() },
ForkId { hash: ForkHash([0xda, 0x76, 0xc2, 0x2d]), next: 4740239 },
),
(
Head { number: 0, timestamp: 1716998400, ..Default::default() },
ForkId { hash: ForkHash([0x54, 0x0a, 0x8c, 0x5d]), next: 1723478400 },
Head { number: 4740239, ..Default::default() },
ForkId { hash: ForkHash([0x9f, 0xb4, 0x75, 0xf1]), next: 1723622400 },
),
(
Head { number: 0, timestamp: 1723478399, ..Default::default() },
ForkId { hash: ForkHash([0x54, 0x0a, 0x8c, 0x5d]), next: 1723478400 },
Head { number: 4740239, timestamp: 1723622400, ..Default::default() },
ForkId { hash: ForkHash([0xe9, 0x26, 0xd4, 0x9b]), next: 1724832000 },
),
(
Head { number: 0, timestamp: 1723478400, ..Default::default() },
ForkId { hash: ForkHash([0x75, 0xde, 0xa4, 0x1e]), next: 1732633200 },
),
(
Head { number: 0, timestamp: 1732633200, ..Default::default() },
ForkId { hash: ForkHash([0x4a, 0x1c, 0x79, 0x2e]), next: 0 },
Head { number: 4740239, timestamp: 1724832000, ..Default::default() },
ForkId { hash: ForkHash([0x69, 0xf3, 0x7e, 0xde]), next: 0 },
),
],
);
}

#[ignore = "waiting on https://github.com/scroll-tech/reth/pull/36"]
#[test]
fn scroll_mainnet_genesis() {
let genesis = SCROLL_MAINNET.genesis_header();
println!("{:?}", genesis);
assert_eq!(
genesis.hash_slow(),
b256!("bbc05efd412b7cd47a2ed0e5ddfcf87af251e414ea4c801d78b6784513180a80")
);
let base_fee = genesis
.next_block_base_fee(SCROLL_MAINNET.base_fee_params_at_timestamp(genesis.timestamp))
.unwrap();
// <https://scrollscan.com/block/1>
assert_eq!(base_fee, 980000000);
}

#[ignore = "waiting on https://github.com/scroll-tech/reth/pull/36"]
#[test]
fn scroll_sepolia_genesis() {
let genesis = SCROLL_SEPOLIA.genesis_header();
assert_eq!(
genesis.hash_slow(),
b256!("aa62d1a8b2bffa9e5d2368b63aae0d98d54928bd713125e3fd9e5c896c68592c")
);
let base_fee = genesis
.next_block_base_fee(SCROLL_SEPOLIA.base_fee_params_at_timestamp(genesis.timestamp))
.unwrap();
// <https://base-sepolia.blockscout.com/block/1>
assert_eq!(base_fee, 980000000);
}

#[ignore = "waiting on https://github.com/scroll-tech/reth/pull/36"]
#[test]
fn latest_scroll_mainnet_fork_id() {
assert_eq!(
ForkId { hash: ForkHash([0xbc, 0x38, 0xf9, 0xca]), next: 0 },
SCROLL_MAINNET.latest_fork_id()
)
}

#[ignore = "waiting on https://github.com/scroll-tech/reth/pull/36"]
#[test]
fn latest_scroll_mainnet_fork_id_with_builder() {
let scroll_mainnet =
ScrollChainSpecBuilder::scroll_mainnet().build(ScrollChainConfig::mainnet());
assert_eq!(
ForkId { hash: ForkHash([0xbc, 0x38, 0xf9, 0xca]), next: 0 },
scroll_mainnet.latest_fork_id()
)
}

#[test]
fn is_bernoulli_active() {
let scroll_mainnet =
Expand Down
3 changes: 2 additions & 1 deletion crates/scroll/evm/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ impl ConfigureEvmEnv for ScrollEvmConfig {
}
block_env.basefee = U256::from(header.base_fee_per_gas.unwrap_or_default());
block_env.gas_limit = U256::from(header.gas_limit);
block_env.blob_excess_gas_and_price = None;
}

fn next_cfg_and_block_env(
Expand Down Expand Up @@ -274,7 +275,7 @@ mod tests {
difficulty: U256::ZERO,
basefee: U256::from(header.base_fee_per_gas.unwrap_or_default()),
gas_limit: U256::from(header.gas_limit),
..Default::default()
blob_excess_gas_and_price: None,
};
assert_eq!(block_env, expected)
}
Expand Down
Loading

0 comments on commit b456d1f

Please sign in to comment.