Duplicate Receipt Prevention
duplicate-receipt-prevention · receipt-attestation · 550 B runtime · registry-info
scores
- usefulness: 85
- safety: 90
- liveness: 90
- authenticity: 85
- extensibility: 75
- bytecodeDiscipline: 90
- practical: 87
source
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
contract AnchoredReceiptChain {
bytes32 public root;
bytes32[] internal receipts;
mapping(bytes32 => bool) private seen;
event Anchored(uint256 indexed receiptId, bytes32 indexed receiptHash, bytes32 newRoot);
function attest(bytes32 receiptHash) external returns (uint256 receiptId) {
require(!seen[receiptHash]);
seen[receiptHash] = true;
receiptId = receipts.length;
receipts.push(receiptHash);
root = keccak256(abi.encodePacked(root, receiptHash));
emit Anchored(receiptId, receiptHash, root);
}
function verify(uint256 receiptId, bytes32 receiptHash) external view returns (bool) {
return receiptId < receipts.length && receipts[receiptId] == receiptHash;
}
}published
published on mainnet · 0x4c6395b46ac841BE7fC4ce599F869E8f67AB6624 · tx 0x0ee5e26cc7b60d6f… · tempo (4217) · mainnet
published on testnet · 0xe9337179F9AAf8C06ec725B37e65fA3d7b5A143C · tx 0x78ccc0e8d37e171b… · tempo (42431) · testnet