diff --git a/src/execute.rs b/src/execute.rs index ecfdd72..d2602a4 100644 --- a/src/execute.rs +++ b/src/execute.rs @@ -1,5 +1,6 @@ use crate::ethereum::{EthEvmExecutor, EthExecuteOutput}; use crate::gnosis::{apply_block_rewards_contract_call, apply_withdrawals_contract_call}; +use eyre::eyre; use reth::providers::ExecutionOutcome; use reth::{ api::ConfigureEvm, @@ -26,15 +27,28 @@ use std::{collections::HashMap, sync::Arc}; pub struct GnosisExecutorProvider { chain_spec: Arc, evm_config: EvmConfig, + /// AuRa BlockRewards contract address for its system call + block_rewards_contract: Address, } impl GnosisExecutorProvider { /// Creates a new executor provider. - pub fn new(chain_spec: Arc, evm_config: EvmConfig) -> Self { - Self { + pub fn new(chain_spec: Arc, evm_config: EvmConfig) -> eyre::Result { + let block_rewards_contract = chain_spec + .genesis() + .config + .extra_fields + .get("blockRewardsContract") + .ok_or(eyre!("blockRewardsContract not defined"))?; + let block_rewards_contract: Address = + serde_json::from_value(block_rewards_contract.clone()) + .map_err(|e| BlockExecutionError::Other(Box::new(e)))?; + + Ok(Self { chain_spec, evm_config, - } + block_rewards_contract, + }) } } @@ -48,6 +62,7 @@ where DB: Database + Display>, { GnosisBlockExecutor::new( + self.block_rewards_contract, self.chain_spec.clone(), self.evm_config.clone(), State::builder() @@ -98,18 +113,26 @@ pub struct GnosisBlockExecutor { executor: EthEvmExecutor, /// The state to use for execution state: State, + /// AuRa BlockRewards contract address for its system call + block_rewards_contract: Address, } // [Gnosis/fork] Copy paste code from crates/ethereum/evm/src/execute.rs::EthBlockExecutor impl GnosisBlockExecutor { /// Creates a new Ethereum block executor. - pub fn new(chain_spec: Arc, evm_config: EvmConfig, state: State) -> Self { + pub fn new( + block_rewards_contract: Address, + chain_spec: Arc, + evm_config: EvmConfig, + state: State, + ) -> Self { Self { executor: EthEvmExecutor { chain_spec, evm_config, }, state, + block_rewards_contract, } } @@ -225,7 +248,7 @@ where let mut evm = self.executor.evm_config.evm_with_env(&mut self.state, env); apply_block_rewards_contract_call( - &chain_spec, + self.block_rewards_contract, block.timestamp, block.beneficiary, &mut evm, diff --git a/src/gnosis.rs b/src/gnosis.rs index 2aeb395..6023db0 100644 --- a/src/gnosis.rs +++ b/src/gnosis.rs @@ -15,9 +15,6 @@ use reth_evm::execute::BlockExecutionError; pub const SYSTEM_ADDRESS: Address = address!("fffffffffffffffffffffffffffffffffffffffe"); -// TODO: customize from genesis or somewhere -pub const BLOCK_REWARDS_CONTRACT: Address = address!("481c034c6d9441db23ea48de68bcae812c5d39ba"); - // Codegen from https://github.com/gnosischain/specs/blob/master/execution/withdrawals.md sol!( function executeSystemWithdrawals( @@ -108,7 +105,7 @@ where /// Ref: #[inline] pub fn apply_block_rewards_contract_call( - _chain_spec: &ChainSpec, + block_rewards_contract: Address, _block_timestamp: u64, coinbase: Address, evm: &mut Evm<'_, EXT, DB>, @@ -123,7 +120,7 @@ where fill_tx_env_with_system_contract_call( &mut evm.context.evm.env, SYSTEM_ADDRESS, - BLOCK_REWARDS_CONTRACT, + block_rewards_contract, rewardCall { benefactors: vec![coinbase], // Type 0 = RewardAuthor diff --git a/src/lib.rs b/src/lib.rs index 2e49c6e..0878f40 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -118,7 +118,7 @@ where let evm_config = GnosisEvmConfig { collector_address: serde_json::from_value(collector_address.clone())?, }; - let executor = GnosisExecutorProvider::new(chain_spec, evm_config); + let executor = GnosisExecutorProvider::new(chain_spec, evm_config)?; Ok((evm_config, executor)) }