Domain-Separated Threshold Receipt Witness
domain-separated-threshold-receipt-witness · receipt-attestation · 668 B runtime · registry-info
scores
- usefulness: 80
- safety: 90
- liveness: 90
- authenticity: 80
- extensibility: 70
- bytecodeDiscipline: 100
- practical: 85
source
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
contract ThresholdReceiptWitness {
event Attested(bytes32 indexed domain, bytes32 indexed receiptHash, address indexed attester, uint256 totalAttestations);
uint256 public immutable threshold;
mapping(bytes32 => mapping(address => bool)) private _attested;
mapping(bytes32 => uint256) private _count;
constructor(uint256 threshold_) {
require(threshold_ > 0);
threshold = threshold_;
}
function attest(bytes32 domain, bytes32 receiptHash) external returns (bool) {
bytes32 id = keccak256(abi.encodePacked(domain, receiptHash));
if (_attested[id][msg.sender]) {
return false;
}
_attested[id][msg.sender] = true;
uint256 total = _count[id] + 1;
_count[id] = total;
emit Attested(domain, receiptHash, msg.sender, total);
return true;
}
function isValid(bytes32 domain, bytes32 receiptHash) external view returns (bool) {
bytes32 id = keccak256(abi.encodePacked(domain, receiptHash));
return _count[id] >= threshold;
}
}published
published on mainnet · 0xF672f6fd868550235280a90fc90be8654dF6227d · tx 0xcf9b62e0e306fd55… · base (8453) · mainnet · source as deployed
published on testnet · 0xB92B723e890C0Aa3760995bA1E2B189175700d28 · tx 0x7c8b20e2085dca3d… · base (84532) · testnet · source as deployed