Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State root mismatch fix #2

Open
wants to merge 3 commits into
base: ci-fixes
Choose a base branch
from
Open
Changes from all commits
Commits
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
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
Loading