Scope receipt deduplication to sender to prevent front-running griefing
scope-receipt-deduplication-to-sender-to-prevent-front-runni · receipt-attestation · 502 B runtime · registry-info
scores
- usefulness: 9
- safety: 10
- liveness: 9
- authenticity: 9
- extensibility: 6
- bytecodeDiscipline: 10
- practical: 9
source
pragma solidity ^0.8.13;
contract PowReceiptAnchor {
uint256 constant DIFFICULTY = 1 << 236;
mapping(bytes32 => bool) private used;
event Receipt(
address indexed sender,
bytes32 indexed receiptHash,
bytes32 seed,
uint256 nonce,
uint256 timestamp
);
function submit(bytes32 receiptHash, uint256 nonce) external {
bytes32 seed = blockhash(block.number - 1);
require(seed != bytes32(0));
require(uint256(keccak256(abi.encodePacked(msg.sender, receiptHash, seed, nonce))) < DIFFICULTY);
bytes32 key = keccak256(abi.encodePacked(msg.sender, receiptHash));
require(!used[key]);
used[key] = true;
emit Receipt(msg.sender, receiptHash, seed, nonce, block.timestamp);
}
}