Reversible Receipt Latch

reversible-receipt-latch · receipt-attestation · 617 B runtime · registry-info

scores

source

pragma solidity ^0.8.13;

contract ReversibleReceiptLatch {
    uint256 constant WINDOW = 100;

    mapping(address => bytes32) public receipts;
    mapping(address => uint256) public deadlines;

    function commit(bytes32 hash) external {
        require(receipts[msg.sender] == bytes32(0));
        require(hash != bytes32(0));
        receipts[msg.sender] = hash;
        deadlines[msg.sender] = block.timestamp + WINDOW;
    }

    function invalidate(bytes32 hash) external {
        require(receipts[msg.sender] == hash);
        require(block.timestamp < deadlines[msg.sender]);
        receipts[msg.sender] = bytes32(0);
    }

    function finalize() external {
        require(deadlines[msg.sender] != 0);
        require(block.timestamp >= deadlines[msg.sender]);
        deadlines[msg.sender] = 0;
    }
}