Skip to content

Commit c1f6bb2

Browse files
committed
Merge branch 'scroll' into feat/feynman-compression
2 parents 94c0531 + 8df56ac commit c1f6bb2

File tree

9 files changed

+301
-24
lines changed

9 files changed

+301
-24
lines changed

.github/workflows/lint.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ jobs:
2323
- type: scroll
2424
args: --bin scroll-reth --workspace --lib --examples --tests --benches --locked
2525
features: "skip-state-root-validation asm-keccak jemalloc jemalloc-prof min-error-logs min-warn-logs min-info-logs min-debug-logs min-trace-logs"
26-
- type: book
27-
args: --manifest-path book/sources/Cargo.toml --workspace --bins
28-
features: ""
26+
# issue <https://github.com/scroll-tech/reth/issues/250>
27+
# - type: book
28+
# args: --manifest-path book/sources/Cargo.toml --workspace --bins
29+
# features: ""
2930
steps:
3031
- uses: actions/checkout@v4
3132
- uses: rui314/setup-mold@v1

Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/scroll/alloy/evm/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ auto_impl = { workspace = true, default-features = false }
3333
serde = { workspace = true, default-features = false, features = ["derive"], optional = true }
3434

3535
[dev-dependencies]
36+
alloy-hardforks.workspace = true
37+
alloy-primitives = { workspace = true, features = ["getrandom"] }
3638
eyre.workspace = true
39+
reth-evm.workspace = true
40+
reth-scroll-chainspec.workspace = true
41+
reth-scroll-evm.workspace = true
3742

3843
[features]
3944
std = [
@@ -46,6 +51,8 @@ std = [
4651
"alloy-eips/std",
4752
"scroll-alloy-consensus/std",
4853
"scroll-alloy-hardforks/std",
54+
"reth-evm/std",
55+
"reth-scroll-chainspec/std",
4956
]
5057
serde = [
5158
"dep:serde",
@@ -56,4 +63,5 @@ serde = [
5663
"alloy-consensus/serde",
5764
"scroll-alloy-consensus/serde",
5865
"scroll-alloy-hardforks/serde",
66+
"alloy-hardforks/serde",
5967
]

crates/scroll/alloy/evm/src/block/mod.rs

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod receipt_builder;
55

66
use crate::{
77
block::curie::{apply_curie_hard_fork, L1_GAS_PRICE_ORACLE_ADDRESS},
8+
system_caller::ScrollSystemCaller,
89
IntoCompressed, ScrollEvm, ScrollEvmFactory, ScrollTransactionIntoTxEnv,
910
ScrollTxCompressionFactorCache, WithCompression,
1011
};
@@ -35,7 +36,7 @@ use scroll_alloy_consensus::L1_MESSAGE_TRANSACTION_TYPE;
3536
use scroll_alloy_hardforks::{ScrollHardfork, ScrollHardforks};
3637

3738
/// Context for Scroll Block Execution.
38-
#[derive(Debug, Clone)]
39+
#[derive(Debug, Default, Clone)]
3940
pub struct ScrollBlockExecutionCtx {
4041
/// Parent block hash.
4142
pub parent_hash: B256,
@@ -48,13 +49,16 @@ pub struct ScrollBlockExecutor<Evm, R: ScrollReceiptBuilder, Spec> {
4849
spec: Spec,
4950
/// Receipt builder.
5051
receipt_builder: R,
51-
5252
/// The EVM used by executor.
5353
evm: Evm,
54+
/// Context for block execution.
55+
ctx: ScrollBlockExecutionCtx,
5456
/// Receipts of executed transactions.
5557
receipts: Vec<R::Receipt>,
5658
/// Total gas used by executed transactions.
5759
gas_used: u64,
60+
/// Utility to call system smart contracts.
61+
system_caller: ScrollSystemCaller<Spec>,
5862
}
5963

6064
impl<E, R: ScrollReceiptBuilder, Spec> ScrollBlockExecutor<E, R, Spec> {
@@ -71,8 +75,53 @@ where
7175
Spec: ScrollHardforks + Clone,
7276
{
7377
/// Creates a new [`ScrollBlockExecutor`].
74-
pub const fn new(evm: E, spec: Spec, receipt_builder: R) -> Self {
75-
Self { evm, spec, receipt_builder, receipts: Vec::new(), gas_used: 0 }
78+
pub fn new(evm: E, ctx: ScrollBlockExecutionCtx, spec: Spec, receipt_builder: R) -> Self {
79+
Self {
80+
evm,
81+
ctx,
82+
system_caller: ScrollSystemCaller::new(spec.clone()),
83+
spec,
84+
receipt_builder,
85+
receipts: Vec::new(),
86+
gas_used: 0,
87+
}
88+
}
89+
}
90+
91+
impl<'db, DB, E, R, Spec> ScrollBlockExecutor<E, R, Spec>
92+
where
93+
DB: Database + 'db,
94+
E: EvmExt<
95+
DB = &'db mut State<DB>,
96+
Tx: FromRecoveredTx<R::Transaction> + FromTxWithEncoded<R::Transaction>,
97+
>,
98+
R: ScrollReceiptBuilder<
99+
Transaction: Transaction + Encodable2718 + RecoveredTx<R::Transaction>,
100+
Receipt: TxReceipt,
101+
>,
102+
Spec: ScrollHardforks,
103+
for<'a> &'a WithCompression<<R as ScrollReceiptBuilder>::Transaction>:
104+
IntoTxEnv<<E as alloy_evm::Evm>::Tx>,
105+
{
106+
/// Executes all transactions in a block, applying pre and post execution changes.
107+
pub fn execute_block_with_compression_cache(
108+
mut self,
109+
transactions: impl IntoIterator<
110+
Item = impl ExecutableTx<Self> + IntoCompressed<<Self as BlockExecutor>::Transaction>,
111+
>,
112+
mut compression_cache: ScrollTxCompressionFactorCache,
113+
) -> Result<BlockExecutionResult<R::Receipt>, BlockExecutionError>
114+
where
115+
Self: Sized,
116+
{
117+
self.apply_pre_execution_changes()?;
118+
119+
for tx in transactions {
120+
let tx = tx.into_compressed(Some(&mut compression_cache));
121+
self.execute_transaction(&tx)?;
122+
}
123+
124+
self.apply_post_execution_changes()
76125
}
77126
}
78127

@@ -133,13 +182,16 @@ where
133182
self.spec.is_spurious_dragon_active_at_block(self.evm.block().number);
134183
self.evm.db_mut().set_state_clear_flag(state_clear_flag);
135184

136-
// load the l1 gas oracle contract in cache
185+
// load the l1 gas oracle contract in cache.
137186
let _ = self
138187
.evm
139188
.db_mut()
140189
.load_cache_account(L1_GAS_PRICE_ORACLE_ADDRESS)
141190
.map_err(BlockExecutionError::other)?;
142191

192+
// apply eip-2935.
193+
self.system_caller.apply_blockhashes_contract_call(self.ctx.parent_hash, &mut self.evm)?;
194+
143195
if self
144196
.spec
145197
.scroll_fork_activation(ScrollHardfork::Curie)
@@ -353,12 +405,12 @@ where
353405
fn create_executor<'a, DB, I>(
354406
&'a self,
355407
evm: <ScrollEvmFactory as EvmFactory>::Evm<&'a mut State<DB>, I>,
356-
_ctx: Self::ExecutionCtx<'a>,
408+
ctx: Self::ExecutionCtx<'a>,
357409
) -> impl BlockExecutorFor<'a, Self, DB, I>
358410
where
359411
DB: Database + 'a,
360412
I: Inspector<ScrollContext<&'a mut State<DB>>> + 'a,
361413
{
362-
ScrollBlockExecutor::new(evm, &self.spec, &self.receipt_builder)
414+
ScrollBlockExecutor::new(evm, ctx, &self.spec, &self.receipt_builder)
363415
}
364416
}

crates/scroll/alloy/evm/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@
44
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
55
#![cfg_attr(not(feature = "std"), no_std)]
66

7+
mod block;
78
pub use block::{
89
curie, EvmExt, ReceiptBuilderCtx, ScrollBlockExecutionCtx, ScrollBlockExecutor,
910
ScrollBlockExecutorFactory, ScrollReceiptBuilder,
1011
};
11-
mod block;
1212

13+
mod tx;
1314
pub use tx::{
1415
compute_compression_factor, FromTxWithCompression, IntoCompressed, ScrollTransactionIntoTxEnv,
1516
ScrollTxCompressionFactorCache, WithCompression,
1617
};
17-
mod tx;
18+
19+
mod system_caller;
1820

1921
extern crate alloc;
2022

0 commit comments

Comments
 (0)