-
Notifications
You must be signed in to change notification settings - Fork 12.1k
Open
Description
π§ 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
Labels
No labels