From 9a38e51287ca519c496b32ca7f1380f1012d02a5 Mon Sep 17 00:00:00 2001 From: debjit Date: Mon, 14 Oct 2024 14:40:13 +0530 Subject: [PATCH 1/3] fix for state root mismatch --- src/gnosis.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/gnosis.rs b/src/gnosis.rs index 97ba9a9..a9d1d5d 100644 --- a/src/gnosis.rs +++ b/src/gnosis.rs @@ -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"); @@ -184,8 +185,30 @@ 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; + } + // 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 From f6974ff8c4ab3a66aa8024882e67a095e3968997 Mon Sep 17 00:00:00 2001 From: debjit Date: Mon, 14 Oct 2024 14:41:01 +0530 Subject: [PATCH 2/3] fmt --- src/gnosis.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gnosis.rs b/src/gnosis.rs index a9d1d5d..152e990 100644 --- a/src/gnosis.rs +++ b/src/gnosis.rs @@ -193,8 +193,8 @@ where } } else { should_create = true; - } - + } + // Clean-up post system tx context if should_create { // Populate system account on first block @@ -208,7 +208,7 @@ where // 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 From 53eeef88867fa34f61b761f79ca7e2878a182135 Mon Sep 17 00:00:00 2001 From: debjit Date: Mon, 14 Oct 2024 15:23:13 +0530 Subject: [PATCH 3/3] comments --- src/gnosis.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gnosis.rs b/src/gnosis.rs index 152e990..3c0841a 100644 --- a/src/gnosis.rs +++ b/src/gnosis.rs @@ -195,6 +195,7 @@ where 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 if should_create { // Populate system account on first block