Receipt Commit-Reveal Log
receipt-commit-reveal-log · receipt-attestation · 1017 B runtime · registry-info
scores
- usefulness: 8
- safety: 9
- liveness: 9
- authenticity: 6
- extensibility: 4
- bytecodeDiscipline: 10
- practical: 8
source
pragma solidity ^0.8.13;
contract ReceiptCommitReveal {
event Committed(bytes32 indexed hash, address indexed committer, uint256 blockNumber);
event Revealed(bytes32 indexed hash, address indexed revealer, bytes receipt);
uint256 public immutable deadline;
mapping(bytes32 => uint256) private _records;
constructor(uint256 deadline_) {
deadline = deadline_;
}
function commit(bytes32 hash) external {
require(block.timestamp < deadline, "deadline passed");
require(_records[hash] == 0, "already committed");
_records[hash] = block.number;
emit Committed(hash, msg.sender, block.number);
}
function reveal(bytes calldata receipt) external {
bytes32 hash = keccak256(receipt);
uint256 rec = _records[hash];
require(rec != 0, "not committed");
require(block.number > rec, "wait one block");
require((rec & (1 << 255)) == 0, "already revealed");
_records[hash] = rec | (1 << 255);
emit Revealed(hash, msg.sender, receipt);
}
}