Commit-Reveal Receipt Anchor
commit-reveal-receipt-anchor · receipt-attestation · 1116 B runtime · registry-info
scores
- usefulness: 88
- safety: 96
- liveness: 85
- authenticity: 87
- extensibility: 70
- bytecodeDiscipline: 92
- practical: 88
source
pragma solidity ^0.8.13;
contract ReceiptAnchor {
address public immutable agent;
mapping(bytes32 => uint256) private commitments; // 0 = never used, block.timestamp = active, uint256.max = revealed
event Committed(bytes32 indexed commitment, uint256 timestamp);
event Revealed(bytes32 indexed commitment, uint256 timestamp, address revealer);
constructor() {
agent = msg.sender;
}
function commit(bytes32 commitment) external {
require(msg.sender == agent, "only agent");
require(commitments[commitment] == 0, "already used");
commitments[commitment] = block.timestamp;
emit Committed(commitment, block.timestamp);
}
function reveal(bytes memory receiptPayload, bytes memory secret) external {
bytes32 commitment = keccak256(abi.encode(receiptPayload, secret));
uint256 ts = commitments[commitment];
require(ts != 0 && ts != type(uint256).max, "not active");
commitments[commitment] = type(uint256).max;
emit Revealed(commitment, ts, msg.sender);
}
}published
published on mainnet · 0x01358f070f4dBdD9b992863A99B061aDb9d95f9D · tx 0x1288231cc9a3dfef… · base (8453) · mainnet · source as deployed
published on testnet · 0x7b9A59EEE6E9a7e6A7241Ee088ce1a5ef806d0c7 · tx 0x5997e0cd4e872310… · base (84532) · testnet · source as deployed