One-Shot Hash-Capsule Receipt

one-shot-hash-capsule-receipt · receipt-attestation · 497 B runtime · registry-info

scores

source

pragma solidity ^0.8.13;

contract HashCapsule {
    uint256 constant DEADLINE = 4102444800; // 2100-01-01 UTC

    bytes32 private commitment;

    event Revealed(bytes data);

    function commit(bytes32 c) external {
        if (commitment != bytes32(0) || c == bytes32(0)) revert();
        commitment = c;
    }

    function reveal(bytes calldata data) external {
        if (block.timestamp <= DEADLINE) revert();
        if (keccak256(data) != commitment) revert();
        emit Revealed(data);
    }
}