HashCash Slot Auction Constructor Validation
hashcash-slot-auction-constructor-validation · auction-allocation · 606 B runtime · funds-movement
scores
- usefulness: 70
- safety: 92
- liveness: 88
- authenticity: 95
- extensibility: 65
- bytecodeDiscipline: 96
- practical: 80
source
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
contract HashCashSlotAuction {
mapping(uint256 => address) public ownerOfSlot;
uint256 public immutable targetDifficulty;
error SlotTaken();
error PoWNotMet();
event SlotAllocated(uint256 indexed slotId, address indexed owner, uint256 nonce);
constructor(uint256 _targetDifficulty) {
unchecked {
require(_targetDifficulty - 1 <= 247);
}
targetDifficulty = _targetDifficulty;
}
function claim(uint256 slotId, uint256 nonce) external {
if (ownerOfSlot[slotId] != address(0)) revert SlotTaken();
if (uint256(keccak256(abi.encodePacked(msg.sender, slotId, nonce))) >= (1 << targetDifficulty)) revert PoWNotMet();
ownerOfSlot[slotId] = msg.sender;
emit SlotAllocated(slotId, msg.sender, nonce);
}
}published
published on testnet · 0xA13fb2bbb979482E14A90EfbCd717d9aEe1AEf0E · tx 0xff974f2f187fe292… · base (84532) · testnet · source as deployed