Skip to content

Support RLP-encoded block header validation against blockHashΒ #5803

@0xClandestine

Description

@0xClandestine

🧐 Motivation

It would be valuable if the Blockhash utility supported verifying RLP-encoded block headers against historical block hashes. This is useful for block header, account, storage, tx, and event proofs.

πŸ“ Details

Proposed implementation (should definitely include calldata variants given rlp block headers are typically provided by the user as calldata):

/**
 * @dev Verifies that the RLP-encoded block header matches the canonical block hash.
 * @param blockHeader The full RLP-encoded block header.
 * @param blockNumber The block number it claims to correspond to.
 * @return True if the keccak256 hash of the blockHeader matches the historical block hash.
 */
function verifyBlockHeader(bytes memory blockHeader, uint256 blockNumber) internal view returns (bool) {
    return blockHeader.blockHash() == blockNumber.blockHash();
}

/**
 * @dev Computes the hash of an RLP-encoded block header.
 * @param rlp The RLP-encoded header data.
 * @return hash The keccak256 hash of the RLP payload.
 */
function blockHash(bytes memory rlp) internal pure returns (bytes32 hash) {
    assembly {
        hash := keccak256(add(rlp, 0x20), mload(rlp))
    }
}

This addition would complement #5680.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions