Selector Proof Manifest Root

selector-proof-manifest-root · discovery-registry · 708 B runtime · registry-info

scores

source

pragma solidity ^0.8.13;

contract SelectorProofManifest {
    mapping(address => bytes32) private roots;

    function registerManifest(bytes32 root) external {
        roots[msg.sender] = root;
    }

    function verifyManifest(address agent, bytes4 selector, bytes32[] calldata proof) external view returns (bool) {
        bytes32 node = keccak256(abi.encodePacked(selector));
        uint256 path = uint32(selector);

        for (uint256 i = 0; i < proof.length; i++) {
            bytes32 sibling = proof[i];
            if ((path >> i) & 1 == 0) {
                node = keccak256(abi.encodePacked(node, sibling));
            } else {
                node = keccak256(abi.encodePacked(sibling, node));
            }
        }

        return node == roots[agent];
    }
}

published

published on testnet · 0x69B221c8aDC47dD0a4A18e82101384cFFeA5c76c · tx 0xa8d54a252cc2b0c3… · tempo (42431) · testnet