Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 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
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
30 changes: 17 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,18 @@ alloy-evm = { version = "0.24.2", path = "crates/evm", default-features = false
alloy-op-evm = { version = "0.24.2", path = "crates/op-evm", default-features = false }

# alloy

# alloy-eip7928 = { version = "0.1.0", default-features = false, git = "https://github.com/alloy-rs/eips.git" }

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-eips = { version = "1.1.2", default-features = false }
alloy-consensus = { version = "1.1.2", 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-rpc-types-eth = { version = "1.1.2", default-features = false }
alloy-rpc-types-engine = { version = "1.1.2", default-features = false }
alloy-hardforks = { version = "0.4.3" }

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

# revm
revm = { version = "33.0.0", default-features = false }
op-revm = { version = "14.0.0", default-features = false }
revm = { version = "31.0.0", default-features = false }
op-revm = { version = "12.0.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" }
alloy-consensus = { git = "https://github.com/Soubhik-10/alloy", branch = "bal" }
alloy-rpc-types-eth = { git = "https://github.com/Soubhik-10/alloy", branch = "bal" }
alloy-rpc-types-engine = { git = "https://github.com/Soubhik-10/alloy", branch = "bal" }
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
4 changes: 3 additions & 1 deletion crates/evm/src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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,
Expand Down Expand Up @@ -34,6 +34,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
8 changes: 6 additions & 2 deletions crates/evm/src/block/state_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,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.load_cache_account(*address).map_err(|_| {
BlockExecutionError::msg("could not load account for balance increment")
Expand All @@ -131,13 +132,16 @@ where
storage: Default::default(),
status: AccountStatus::Touched,
transaction_id: 0,
original_info: account.info.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
}
128 changes: 124 additions & 4 deletions crates/evm/src/eth/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ use crate::{
};
use alloc::{borrow::Cow, boxed::Box, vec::Vec};
use alloy_consensus::{Header, Transaction, TxReceipt};
use alloy_eips::{eip4895::Withdrawals, eip7685::Requests, Encodable2718};
use alloy_eips::{
eip4895::Withdrawals,
eip7685::Requests,
eip7928::{AccountChanges, BalanceChange, BlockAccessList},
Encodable2718,
};
use alloy_hardforks::EthereumHardfork;
use alloy_primitives::{Log, B256};
use alloy_primitives::{map::HashMap, Log, B256, U256};
use revm::{
context::Block, context_interface::result::ResultAndState, database::State, DatabaseCommit,
Inspector,
Expand Down Expand Up @@ -106,7 +111,7 @@ where
self.system_caller.apply_blockhashes_contract_call(self.ctx.parent_hash, &mut self.evm)?;
self.system_caller
.apply_beacon_root_contract_call(self.ctx.parent_beacon_block_root, &mut self.evm)?;

tracing::debug!(" Applied pre ex");
Ok(())
}

Expand Down Expand Up @@ -144,6 +149,7 @@ where

let gas_used = result.gas_used();

//BAL TODO
// append gas used
self.gas_used += gas_used;

Expand All @@ -163,9 +169,11 @@ where
cumulative_gas_used: self.gas_used,
}));

// Increment bal_index
self.evm.db_mut().bal_state.bump_bal_index();
::tracing::debug!("Updated BAL index to {}", self.evm.db().bal_state.bal_index);
// Commit the state changes.
self.evm.db_mut().commit(state);

Ok(gas_used)
}

Expand Down Expand Up @@ -233,14 +241,92 @@ where
)
})
})?;
tracing::debug!("balance_increments{:?}", balance_increments);

let last_bal_index = self.receipts.len() as u64 + 1;
let mut bal = if self
.spec
.is_amsterdam_active_at_timestamp(self.evm.block().timestamp().saturating_to())
{
let mut withdrawal_bal = BlockAccessList::default();
if let Some(alloy_bal) = self.evm.db_mut().take_built_alloy_bal() {
if let Some(withdrawals) = self.ctx.withdrawals.as_deref() {
for withdrawal in withdrawals.iter() {
let initial = if let Some(account_changes) =
alloy_bal.iter().find(|ac| ac.address == withdrawal.address)
{
if let Some(last_balance) = account_changes.balance_changes.last() {
last_balance.post_balance
} else {
self.evm
.db_mut()
.database
.basic(withdrawal.address)
.unwrap()
.unwrap_or_default()
.balance
}
} else {
self.evm
.db_mut()
.database
.basic(withdrawal.address)
.unwrap()
.unwrap_or_default()
.balance
};

// let final_balance = initial
// .saturating_add(U256::from(withdrawal.amount_wei().to::<u128>()));
if let Some(balance) = balance_increments.get(&withdrawal.address) {
withdrawal_bal.push(
AccountChanges::new(withdrawal.address).with_balance_change(
BalanceChange::new(
last_bal_index,
U256::from(initial.saturating_add(U256::from(*balance))),
),
),
);
} else {
withdrawal_bal.push(AccountChanges::new(withdrawal.address));
}
}
}
// tracing::debug!("Block Access List converted to alloy: {:?}", alloy_bal);
sort_and_remove_duplicates_in_bal(alloy_bal, withdrawal_bal)
} else {
::tracing::debug!("No Block Access List found in revm db; using default");
BlockAccessList::default()
}
} else {
BlockAccessList::default()
}
.to_vec();
// tracing::debug!("Before coinbase:{:?}", bal);

let beneficiary = self.evm.block().beneficiary();
if self.receipts.len() == 0 {
bal =
bal.into_iter()
.filter(|a| {
if a.address == beneficiary {
!a.balance_changes.is_empty()
} else {
true
}
})
.collect();
// tracing::debug!("After coinbase:{:?}", bal);
}
tracing::debug!("Block Coinbase: {}", beneficiary);
Ok((
self.evm,
BlockExecutionResult {
receipts: self.receipts,
requests,
gas_used: self.gas_used,
blob_gas_used: self.blob_gas_used,
block_access_list: Some(bal),
},
))
}
Expand Down Expand Up @@ -324,3 +410,37 @@ where
EthBlockExecutor::new(evm, ctx, &self.spec, &self.receipt_builder)
}
}

/// Sort block-level access list and removes duplicates entries by merging them together.
pub fn sort_and_remove_duplicates_in_bal(
mut alloy_bal: BlockAccessList,
withdrawal_bal: BlockAccessList,
) -> BlockAccessList {
tracing::debug!("Bal before modification:{:?}", alloy_bal);
// tracing::debug!("Withdrawal bal before: {:?}", withdrawal_bal);
let mut last_per_address = HashMap::new();
for account in withdrawal_bal {
last_per_address.insert(account.address, account);
}
// tracing::debug!("Withdrawal bal after: {:?}", last_per_address);
alloy_bal.extend(last_per_address.into_values());

alloy_bal.sort_by_key(|ac| ac.address);

let mut merged: Vec<AccountChanges> = Vec::new();
for account in alloy_bal {
if let Some(last) = merged.last_mut() {
if last.address == account.address {
last.storage_changes.extend(account.storage_changes);
last.storage_reads.extend(account.storage_reads);
last.balance_changes.extend(account.balance_changes);
last.nonce_changes.extend(account.nonce_changes);
last.code_changes.extend(account.code_changes);
continue;
}
}
merged.push(account);
}
tracing::debug!("Bal after modification:{:?}", merged);
merged
}
1 change: 1 addition & 0 deletions crates/evm/src/overrides.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ where
status: AccountStatus::Touched,
storage: Default::default(),
transaction_id: 0,
..Default::default()
};

let storage_diff = match (account_override.state, account_override.state_diff) {
Expand Down
1 change: 0 additions & 1 deletion crates/op-evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,3 @@ std = [
"op-alloy/std",
"thiserror/std"
]
asm-keccak = ["alloy-evm/asm-keccak", "alloy-primitives/asm-keccak", "revm/asm-keccak"]
1 change: 1 addition & 0 deletions crates/op-evm/src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ where
requests: Default::default(),
gas_used: legacy_gas_used,
blob_gas_used: self.da_footprint_used,
block_access_list: None,
},
))
}
Expand Down
Loading
Loading