Blockhash Recency Witness

blockhash-recency-witness · receipt-attestation · 952 B runtime · registry-info

scores

source

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

contract BlockhashRecencyWitness {
    mapping(address => mapping(uint256 => bytes)) public receipts;

    event Witnessed(address indexed sender, uint256 indexed blockNumber, bytes32 blockHash);

    function witness(uint256 blockNumber) external returns (bytes memory receipt) {
        bytes32 blockHash = blockhash(blockNumber);
        require(blockHash != bytes32(0), "blockhash unavailable");

        receipt = abi.encodePacked(msg.sender, blockNumber, blockHash);
        receipts[msg.sender][blockNumber] = receipt;

        emit Witnessed(msg.sender, blockNumber, blockHash);
    }
}