Skip to content

Conversation

@0xClandestine
Copy link
Contributor

@0xClandestine 0xClandestine commented Sep 1, 2025

Description

Adds minimal block header utilities for state proofs + light client implementations.

  • Added BlockHashLib.verifyBlockHash(blockHeader, blockNumber)
    Validates RLP-encoded headers against BlockHashLib.blockHash(blockNumber).

  • Added BlockHashLib.toShortHeader(blockHeader):
    Efficiently extracts relevant fields from RLP-encoded block headers for MPT proof verification, without full RLP-decoding.

/// @dev Ethereum block header fields relevent to historical MPT proofs.
struct ShortHeader {
    bytes32 parentHash;
    bytes32 stateRoot;
    bytes32 transactionsRoot;
    bytes32 receiptsRoot;
    bytes32[8] logsBloom;
}

Checklist

Ensure you completed all of the steps below before submitting your pull request:

  • Ran forge fmt?
  • Ran forge test?

Pull requests with an incomplete checklist will be thrown out.


// cast block 23270177 --raw
// vm.getRawBlockHeader(23270177)
bytes private constant _ETH_BLOCK_23270177 =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fork tests are preferred, not sure how you handle them though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to bump forge-std to support vm.getRawBlockHeader.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we’ll just fake it for now.

when we are really free, we can add a CI that does fork testing.

/// @solidity memory-safe-assembly
assembly {
calldatacopy(mload(0x40), header.offset, header.length)
if iszero(eq(result, keccak256(mload(0x40), header.length))) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is xor more efficient here than iszero + eq?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not for here, i think.

@0xClandestine
Copy link
Contributor Author

#1449

@0xClandestine 0xClandestine changed the title ✨ verifyBlockHash + leadingPos ✨ verifyBlockHash + toShortHeader Sep 2, 2025
@0xClandestine
Copy link
Contributor Author

anything else needed on this?

@Vectorized Vectorized changed the base branch from main to blockheader-tidy October 1, 2025 03:18
@Vectorized Vectorized merged commit 9188019 into Vectorized:blockheader-tidy Oct 1, 2025
11 checks passed
Vectorized added a commit that referenced this pull request Oct 6, 2025
* ✨ verifyBlockHash + toShortHeader (#1483)

Co-authored-by: clandestine.eth <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants