Skip to content

Commit bd3280d

Browse files
Some preliminary fixes of crates/reth/node and crates/reth/evm
1 parent d9d08fa commit bd3280d

File tree

16 files changed

+1658
-2673
lines changed

16 files changed

+1658
-2673
lines changed

Cargo.lock

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

bin/alpen-cli/src/cmd/drain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub async fn drain(
105105
.value(U256::from(1));
106106

107107
let gas_price = l2w.get_gas_price().await.unwrap();
108-
let gas_estimate = l2w.estimate_gas(&estimate_tx).await.unwrap() as u128;
108+
let gas_estimate = l2w.estimate_gas(estimate_tx).await.unwrap() as u128;
109109

110110
let total_fee = gas_estimate * gas_price;
111111
let max_send_amount = balance.saturating_sub(U256::from(total_fee));

crates/proof-impl/evm-ee-stf/src/db.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ use std::collections::hash_map::Entry;
2222
use alloy_primitives::map::{DefaultHashBuilder, HashMap};
2323
use anyhow::{anyhow, Result};
2424
use revm::{
25-
db::{AccountState, DbAccount, InMemoryDB},
26-
primitives::{AccountInfo, Bytecode},
25+
bytecode::Bytecode,
26+
database::{AccountState, Cache, DbAccount, InMemoryDB},
27+
state::AccountInfo,
2728
};
2829
use revm_primitives::alloy_primitives::{Address, Bytes, B256, U256};
2930

@@ -142,21 +143,24 @@ impl InMemoryDBHelper for InMemoryDB {
142143

143144
// Return the DB.
144145
Ok(InMemoryDB {
145-
accounts,
146-
block_hashes,
146+
cache: Cache {
147+
accounts,
148+
block_hashes,
149+
..Default::default()
150+
},
147151
..Default::default()
148152
})
149153
}
150154

151155
fn get_account_info(&self, address: Address) -> Result<Option<AccountInfo>> {
152-
match self.accounts.get(&address) {
156+
match self.cache.accounts.get(&address) {
153157
Some(db_account) => Ok(db_account.info()),
154158
None => Err(anyhow!("Account not found.")),
155159
}
156160
}
157161

158162
fn get_storage_slot(&self, address: Address, index: U256) -> Result<U256> {
159-
match self.accounts.get(&address) {
163+
match self.cache.accounts.get(&address) {
160164
Some(account) => match account.storage.get(&index) {
161165
Some(value) => Ok(*value),
162166
None => match account.account_state {
@@ -171,14 +175,14 @@ impl InMemoryDBHelper for InMemoryDB {
171175

172176
fn storage_keys(&self) -> HashMap<Address, Vec<U256>> {
173177
let mut out = HashMap::with_hasher(alloy_primitives::map::DefaultHashBuilder::default());
174-
for (address, account) in &self.accounts {
178+
for (address, account) in &self.cache.accounts {
175179
out.insert(*address, account.storage.keys().cloned().collect());
176180
}
177181
out
178182
}
179183

180184
fn insert_block_hash(&mut self, block_number: U256, block_hash: B256) {
181-
match self.block_hashes.entry(block_number) {
185+
match self.cache.block_hashes.entry(block_number) {
182186
Entry::Occupied(entry) => assert_eq!(&block_hash, entry.get()),
183187
Entry::Vacant(entry) => {
184188
entry.insert(block_hash);

crates/proof-impl/evm-ee-stf/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use db::InMemoryDBHelper;
2626
use mpt::keccak;
2727
pub use primitives::{EvmBlockStfInput, EvmBlockStfOutput};
2828
use processor::{EvmConfig, EvmProcessor};
29-
use revm::{primitives::SpecId, InMemoryDB};
29+
use revm::{database::InMemoryDB, primitives::hardfork::SpecId};
3030
use revm_primitives::alloy_primitives::B256;
3131
use utils::generate_exec_update;
3232
use zkaleido::ZkVmEnv;
@@ -112,7 +112,7 @@ pub fn process_block_transaction_outer(zkvm: &impl ZkVmEnv) {
112112

113113
#[cfg(test)]
114114
mod tests {
115-
use revm::primitives::SpecId;
115+
use revm::primitives::hardfork::SpecId;
116116
use serde::{Deserialize, Serialize};
117117

118118
use super::*;

crates/proof-impl/evm-ee-stf/src/primitives.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
use std::collections::HashMap;
22

3-
use alloy_consensus::{serde_bincode_compat as serde_bincode_compat_header, Header};
3+
use alloy_consensus::{
4+
serde_bincode_compat::{self as serde_bincode_compat_header},
5+
transaction::serde_bincode_compat as serde_bincode_compat_tx,
6+
EthereumTxEnvelope, Header, TxEip4844,
7+
};
48
use alloy_eips::eip4895::Withdrawal;
59
use alpen_reth_primitives::WithdrawalIntent;
6-
use reth_primitives::TransactionSigned;
710
use revm_primitives::alloy_primitives::{Address, Bytes, FixedBytes, B256};
811
use serde::{Deserialize, Serialize};
912
use serde_with::serde_as;
@@ -73,9 +76,8 @@ pub struct EvmBlockStfInput {
7376
pub ancestor_headers: Vec<Header>,
7477

7578
/// A list of transactions to process.
76-
// #[serde_as(as = "Vec<serde_bincode_compat::TransactionSigned>")]
77-
// https://github.com/paradigmxyz/reth/issues/15751
78-
pub transactions: Vec<TransactionSigned>,
79+
#[serde_as(as = "Vec<serde_bincode_compat_tx::EthereumTxEnvelope<'_>>")]
80+
pub transactions: Vec<EthereumTxEnvelope<TxEip4844>>,
7981

8082
/// A list of withdrawals to process.
8183
pub withdrawals: Vec<Withdrawal>,

crates/proof-impl/evm-ee-stf/src/processor.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,18 @@ use alloy_primitives::map::DefaultHashBuilder;
2626
use alloy_rlp::BufMut;
2727
use alloy_rpc_types_eth::TransactionTrait;
2828
use alloy_trie::root::ordered_trie_root_with_encoder;
29-
use alpen_reth_evm::set_evm_handles;
3029
use anyhow::anyhow;
3130
use reth_primitives::{Header, Receipt, Transaction, TransactionSigned};
3231
use reth_primitives_traits::{constants::MINIMUM_GAS_LIMIT, SignedTransaction};
3332
use revm::{
34-
db::{AccountState, InMemoryDB},
35-
interpreter::Host,
36-
primitives::{SpecId, TransactTo, TxEnv},
37-
Database, DatabaseCommit, Evm,
38-
};
39-
use revm_primitives::{
40-
alloy_primitives::{Address, Bloom, TxKind as TransactionKind, U256},
41-
Account,
33+
context::{tx::TxEnv, Evm},
34+
context_interface::TransactTo,
35+
database::{AccountState, InMemoryDB},
36+
primitives::hardfork::SpecId,
37+
state::AccountInfo,
38+
Database, DatabaseCommit,
4239
};
40+
use revm_primitives::alloy_primitives::{Address, Bloom, TxKind as TransactionKind, U256};
4341

4442
use crate::{
4543
mpt::{keccak, RlpBytes, StateAccount},
@@ -191,7 +189,7 @@ where
191189
blk_env.gas_limit = U256::from(self.header.as_mut().unwrap().gas_limit);
192190
})
193191
.with_db(self.db.take().unwrap())
194-
.append_handler_register(set_evm_handles)
192+
//.append_handler_register(set_evm_handles)
195193
.build();
196194

197195
let mut logs_bloom = Bloom::default();
@@ -282,7 +280,7 @@ impl EvmProcessor<InMemoryDB> {
282280
let db = self.db.take().expect("DB not initialized");
283281

284282
let mut state_trie = mem::take(&mut self.input.pre_state_trie);
285-
for (address, account) in &db.accounts {
283+
for (address, account) in &db.cache.accounts {
286284
// Ignore untouched accounts.
287285
if account.account_state == AccountState::None {
288286
continue;
@@ -357,15 +355,15 @@ fn fill_eth_tx_env(tx_env: &mut TxEnv, essence: &Transaction, caller: Address) {
357355
tx_env.value = tx.value;
358356
tx_env.data = tx.input.clone();
359357
tx_env.chain_id = tx.chain_id;
360-
tx_env.nonce = Some(tx.nonce);
358+
tx_env.nonce = tx.nonce;
361359
tx_env.access_list.clear();
362360
}
363361
Transaction::Eip2930(tx) => {
364362
tx_env.caller = caller;
365363
tx_env.gas_limit = tx.gas_limit;
366364
tx_env.gas_price = U256::from(tx.gas_price);
367365
tx_env.gas_priority_fee = None;
368-
tx_env.transact_to = if let TransactionKind::Call(to_addr) = tx.to {
366+
tx_env.to = if let TransactionKind::Call(to_addr) = tx.to {
369367
TransactTo::Call(to_addr)
370368
} else {
371369
TransactTo::Create
@@ -407,7 +405,7 @@ where
407405
<D as Database>::Error: core::fmt::Debug,
408406
{
409407
// Read account from database
410-
let mut account: Account = db
408+
let mut account: AccountInfo = db
411409
.basic(address)
412410
.map_err(|db_err| {
413411
anyhow!(
@@ -419,7 +417,7 @@ where
419417
.unwrap_or_default()
420418
.into();
421419
// Credit withdrawal amount
422-
account.info.balance = account.info.balance.checked_add(amount_wei).unwrap();
420+
account.balance = account.balance.checked_add(amount_wei).unwrap();
423421
account.mark_touch();
424422
// Commit changes to database
425423

crates/reth/evm/src/config.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
use std::sync::Arc;
22

33
use revm::{
4-
handler::register::EvmHandler,
5-
primitives::{Address, EVMError, SpecId, U256},
6-
Context, ContextPrecompile, Database,
4+
context::result::EVMError,
5+
precompile::{PrecompileWithAddress, Precompiles},
6+
primitives::{Address, U256},
7+
Context, Database,
78
};
8-
use revm_primitives::Precompile;
99

10-
use crate::{
11-
constants::{BASEFEE_ADDRESS, FIXED_WITHDRAWAL_WEI, SCHNORR_ADDRESS},
12-
precompiles::{
13-
bridge::{BridgeoutPrecompile, BRIDGEOUT_ADDRESS},
14-
schnorr::verify_schnorr_precompile,
15-
},
16-
};
10+
use crate::{constants::SCHNORR_ADDRESS, precompiles::schnorr::verify_schnorr_precompile};
1711

1812
/// Add rollup specific customizations to EVM
19-
pub fn set_evm_handles<EXT, DB>(handler: &mut EvmHandler<EXT, DB>)
13+
pub fn set_evm_handles<EXT, DB>()
2014
where
2115
DB: Database,
2216
{
17+
/*
2318
let spec_id = handler.cfg.spec_id;
2419
2520
// install the precompiles
@@ -54,12 +49,13 @@ where
5449
5550
prev_handle(context, gas)
5651
})
52+
*/
5753
}
5854

5955
enum BalanceUpdate {
6056
Add(U256),
6157
}
62-
58+
/*
6359
fn update_account_balance<EXT, DB: Database>(
6460
context: &mut Context<EXT, DB>,
6561
address: Address,
@@ -77,3 +73,14 @@ fn update_account_balance<EXT, DB: Database>(
7773
7874
Ok(())
7975
}
76+
*/
77+
78+
pub fn get_precompiles() -> Precompiles {
79+
let mut p = Precompiles::default();
80+
p.extend([PrecompileWithAddress(
81+
SCHNORR_ADDRESS,
82+
verify_schnorr_precompile,
83+
)]);
84+
85+
p
86+
}

crates/reth/evm/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ pub mod constants;
66
mod precompiles;
77
mod utils;
88

9-
pub use config::set_evm_handles;
9+
pub use config::{get_precompiles, set_evm_handles};
1010
pub use utils::collect_withdrawal_intents;

crates/reth/evm/src/precompiles/bridge.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use alpen_reth_primitives::WithdrawalIntentEvent;
22
use revm::{
3-
primitives::{PrecompileError, PrecompileErrors, PrecompileOutput, PrecompileResult},
3+
precompile::{PrecompileError, PrecompileOutput, PrecompileResult},
44
ContextStatefulPrecompile, Database,
55
};
66
use revm_primitives::{Bytes, Log, LogData, U256};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
pub mod bridge;
1+
//pub mod bridge;
22
pub mod schnorr;

crates/reth/evm/src/precompiles/schnorr.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use revm::{
2-
precompile::utilities::right_pad,
3-
primitives::{PrecompileOutput, PrecompileResult},
4-
};
1+
use revm::precompile::{utilities::right_pad, PrecompileOutput, PrecompileResult};
52
use revm_primitives::Bytes;
63
use strata_crypto::verify_schnorr_sig;
74
use strata_primitives::buf::{Buf32, Buf64};

crates/reth/evm/src/utils.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,15 @@ where
4545
}
4646

4747
let txid = Buf32(tx.hash().as_slice().try_into().expect("32 bytes"));
48-
WithdrawalIntentEvent::decode_log(log, true)
49-
.ok()
50-
.and_then(|evt| {
51-
Descriptor::from_bytes(&evt.destination)
52-
.ok()
53-
.map(|destination| WithdrawalIntent {
54-
amt: evt.amount,
55-
destination,
56-
withdrawal_txid: txid,
57-
})
58-
})
48+
WithdrawalIntentEvent::decode_log(log).ok().and_then(|evt| {
49+
Descriptor::from_bytes(&evt.destination)
50+
.ok()
51+
.map(|destination| WithdrawalIntent {
52+
amt: evt.amount,
53+
destination,
54+
withdrawal_txid: txid,
55+
})
56+
})
5957
})
6058
})
6159
}

crates/reth/node/src/engine.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,42 +28,51 @@ pub struct StrataEngineTypes<T: PayloadTypes = StrataPayloadTypes> {
2828

2929
impl<T: PayloadTypes> PayloadTypes for StrataEngineTypes<T> {
3030
type BuiltPayload = T::BuiltPayload;
31+
type ExecutionData = ExecutionData;
3132
type PayloadAttributes = T::PayloadAttributes;
3233
type PayloadBuilderAttributes = T::PayloadBuilderAttributes;
34+
35+
fn block_to_payload(
36+
block: SealedBlock<
37+
<<Self::BuiltPayload as BuiltPayload>::Primitives as NodePrimitives>::Block,
38+
>,
39+
) -> ExecutionData {
40+
let (payload, sidecar) =
41+
ExecutionPayload::from_block_unchecked(block.hash(), &block.into_block());
42+
ExecutionData { payload, sidecar }
43+
}
3344
}
3445

35-
impl<T: PayloadTypes> EngineTypes for StrataEngineTypes<T>
46+
impl<T: PayloadTypes<ExecutionData = ExecutionData>> EngineTypes for StrataEngineTypes<T>
3647
where
3748
T::BuiltPayload: BuiltPayload<Primitives: NodePrimitives<Block = reth_primitives::Block>>
3849
+ TryInto<ExecutionPayloadV1>
3950
+ TryInto<StrataExecutionPayloadEnvelopeV2>
4051
+ TryInto<ExecutionPayloadEnvelopeV3>
4152
+ TryInto<ExecutionPayloadEnvelopeV4>,
4253
{
43-
type ExecutionData = ExecutionData;
4454
type ExecutionPayloadEnvelopeV1 = ExecutionPayloadV1;
4555
type ExecutionPayloadEnvelopeV2 = StrataExecutionPayloadEnvelopeV2;
4656
type ExecutionPayloadEnvelopeV3 = ExecutionPayloadEnvelopeV3;
4757
type ExecutionPayloadEnvelopeV4 = ExecutionPayloadEnvelopeV4;
48-
49-
fn block_to_payload(
50-
block: SealedBlock<
51-
<<Self::BuiltPayload as BuiltPayload>::Primitives as NodePrimitives>::Block,
52-
>,
53-
) -> ExecutionData {
54-
let (payload, sidecar) =
55-
ExecutionPayload::from_block_unchecked(block.hash(), &block.into_block());
56-
ExecutionData { payload, sidecar }
57-
}
5858
}
5959

6060
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
61-
pub struct StrataPayloadTypes;
61+
pub struct StrataPayloadTypes<N: NodePrimitives = NodePrimitives>;
6262

6363
impl PayloadTypes for StrataPayloadTypes {
64+
type ExecutionData = ExecutionData;
6465
type BuiltPayload = StrataBuiltPayload;
6566
type PayloadAttributes = StrataPayloadAttributes;
6667
type PayloadBuilderAttributes = StrataPayloadBuilderAttributes;
68+
69+
fn block_to_payload(
70+
block: SealedBlock<
71+
<<Self::BuiltPayload as BuiltPayload>::Primitives as NodePrimitives>::Block,
72+
>,
73+
) -> Self::ExecutionData {
74+
Self::ExecutionData::from_block_unchecked(block.hash(), &block.into_block())
75+
}
6776
}
6877

6978
/// Strata engine validator

0 commit comments

Comments
 (0)