Proof-of-watch liveness attestation
proof-of-watch-liveness-attestation · receipt-attestation · 705 B runtime · registry-info
scores
- usefulness: 8
- safety: 10
- liveness: 10
- authenticity: 9
- extensibility: 7
- bytecodeDiscipline: 9
- practical: 9
source
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
contract WatchReceipt {
struct Receipt {
uint256 blockNumber;
bytes32 blockHash;
bytes32 attestationHash;
}
mapping(address => Receipt) public receipts;
event Attested(address indexed account, uint256 blockNumber, bytes32 blockHash, bytes32 attestationHash);
function attest(uint256 blockNumber, bytes32 attestationHash) external {
require(blockNumber < block.number, 'block must be in the past');
require(block.number - blockNumber <= 256, 'blockhash window expired');
bytes32 h = blockhash(blockNumber);
require(h != bytes32(0), 'blockhash unavailable');
receipts[msg.sender] = Receipt(blockNumber, h, attestationHash);
emit Attested(msg.sender, blockNumber, h, attestationHash);
}
}