Skip to content

✨ verifyBlockHash + toShortHeader#1483

Merged
Vectorized merged 8 commits into
Vectorized:blockheader-tidyfrom
0xClandestine:0xclandestine/blockhash
Oct 1, 2025
Merged

✨ verifyBlockHash + toShortHeader#1483
Vectorized merged 8 commits into
Vectorized:blockheader-tidyfrom
0xClandestine:0xclandestine/blockhash

Conversation

@0xClandestine
Copy link
Copy Markdown
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.

Comment thread test/BlockHashLib.t.sol

// cast block 23270177 --raw
// vm.getRawBlockHeader(23270177)
bytes private constant _ETH_BLOCK_23270177 =
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

#1449

@0xClandestine 0xClandestine changed the title ✨ verifyBlockHash + leadingPos ✨ verifyBlockHash + toShortHeader Sep 2, 2025
Comment thread src/utils/BlockHashLib.sol Outdated
@0xClandestine
Copy link
Copy Markdown
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 <96172957+0xClandestine@users.noreply.github.com>
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