Skip to content

Commit

Permalink
state root mismatch fix
Browse files Browse the repository at this point in the history
  • Loading branch information
debjit-bw committed Oct 15, 2024
1 parent ec71c67 commit 0b88039
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/gnosis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use reth::{
use reth_chainspec::ChainSpec;
use reth_errors::BlockValidationError;
use reth_evm::{execute::BlockExecutionError, ConfigureEvm};
use revm_primitives::{Account, AccountInfo, AccountStatus};

pub const SYSTEM_ADDRESS: Address = address!("fffffffffffffffffffffffffffffffffffffffe");

Expand Down Expand Up @@ -184,8 +185,31 @@ where
})
})?;

// figure out if we should create the system account
let mut should_create = false;
if let Some(system_account) = state.get(&SYSTEM_ADDRESS) {
if system_account.status == (AccountStatus::Touched | AccountStatus::LoadedAsNotExisting) {
should_create = true;
}
} else {
should_create = true;
}

// system account call is only in rewards function because it will be called in every block
// Clean-up post system tx context
state.remove(&SYSTEM_ADDRESS);
if should_create {
// Populate system account on first block
let account = Account {
info: AccountInfo::default(),
storage: Default::default(),
status: AccountStatus::Touched | AccountStatus::Created,
};
state.insert(SYSTEM_ADDRESS, account);
} else {
// Conditionally clear the system address account to prevent being removed
state.remove(&SYSTEM_ADDRESS);
}

state.remove(&evm.block().coinbase);
evm.context.evm.db.commit(state);
// re-set the previous env
Expand Down

0 comments on commit 0b88039

Please sign in to comment.