Skip to content

Commit

Permalink
Fix block header encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Lohann committed Nov 12, 2023
1 parent 103eaf8 commit 48fbb6a
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 143 deletions.
12 changes: 6 additions & 6 deletions chains/ethereum/executor/src/rust_evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ where
env.cfg.disable_block_gas_limit = true;

// Configure block
env.block.number = revm::primitives::U256::from(block.number);
env.block.coinbase = revm::primitives::Address::from(block.miner.unwrap_or_default().0);
env.block.timestamp = revm::primitives::U256::from_limbs(block.timestamp.0);
env.block.difficulty = revm::primitives::U256::from_limbs(block.difficulty.0);
env.block.number = revm::primitives::U256::from(block.header.number);
env.block.coinbase = revm::primitives::Address::from(block.header.beneficiary.0);
env.block.timestamp = revm::primitives::U256::from(block.header.timestamp);
env.block.difficulty = revm::primitives::U256::from_limbs(block.header.difficulty.0);
env.block.basefee =
revm::primitives::U256::from_limbs(block.base_fee_per_gas.unwrap_or_default().0);
env.block.gas_limit = revm::primitives::U256::from_limbs(block.gas_limit.0);
revm::primitives::U256::from(block.header.base_fee_per_gas.unwrap_or_default());
env.block.gas_limit = revm::primitives::U256::from(block.header.gas_limit);
env.block.prevrandao = Some(revm::primitives::B256::ZERO);
env.block.blob_excess_gas_and_price = Some(revm::primitives::BlobExcessGasAndPrice::new(0));

Expand Down
16 changes: 10 additions & 6 deletions chains/ethereum/executor/src/sputnik_evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,17 @@ where
gas_price: U256::zero(),
origin: tx.from.unwrap_or_default(),
block_hashes: self.db.blocks_hashes.values().copied().collect(),
block_number: U256::from(block.number),
block_coinbase: block.miner.unwrap_or_default(),
block_timestamp: block.timestamp,
block_difficulty: block.difficulty,
block_gas_limit: block.gas_limit,
block_number: U256::from(block.header.number),
block_coinbase: block.header.beneficiary,
block_timestamp: U256::from(block.header.timestamp),
block_difficulty: block.header.difficulty,
block_gas_limit: U256::from(block.header.gas_limit),
chain_id: tx.chain_id.map(U256::from).unwrap_or_default(),
block_base_fee_per_gas: block.base_fee_per_gas.unwrap_or_default(),
block_base_fee_per_gas: block
.header
.base_fee_per_gas
.map(U256::from)
.unwrap_or_default(),
block_randomness: None,
};

Expand Down
2 changes: 1 addition & 1 deletion chains/ethereum/executor/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ where
let at = AtBlock::At(BlockIdentifier::Hash(block.hash));

// Store block hash
self.blocks_hashes.insert(block.number, block.hash);
self.blocks_hashes.insert(block.header.number, block.hash);

// Load storages
let mut access_list =
Expand Down
67 changes: 14 additions & 53 deletions chains/ethereum/primitives/src/block.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
use crate::{
bytes::Bytes,
eth_hash::{Address, H256, H64},
eth_uint::U256,
};
use crate::{bytes::Bytes, eth_hash::H256, eth_uint::U256, header::Header};
use alloc::vec::Vec;
use ethbloom::Bloom;

#[cfg(feature = "with-serde")]
use crate::serde_utils::{deserialize_uint, serialize_uint};

/// The block type returned from RPC calls.
///
Expand All @@ -26,66 +18,35 @@ use crate::serde_utils::{deserialize_uint, serialize_uint};
pub struct Block<TX> {
/// Hash of the block
pub hash: H256,
/// Hash of the parent
pub parent_hash: H256,
/// Hash of the uncles
pub sha3_uncles: H256,
/// Miner/author's address.
pub miner: Option<Address>,
/// State root hash
pub state_root: H256,
/// Transactions root hash
pub transactions_root: H256,
/// Transactions receipts root hash
pub receipts_root: H256,
/// Block number.
#[cfg_attr(
feature = "with-serde",
serde(deserialize_with = "deserialize_uint", serialize_with = "serialize_uint",)
)]
pub number: u64,
/// Gas Used
pub gas_used: U256,
/// Gas Limit
pub gas_limit: U256,
/// Extra data
pub extra_data: Bytes,
/// Logs bloom
pub logs_bloom: Option<Bloom>,
/// Timestamp
#[cfg_attr(feature = "with-serde", serde(default))]
pub timestamp: U256,
/// Difficulty
#[cfg_attr(feature = "with-serde", serde(default))]
pub difficulty: U256,

/// Block header.
#[cfg_attr(feature = "with-serde", serde(flatten))]
pub header: Header,

/// Total difficulty
#[cfg_attr(feature = "with-serde", serde(default))]
pub total_difficulty: Option<U256>,

/// Seal fields
#[cfg_attr(
feature = "with-serde",
serde(default, rename = "sealFields", deserialize_with = "deserialize_null_default")
)]
pub seal_fields: Vec<Bytes>,
/// Uncles' hashes
#[cfg_attr(feature = "with-serde", serde(default))]
pub uncles: Vec<H256>,

/// Transactions
#[cfg_attr(
feature = "with-serde",
serde(bound = "TX: serde::Serialize + serde::de::DeserializeOwned", default)
)]
pub transactions: Vec<TX>,

/// Uncles' hashes
#[cfg_attr(feature = "with-serde", serde(default))]
pub uncles: Vec<H256>,

/// Size in bytes
pub size: Option<U256>,
/// Mix Hash
pub mix_hash: Option<H256>,
/// Nonce
pub nonce: Option<H64>,
/// Base fee per unit of gas (if past London)
pub base_fee_per_gas: Option<U256>,
/// Withdrawals root hash (if past Shanghai)
#[cfg_attr(feature = "with-serde", serde(default, skip_serializing_if = "Option::is_none"))]
pub withdrawals_root: Option<H256>,
}

#[cfg(feature = "with-serde")]
Expand Down
Loading

0 comments on commit 48fbb6a

Please sign in to comment.