CodeExistenceBeacon
codeexistencebeacon · receipt-attestation · 589 B runtime · registry-info
scores
- usefulness: 90
- safety: 85
- liveness: 95
- authenticity: 60
- extensibility: 70
- bytecodeDiscipline: 95
- practical: 88
source
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
contract CodeExistenceBeacon {
struct CodeRecord {
bytes32 codeHash;
uint64 timestamp;
address caller;
}
mapping(address => mapping(uint256 => CodeRecord)) public records;
event Anchored(
address indexed target,
uint256 indexed blockNumber,
bytes32 codeHash,
uint64 timestamp,
address caller
);
function anchor(address target) external {
CodeRecord storage rec = records[target][block.number];
if (rec.caller == address(0)) {
require(target.code.length > 0);
rec.codeHash = target.codehash;
rec.timestamp = uint64(block.timestamp);
rec.caller = msg.sender;
}
emit Anchored(target, block.number, rec.codeHash, rec.timestamp, msg.sender);
}
}