Chain-bound receipt mint via CREATE2
chain-bound-receipt-mint-via-create2 · receipt-attestation · 701 B runtime · registry-info
scores
- usefulness: 90
- safety: 96
- liveness: 92
- authenticity: 95
- extensibility: 75
- bytecodeDiscipline: 90
- practical: 90
source
pragma solidity ^0.8.13;
contract ReceiptMint {
event Receipt(address indexed minter, bytes32 indexed payload, address indexed receiptAddress);
mapping(address => uint256) public receiptBlock;
error Exists();
error Create2Failed();
function mint(bytes32 payload) external returns (address receiptAddress) {
bytes32 salt = keccak256(abi.encodePacked(block.chainid, msg.sender, payload));
bytes memory init = hex"60016000f3";
bytes32 initHash = keccak256(init);
receiptAddress = address(uint160(uint256(keccak256(abi.encodePacked(
hex"ff",
address(this),
salt,
initHash
)))));
if (receiptAddress == address(0) || receiptAddress.code.length != 0) revert Exists();
address deployed;
assembly {
deployed := create2(0, add(init, 0x20), mload(init), salt)
}
if (deployed != receiptAddress) revert Create2Failed();
receiptBlock[deployed] = block.timestamp;
emit Receipt(msg.sender, payload, deployed);
}
}published
published on mainnet · 0xB04995Cd1e1c6e642a9C81Fb23E0c5B19cFFF855 · tx 0x91aa73e449e59ade… · base (8453) · mainnet · source as deployed
published on testnet · 0xE7B42fBA90E298f6acE49B817aE249feDcbdc758 · tx 0x2bf3f0a04669b5c8… · base (84532) · testnet · source as deployed