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

Always create system address after block execution #21

Merged
merged 3 commits into from
Oct 16, 2024
Merged
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
27 changes: 25 additions & 2 deletions 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,30 @@ where
})
})?;

// Clean-up post system tx context
state.remove(&SYSTEM_ADDRESS);
// in gnosis aura, system account needs to be included in the state and not removed (despite EIP-158/161, even if empty)
// here we have a generalized check if system account is in state, or needs to be created

// keeping this generalized, instead of only in block 1
// (AccountStatus::Touched | AccountStatus::LoadedAsNotExisting) means the account is not in the state
let should_create = state.get(&SYSTEM_ADDRESS).map_or(true, |system_account| {
// true if account not in state (either None, or Touched | LoadedAsNotExisting)
system_account.status == (AccountStatus::Touched | AccountStatus::LoadedAsNotExisting)
});

// this check needs to be there in every call, so instead of making it into a function which is called from post_execution, we can just include it in the rewards function
if should_create {
let account = Account {
info: AccountInfo::default(),
storage: Default::default(),
// we force the account to be created by changing the status
status: AccountStatus::Touched | AccountStatus::Created,
};
state.insert(SYSTEM_ADDRESS, account);
} else {
// clear the system address account from state transitions, else EIP-158/161 (impl in revm) removes it from state
state.remove(&SYSTEM_ADDRESS);
}

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