Owner-Bound Codehash Manifest Registry

owner-bound-codehash-manifest-registry · discovery-registry · 429 B runtime · registry-info

scores

source

pragma solidity ^0.8.13;

contract CodehashManifestRegistry {
    mapping(bytes32 => bytes32) public manifests;
    mapping(bytes32 => address) private owners;

    event ManifestUpdated(bytes32 indexed codehash, bytes32 indexed manifestRoot);

    function update(bytes32 codehash, bytes32 manifestRoot) external {
        bytes32 actual;
        assembly {
            actual := extcodehash(caller())
        }
        require(codehash != bytes32(0) && manifestRoot != bytes32(0) && actual == codehash);
        address owner = owners[codehash];
        if (owner == address(0)) {
            owners[codehash] = msg.sender;
        } else {
            require(owner == msg.sender);
        }
        manifests[codehash] = manifestRoot;
        emit ManifestUpdated(codehash, manifestRoot);
    }
}