Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
0249bd8
fixes
Rimeeeeee Oct 18, 2025
73ec143
fixes
Rimeeeeee Oct 18, 2025
5b99889
fix compilation
Soubhik-10 Oct 18, 2025
b5ce843
try use revm bal
Soubhik-10 Oct 18, 2025
c01e0d9
fixed import
Soubhik-10 Oct 19, 2025
0a1b3ec
traces
Soubhik-10 Oct 19, 2025
a4004e6
try fix
Soubhik-10 Oct 20, 2025
c8cdea0
sort
Soubhik-10 Oct 20, 2025
4dcf577
used rakita/bal
Rimeeeeee Oct 20, 2025
ae6e67a
fix: passed rev for revm and op-revm
Rimeeeeee Oct 22, 2025
22dc773
feat: rebase new approach for bal
Rimeeeeee Oct 30, 2025
510fe6a
fixes
Rimeeeeee Oct 30, 2025
f1ddd17
merge
Soubhik-10 Oct 30, 2025
4ca99bb
use built in fn
Soubhik-10 Oct 30, 2025
514b0ce
traces
Soubhik-10 Oct 30, 2025
b691235
revert things
Soubhik-10 Oct 31, 2025
313209e
withdrawl changes
Rimeeeeee Nov 4, 2025
a015c72
fixes
Rimeeeeee Nov 4, 2025
b0608ed
manually add withdrawals
Soubhik-10 Nov 4, 2025
4a15130
rm unwrap
Soubhik-10 Nov 4, 2025
f4111a8
fix index
Soubhik-10 Nov 4, 2025
f0d07e5
fix: saturating sub index
Rimeeeeee Nov 4, 2025
35e5e2d
fix index
Soubhik-10 Nov 4, 2025
056e3d7
removing duplcates and refactor
Rimeeeeee Nov 4, 2025
9c648c4
Merge branch 'new-approach4' of https://github.com/Rimeeeeee/evm into…
Rimeeeeee Nov 4, 2025
9f6eb5b
sort
Soubhik-10 Nov 4, 2025
8deb454
trace
Soubhik-10 Nov 4, 2025
d78a087
added prev tracing
Rimeeeeee Nov 4, 2025
869c9f8
fixes
Rimeeeeee Nov 4, 2025
83cd9cd
fixes
Rimeeeeee Nov 5, 2025
77d747f
trace
Soubhik-10 Nov 5, 2025
3c0af8a
Merge branch 'new-approach4' of https://github.com/Rimeeeeee/evm into…
Soubhik-10 Nov 5, 2025
4ab9db0
more traces
Soubhik-10 Nov 5, 2025
e6f2919
try fix balance
Soubhik-10 Nov 5, 2025
7b62385
fix
Soubhik-10 Nov 5, 2025
20d162f
update version
Soubhik-10 Nov 5, 2025
059f2ab
rm wrong logic
Soubhik-10 Nov 5, 2025
c8262c9
fixes: check if balance is empty for coinbase
Rimeeeeee Nov 5, 2025
334a8a1
fixes: check if balance is empty for coinbase
Rimeeeeee Nov 5, 2025
a134992
use reciepts
Soubhik-10 Nov 5, 2025
f01dbf8
reduce logs
Soubhik-10 Nov 5, 2025
fb85542
Merge branch 'main' into new-approach4
Soubhik-10 Nov 6, 2025
1abf9eb
version bump
Rimeeeeee Nov 6, 2025
325ff0b
Merge branch 'new-approach4' of https://github.com/Rimeeeeee/evm into…
Rimeeeeee Nov 6, 2025
9139f4a
fixes
Rimeeeeee Nov 6, 2025
b1bd0c3
Revert "fixes"
Soubhik-10 Nov 6, 2025
b6ebb0c
trace
Soubhik-10 Nov 6, 2025
b8948a2
add
Soubhik-10 Nov 21, 2025
93e6562
update
Soubhik-10 Nov 21, 2025
a716ab5
trace
Soubhik-10 Nov 21, 2025
a47c1fb
Merge branch 'main' into new-approach4
Rimeeeeee Dec 5, 2025
4f6b9c9
chore: remove handling withdrawal logic
Rimeeeeee Dec 5, 2025
4c99231
fixes
Rimeeeeee Dec 5, 2025
6030ccc
chore:changed database to DatabaseCommitExt
Rimeeeeee Dec 5, 2025
7fcb58b
Revert "chore:changed database to DatabaseCommitExt"
Soubhik-10 Dec 5, 2025
f76a338
fix
Soubhik-10 Dec 5, 2025
cf8d9c3
Revert "fix"
Soubhik-10 Dec 5, 2025
823c788
Reapply "chore:changed database to DatabaseCommitExt"
Soubhik-10 Dec 6, 2025
2b006af
chore: added DatabaseCommit and used revm fork
Rimeeeeee Dec 6, 2025
3c65097
fixes
Rimeeeeee Dec 6, 2025
ca59a00
chore: bump bal index in finish
Rimeeeeee Dec 7, 2025
c8fe9a1
fixes
Rimeeeeee Dec 7, 2025
2b07037
fixes
Rimeeeeee Dec 7, 2025
f7d618e
chore: bump alloy eip7928 dep
Rimeeeeee Dec 14, 2025
d12155d
Merge branch 'main' into bal-devnet-1
Rimeeeeee Dec 14, 2025
3591868
update
Soubhik-10 Dec 14, 2025
6101704
use main
Soubhik-10 Dec 16, 2025
167778d
update
Soubhik-10 Dec 17, 2025
6c2dec9
import
Rimeeeeee Dec 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,18 @@ alloy-evm = { version = "0.25.2", path = "crates/evm", default-features = false
alloy-op-evm = { version = "0.25.2", path = "crates/op-evm", default-features = false }

# alloy

alloy-eip7928 = { version = "0.2.0", default-features = false, git = "https://github.com/rakita/alloy-eips.git", rev = "734beaf" }

alloy-eip2124 = { version = "0.2", default-features = false }
alloy-chains = { version = "0.2.0", default-features = false }
alloy-eips = { version = "1.0.34", default-features = false }
alloy-consensus = { version = "1.0.27", default-features = false }
alloy-primitives = { version = "1.0.0", default-features = false }
alloy-sol-types = { version = "1.0.0", default-features = false }
alloy-hardforks = { version = "0.4.2" }
alloy-rpc-types-eth = { version = "1.0.27", default-features = false }
alloy-rpc-types-engine = { version = "1.0.27", default-features = false }
alloy-eips = { version = "1.1.3", default-features = false }
alloy-consensus = { version = "1.1.3", default-features = false }
alloy-primitives = { version = "1.4.1", default-features = false }
alloy-sol-types = { version = "1.4.1", default-features = false }
alloy-rpc-types-eth = { version = "1.1.3", default-features = false }
alloy-rpc-types-engine = { version = "1.1.3", default-features = false }
alloy-hardforks = { version = "0.4.3" }

# op-alloy
alloy-op-hardforks = { version = "0.4.2" }
Expand All @@ -56,20 +59,22 @@ op-alloy = { version = "0.23", default-features = false, features = [
] }

# revm
revm = { version = "33.0.0", default-features = false }
op-revm = { version = "14.0.0", default-features = false }
revm = { version = "33.1.0", default-features = false }
op-revm = { version = "14.1.0", default-features = false }

# misc
auto_impl = "1"
derive_more = { version = "2", default-features = false, features = ["full"] }
serde = { version = "1", default-features = false, features = ["derive"] }
thiserror = { version = "2.0.0", default-features = false }
serde_json = "1"
tracing = { version = "0.1.41", default-features = false }
test-case = "3"

[patch.crates-io]
# revm = { git = "https://github.com/bluealloy/revm", rev = "11b16259" }
# op-revm = { git = "https://github.com/bluealloy/revm", rev = "11b16259" }

#alloy-hardforks = { git = "https://github.com/alloy-rs/hardforks", rev = "0fd230f5aa24c4f6a8c593918b7449df0c20f60a" }
#alloy-op-hardforks = { git = "https://github.com/alloy-rs/hardforks", rev = "0fd230f5aa24c4f6a8c593918b7449df0c20f60a" }
revm = { git = "https://github.com/bluealloy/revm.git", branch = "rakita/bal" }
op-revm = { git = "https://github.com/bluealloy/revm.git", branch = "rakita/bal" }
alloy-eips = { git = "https://github.com/Soubhik-10/alloy", branch = "bal-devnet-1" }
alloy-consensus = { git = "https://github.com/Soubhik-10/alloy", branch = "bal-devnet-1" }
alloy-rpc-types-eth = { git = "https://github.com/Soubhik-10/alloy", branch = "bal-devnet-1" }
alloy-rpc-types-engine = { git = "https://github.com/Soubhik-10/alloy", branch = "bal-devnet-1" }
31 changes: 16 additions & 15 deletions crates/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ alloy-op-hardforks = { workspace = true, optional = true }
alloy-rpc-types-eth = { workspace = true, optional = true }
alloy-rpc-types-engine = { workspace = true, optional = true }

tracing.workspace = true
# alloy-eip7928.workspace = true

revm.workspace = true
op-revm = { workspace = true, optional = true }
op-alloy = { workspace = true, optional = true }
Expand All @@ -38,22 +41,20 @@ test-case.workspace = true

[features]
default = ["std"]
secp256k1 = [
"std",
"alloy-consensus/secp256k1",
]
secp256k1 = ["std", "alloy-consensus/secp256k1"]
std = [
"alloy-primitives/std",
"revm/std",
"alloy-consensus/std",
"alloy-eips/std",
"alloy-sol-types/std",
"derive_more/std",
"op-revm?/std",
"thiserror/std",
"op-alloy?/std",
"alloy-rpc-types-eth?/std",
"alloy-rpc-types-engine?/std"
"alloy-primitives/std",
"revm/std",
"alloy-consensus/std",
"alloy-eips/std",
"alloy-sol-types/std",
"derive_more/std",
"op-revm?/std",
"thiserror/std",
"op-alloy?/std",
"alloy-rpc-types-eth?/std",
"alloy-rpc-types-engine?/std",
"tracing/std",
]
op = ["op-revm", "op-alloy", "alloy-op-hardforks"]
overrides = ["dep:alloy-rpc-types-eth"]
Expand Down
25 changes: 13 additions & 12 deletions crates/evm/src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

use crate::{Database, Evm, EvmFactory, FromRecoveredTx, FromTxWithEncoded, RecoveredTx, ToTxEnv};
use alloc::{boxed::Box, vec::Vec};
use alloy_eips::eip7685::Requests;
use alloy_eips::{eip7685::Requests, eip7928::BlockAccessList};
use revm::{
context::result::{ExecutionResult, ResultAndState},
database::State,
inspector::NoOpInspector,
Inspector,
DatabaseCommit, Inspector,
};

mod error;
Expand Down Expand Up @@ -37,6 +36,8 @@ pub struct BlockExecutionResult<T> {
pub gas_used: u64,
/// Blob gas used by the block.
pub blob_gas_used: u64,
/// Block Access List of the block
pub block_access_list: Option<BlockAccessList>,
}

/// Helper trait to encapsulate requirements for a type to be used as input for [`BlockExecutor`].
Expand Down Expand Up @@ -328,22 +329,22 @@ pub trait BlockExecutor {
pub trait BlockExecutorFor<'a, F: BlockExecutorFactory + ?Sized, DB, I = NoOpInspector>
where
Self: BlockExecutor<
Evm = <F::EvmFactory as EvmFactory>::Evm<&'a mut State<DB>, I>,
Evm = <F::EvmFactory as EvmFactory>::Evm<DB, I>,
Transaction = F::Transaction,
Receipt = F::Receipt,
>,
DB: Database + 'a,
I: Inspector<<F::EvmFactory as EvmFactory>::Context<&'a mut State<DB>>> + 'a,
DB: StateDB + Database + 'a,
I: Inspector<<F::EvmFactory as EvmFactory>::Context<DB>> + 'a,
{
}

impl<'a, F, DB, I, T> BlockExecutorFor<'a, F, DB, I> for T
where
F: BlockExecutorFactory,
DB: Database + 'a,
I: Inspector<<F::EvmFactory as EvmFactory>::Context<&'a mut State<DB>>> + 'a,
DB: StateDB + Database + 'a,
I: Inspector<<F::EvmFactory as EvmFactory>::Context<DB>> + 'a,
T: BlockExecutor<
Evm = <F::EvmFactory as EvmFactory>::Evm<&'a mut State<DB>, I>,
Evm = <F::EvmFactory as EvmFactory>::Evm<DB, I>,
Transaction = F::Transaction,
Receipt = F::Receipt,
>,
Expand Down Expand Up @@ -467,10 +468,10 @@ pub trait BlockExecutorFactory: 'static {
/// ```
fn create_executor<'a, DB, I>(
&'a self,
evm: <Self::EvmFactory as EvmFactory>::Evm<&'a mut State<DB>, I>,
evm: <Self::EvmFactory as EvmFactory>::Evm<DB, I>,
ctx: Self::ExecutionCtx<'a>,
) -> impl BlockExecutorFor<'a, Self, DB, I>
where
DB: Database + 'a,
I: Inspector<<Self::EvmFactory as EvmFactory>::Context<&'a mut State<DB>>> + 'a;
DB: StateDB + DatabaseCommit + Database + 'a,
I: Inspector<<Self::EvmFactory as EvmFactory>::Context<DB>> + 'a;
}
92 changes: 67 additions & 25 deletions crates/evm/src/block/state.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! State database abstraction.

use alloy_primitives::Address;
use revm::database::State;
use alloy_eips::eip7928::BlockAccessList;
use revm::{
database::{states::bundle_state::BundleRetention, BundleState, State},
state::bal::Bal,
};

/// A type which has the state of the blockchain.
///
Expand All @@ -10,18 +13,30 @@ pub trait StateDB: revm::Database {
/// State clear EIP-161 is enabled in Spurious Dragon hardfork.
fn set_state_clear_flag(&mut self, has_state_clear: bool);

/// Iterates over received balances and increment all account balances.
///
/// **Note**: If account is not found inside cache state it will be loaded from database.
///
/// Update will create transitions for all accounts that are updated.
///
/// If using this to implement withdrawals, zero balances must be filtered out before calling
/// this function.
fn increment_balances(
&mut self,
balances: impl IntoIterator<Item = (Address, u128)>,
) -> Result<(), Self::Error>;
/// Gets a reference to the internal [`BundleState`]
fn bundle_state(&self) -> &BundleState;

/// Gets a mutable reference to the internal [`BundleState`]
fn bundle_state_mut(&mut self) -> &mut BundleState;

/// If the `State` has been built with the
/// [`revm::database::StateBuilder::with_bundle_prestate`] option, the pre-state will be
/// taken along with any changes made by [`StateDB::merge_transitions`].
fn take_bundle(&mut self) -> BundleState {
core::mem::take(self.bundle_state_mut())
}

/// Take all transitions and merge them inside [`BundleState`].
/// This action will create final post state and all reverts so that
/// we at any time revert state of bundle to the state before transition
/// is applied.
fn merge_transitions(&mut self, retention: BundleRetention);

/// Increments the internal BAL index used for tracking BAL transfers.
fn bump_bal_index(&mut self);

/// Takes the built Alloy BAL access list, if any.
fn take_built_alloy_bal(&mut self) -> Option<BlockAccessList>;
}

/// auto_impl unable to reconcile return associated type from supertrait
Expand All @@ -30,23 +45,50 @@ impl<T: StateDB> StateDB for &mut T {
StateDB::set_state_clear_flag(*self, has_state_clear);
}

fn increment_balances(
&mut self,
balances: impl IntoIterator<Item = (Address, u128)>,
) -> Result<(), Self::Error> {
StateDB::increment_balances(*self, balances)
fn bundle_state(&self) -> &BundleState {
StateDB::bundle_state(*self)
}

fn bundle_state_mut(&mut self) -> &mut BundleState {
StateDB::bundle_state_mut(*self)
}

fn merge_transitions(&mut self, retention: BundleRetention) {
StateDB::merge_transitions(*self, retention);
}

fn bump_bal_index(&mut self) {
StateDB::bump_bal_index(*self);
}

fn take_built_alloy_bal(&mut self) -> Option<BlockAccessList> {
StateDB::take_built_alloy_bal(*self)
}
}

impl<DB: revm::Database> StateDB for State<DB> {
fn set_state_clear_flag(&mut self, has_state_clear: bool) {
self.cache.set_state_clear_flag(has_state_clear);
Self::set_state_clear_flag(self, has_state_clear);
}

fn increment_balances(
&mut self,
balances: impl IntoIterator<Item = (Address, u128)>,
) -> Result<(), Self::Error> {
Self::increment_balances(self, balances)
fn bundle_state(&self) -> &BundleState {
&self.bundle_state
}

fn bundle_state_mut(&mut self) -> &mut BundleState {
&mut self.bundle_state
}
fn merge_transitions(&mut self, retention: BundleRetention) {
Self::merge_transitions(self, retention);
}
fn bump_bal_index(&mut self) {
let bal_index = self.bal_state.bump_bal_index();
bal_index
}
fn take_built_alloy_bal(&mut self) -> Option<BlockAccessList> {
let bal = self.bal_state.take_built_alloy_bal();
tracing::debug!("bal : {:?}", bal);
self.bal_state.bal_builder = Some(Bal::new());
bal
}
}
15 changes: 9 additions & 6 deletions crates/evm/src/block/state_changes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! State changes that are not related to transactions.

use super::{calc, BlockExecutionError};
use alloc::boxed::Box;
use alloy_consensus::BlockHeader;
use alloy_eips::eip4895::{Withdrawal, Withdrawals};
use alloy_hardforks::EthereumHardforks;
Expand Down Expand Up @@ -95,10 +96,8 @@ pub fn insert_post_block_withdrawals_balance_increments(
if spec.is_shanghai_active_at_timestamp(block_timestamp) {
if let Some(withdrawals) = withdrawals {
for withdrawal in withdrawals {
if withdrawal.amount > 0 {
*balance_increments.entry(withdrawal.address).or_default() +=
withdrawal.amount_wei().to::<u128>();
}
*balance_increments.entry(withdrawal.address).or_default() +=
withdrawal.amount_wei().to::<u128>();
}
}
}
Expand All @@ -114,6 +113,7 @@ pub fn balance_increment_state<DB>(
where
DB: Database,
{
tracing::debug!("Entered balance incr fn");
let mut load_account = |address: &Address| -> Result<(Address, Account), BlockExecutionError> {
let cache_account = state.basic(*address).map_err(|_| {
BlockExecutionError::msg("could not load account for balance increment")
Expand All @@ -130,13 +130,16 @@ where
storage: Default::default(),
status: AccountStatus::Touched,
transaction_id: 0,
original_info: Box::new(account.clone()),
},
))
};

balance_increments
let evm_state = balance_increments
.iter()
.filter(|(_, &balance)| balance != 0)
.map(|(addr, _)| load_account(addr))
.collect::<Result<EvmState, _>>()
.collect::<Result<EvmState, _>>();
tracing::debug!("Created balance increment state for {:?} accounts", evm_state);
evm_state
}
Loading
Loading