Skip to content

Commit

Permalink
primitives: use EMPTY_ROOT_HASH when possible (#11822)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger authored Oct 16, 2024
1 parent 025cb3b commit 24287e8
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 29 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions crates/chainspec/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1814,9 +1814,7 @@ Post-merge hard forks (timestamp based):
hex!("078dc6061b1d8eaa8493384b59c9c65ceb917201221d08b80c4de6770b6ec7e7").into();
assert_eq!(chainspec.genesis_header().state_root, expected_state_root);

let expected_withdrawals_hash: B256 =
hex!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421").into();
assert_eq!(chainspec.genesis_header().withdrawals_root, Some(expected_withdrawals_hash));
assert_eq!(chainspec.genesis_header().withdrawals_root, Some(EMPTY_ROOT_HASH));

let expected_hash: B256 =
hex!("1fc027d65f820d3eef441ebeec139ebe09e471cf98516dce7b5643ccb27f418c").into();
Expand Down
6 changes: 3 additions & 3 deletions crates/consensus/common/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ pub fn validate_against_parent_4844(
#[cfg(test)]
mod tests {
use super::*;
use alloy_consensus::TxEip4844;
use alloy_consensus::{TxEip4844, EMPTY_ROOT_HASH};
use alloy_primitives::{
hex_literal::hex, Address, BlockHash, BlockNumber, Bytes, Parity, Sealable, U256,
};
Expand Down Expand Up @@ -444,8 +444,8 @@ mod tests {
ommers_hash: hex!("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347").into(),
beneficiary: hex!("4675c7e5baafbffbca748158becba61ef3b0a263").into(),
state_root: hex!("8337403406e368b3e40411138f4868f79f6d835825d55fd0c2f6e17b1a3948e9").into(),
transactions_root: hex!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421").into(),
receipts_root: hex!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421").into(),
transactions_root: EMPTY_ROOT_HASH,
receipts_root: EMPTY_ROOT_HASH,
logs_bloom: hex!("002400000000004000220000800002000000000000000000000000000000100000000000000000100000000000000021020000000800000006000000002100040000000c0004000000000008000008200000000000000000000000008000000001040000020000020000002000000800000002000020000000022010000000000000010002001000000000020200000000000001000200880000004000000900020000000000020000000040000000000000000000000000000080000000000001000002000000000000012000200020000000000000001000000000000020000010321400000000100000000000000000000000000000400000000000000000").into(),
difficulty: U256::ZERO, // total difficulty: 0xc70d815d562d3cfa955).into(),
number: 0xf21d20,
Expand Down
28 changes: 7 additions & 21 deletions crates/net/eth-wire-types/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ impl From<HeadersDirection> for bool {
#[cfg(test)]
mod tests {
use super::*;
use alloy_consensus::EMPTY_ROOT_HASH;
use alloy_primitives::{address, b256, bloom, bytes, hex, Address, Bytes, B256, U256};
use alloy_rlp::{Decodable, Encodable};
use reth_primitives::Header;
Expand Down Expand Up @@ -201,10 +202,7 @@ mod tests {
gas_used: 0x0125b8,
timestamp: 0x079e,
extra_data: Bytes::from_str("42").unwrap(),
mix_hash: B256::from_str(
"56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
)
.unwrap(),
mix_hash: EMPTY_ROOT_HASH,
base_fee_per_gas: Some(0x09),
withdrawals_root: Some(
B256::from_str("27f166f1d7c789251299535cb176ba34116e44894476a7886fe5d73d9be5c973")
Expand Down Expand Up @@ -254,16 +252,10 @@ mod tests {
gas_used: 0x02a865,
timestamp: 0x079e,
extra_data: Bytes::from(vec![0x42]),
mix_hash: B256::from_str(
"56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
)
.unwrap(),
mix_hash: EMPTY_ROOT_HASH,
nonce: 0u64.into(),
base_fee_per_gas: Some(9),
withdrawals_root: Some(
B256::from_str("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
.unwrap(),
),
withdrawals_root: Some(EMPTY_ROOT_HASH),
blob_gas_used: Some(0x020000),
excess_blob_gas: Some(0),
parent_beacon_block_root: None,
Expand Down Expand Up @@ -291,12 +283,8 @@ mod tests {
ommers_hash: b256!("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"),
beneficiary: address!("f97e180c050e5ab072211ad2c213eb5aee4df134"),
state_root: b256!("ec229dbe85b0d3643ad0f471e6ec1a36bbc87deffbbd970762d22a53b35d068a"),
transactions_root: b256!(
"56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
),
receipts_root: b256!(
"56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
),
transactions_root: EMPTY_ROOT_HASH,
receipts_root: EMPTY_ROOT_HASH,
logs_bloom: Default::default(),
difficulty: U256::from(0),
number: 0x30598,
Expand All @@ -307,9 +295,7 @@ mod tests {
mix_hash: b256!("70ccadc40b16e2094954b1064749cc6fbac783c1712f1b271a8aac3eda2f2325"),
nonce: 0u64.into(),
base_fee_per_gas: Some(7),
withdrawals_root: Some(b256!(
"56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
)),
withdrawals_root: Some(EMPTY_ROOT_HASH),
parent_beacon_block_root: None,
blob_gas_used: Some(0),
excess_blob_gas: Some(0x1600000),
Expand Down
1 change: 1 addition & 0 deletions crates/optimism/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ workspace = true
reth-primitives.workspace = true
reth-primitives-traits.workspace = true
alloy-primitives.workspace = true
alloy-consensus.workspace = true
5 changes: 3 additions & 2 deletions crates/optimism/primitives/src/bedrock.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! OP mainnet bedrock related data.

use alloy_consensus::EMPTY_ROOT_HASH;
use alloy_primitives::{address, b256, bloom, bytes, B256, B64, U256};
use reth_primitives::Header;
use reth_primitives_traits::constants::EMPTY_OMMER_ROOT_HASH;
Expand Down Expand Up @@ -73,10 +74,10 @@ pub const BEDROCK_HEADER: Header = Header {
nonce: B64::ZERO,
number: 105235063,
parent_hash: b256!("21a168dfa5e727926063a28ba16fd5ee84c814e847c81a699c7a0ea551e4ca50"),
receipts_root: b256!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"),
receipts_root: EMPTY_ROOT_HASH,
state_root: b256!("920314c198da844a041d63bf6cbe8b59583165fd2229d1b3f599da812fd424cb"),
timestamp: 1686068903,
transactions_root: b256!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"),
transactions_root: EMPTY_ROOT_HASH,
ommers_hash: EMPTY_OMMER_ROOT_HASH,
beneficiary: address!("4200000000000000000000000000000000000011"),
withdrawals_root: None,
Expand Down

0 comments on commit 24287e8

Please sign in to comment.