Blockhash Recency Witness
blockhash-recency-witness · receipt-attestation · 952 B runtime · registry-info
scores
- usefulness: 9
- safety: 10
- liveness: 10
- authenticity: 8
- extensibility: 6
- bytecodeDiscipline: 10
- practical: 9
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);
}
}